Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleDriverTest.java
linenumberstrue
public class DriverTest {
  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
  @Before
  public void setUp() throws Exception {
    testEnvironment.setUp();
  }
  @Test
  public void testSimpleDriver() throws BindException, InjectionException {
    final Configuration driverConfiguration = DriverConfiguration.CONF
        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(DriverTestStartHandler.class))
        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_DriverTest")
        .set(DriverConfiguration.ON_DRIVER_STARTED, DriverTestStartHandler.class)
        .build();
    final LauncherStatus status = this.testEnvironment.run(driverConfiguration);
    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
  }
  @After
  public void tearDown() throws Exception {
    this.testEnvironment.tearDown();
  }
}

Lines 9-13 set up a very simple driver and in line 16 submits . In line 14, it is submitted it for execution and line 15 fails the test if it did not run successfully. Note that the interaction between the test and the actual runtime is mediated via the TestEnvironment interface. This allows us to write integration tests that are portable across all of the runtimes supported. In order to allow for the runtime to pefrom setup and teardown operations, we have to call it in the @Before and @After methods of the test class accordingly.

How to fail a test

Integration tests can fail on the Client, the Driver or any of the Evaluators spawned by the test. In order to propagate the test failures from Driver and Evaluator back to the client, we use REEF's exception propagation mechanism. If a test fails on the Driver side, throw a "DriverSideFailure". For the task side, throw a "TaskSideFailure". And don't worry: The exception propagation itself is tested within the reef-tests module.

Registering your test / test suite

In order for us to run the new test (suite) as part of our release validation, please add it to org.apache.reef.tests.AllTestsSuite.