This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.tests.fail.driver;
020
021import org.apache.reef.client.DriverConfiguration;
022import org.apache.reef.client.LauncherStatus;
023import org.apache.reef.tang.Configuration;
024import org.apache.reef.tang.JavaConfigurationBuilder;
025import org.apache.reef.tang.Tang;
026import org.apache.reef.tang.exceptions.BindException;
027import org.apache.reef.tang.exceptions.InjectionException;
028import org.apache.reef.tests.TestDriverLauncher;
029import org.apache.reef.util.EnvironmentUtils;
030
031/**
032 * Client for the test REEF job that fails on different stages of execution.
033 */
034public final class FailClient {
035
036  public static LauncherStatus run(final Class<?> failMsgClass,
037                                   final Configuration runtimeConfig,
038                                   final int timeOut) throws BindException, InjectionException {
039
040    final Configuration driverConfig = DriverConfiguration.CONF
041        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(FailDriver.class))
042        .set(DriverConfiguration.DRIVER_IDENTIFIER, "Fail_" + failMsgClass.getSimpleName())
043        .set(DriverConfiguration.ON_DRIVER_STARTED, FailDriver.StartHandler.class)
044        .set(DriverConfiguration.ON_DRIVER_STOP, FailDriver.StopHandler.class)
045        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FailDriver.AllocatedEvaluatorHandler.class)
046        .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, FailDriver.CompletedEvaluatorHandler.class)
047        .set(DriverConfiguration.ON_EVALUATOR_FAILED, FailDriver.FailedEvaluatorHandler.class)
048        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, FailDriver.ActiveContextHandler.class)
049        .set(DriverConfiguration.ON_CONTEXT_MESSAGE, FailDriver.ContextMessageHandler.class)
050        .set(DriverConfiguration.ON_CONTEXT_CLOSED, FailDriver.ClosedContextHandler.class)
051        .set(DriverConfiguration.ON_CONTEXT_FAILED, FailDriver.FailedContextHandler.class)
052        .set(DriverConfiguration.ON_TASK_RUNNING, FailDriver.RunningTaskHandler.class)
053        .set(DriverConfiguration.ON_TASK_SUSPENDED, FailDriver.SuspendedTaskHandler.class)
054        .set(DriverConfiguration.ON_TASK_MESSAGE, FailDriver.TaskMessageHandler.class)
055        .set(DriverConfiguration.ON_TASK_FAILED, FailDriver.FailedTaskHandler.class)
056        .set(DriverConfiguration.ON_TASK_COMPLETED, FailDriver.CompletedTaskHandler.class)
057        .build();
058
059    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
060    cb.addConfiguration(driverConfig);
061    cb.bindNamedParameter(FailDriver.FailMsgClassName.class, failMsgClass.getName());
062
063    return TestDriverLauncher.getLauncher(runtimeConfig).run(cb.build(), timeOut);
064  }
065
066  /**
067   * Empty private constructor to prohibit instantiation of utility class.
068   */
069  private FailClient() {
070  }
071}