The module reef-tests contains our integration tests. These tests run actual REEF jobs and validate their behavior. Also, they are portable across all runtimes REEF supports. this page documents how to write such integration tests. We use JUnit as the testing framework. However, these tests are not unit tests, but integration tests. Within the test method, we use the REEF client submit a Driver and observe its behavior.
The simplest test
Consider the following simple test:
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. 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
.