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.task;
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.task.Task;
029import org.apache.reef.tests.TestDriverLauncher;
030import org.apache.reef.util.EnvironmentUtils;
031
032/**
033 * Client for the test REEF job that fails on different stages of execution.
034 */
035public final class Client {
036
037  public static LauncherStatus run(
038      final Class<? extends Task> failTaskClass,
039      final Configuration runtimeConfig,
040      final int timeOut) throws BindException, InjectionException {
041
042    final Configuration driverConfig = DriverConfiguration.CONF
043        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(Driver.class))
044        .set(DriverConfiguration.DRIVER_IDENTIFIER, failTaskClass.getSimpleName())
045        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, Driver.AllocatedEvaluatorHandler.class)
046        .set(DriverConfiguration.ON_TASK_RUNNING, Driver.RunningTaskHandler.class)
047        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, Driver.ActiveContextHandler.class)
048        .set(DriverConfiguration.ON_DRIVER_STARTED, Driver.StartHandler.class)
049        .build();
050
051    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
052    cb.addConfiguration(driverConfig);
053    cb.bindNamedParameter(Driver.FailTaskName.class, failTaskClass.getSimpleName());
054
055    return TestDriverLauncher.getLauncher(runtimeConfig).run(cb.build(), timeOut);
056  }
057
058  /**
059   * Empty private constructor to prohibit instantiation of utility class.
060   */
061  private Client() {
062  }
063}