You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/01/23 00:46:38 UTC

[05/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java
new file mode 100644
index 0000000..aa4b5fd
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.yarn.failure;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class FailureREEF {
+
+  public static final int NUM_LOCAL_THREADS = 16;
+
+  private static final Logger LOG = Logger.getLogger(FailureREEF.class.getName());
+
+  private static Configuration parseCommandLine(final String[] aArgs) {
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    try {
+      new CommandLine(cb)
+          .registerShortNameOfClass(Local.class)
+          .registerShortNameOfClass(TimeOut.class)
+          .processCommandLine(aArgs);
+      return cb.build();
+    } catch (final BindException | IOException ex) {
+      final String msg = "Unable to parse command line";
+      LOG.log(Level.SEVERE, msg, ex);
+      throw new RuntimeException(msg, ex);
+    }
+  }
+
+  /**
+   * @return (immutable) TANG Configuration object.
+   * @throws BindException      if configuration injector fails.
+   * @throws InjectionException if the Local.class parameter is not injected.
+   */
+  private static Configuration getRunTimeConfiguration(final boolean isLocal) throws BindException {
+
+    final Configuration runtimeConfiguration;
+
+    if (isLocal) {
+      LOG.log(Level.INFO, "Running Failure demo on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.INFO, "Running Failure demo on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+
+    return runtimeConfiguration;
+  }
+
+  public static LauncherStatus runFailureReef(
+      final Configuration runtimeConfig, final int timeout) throws InjectionException {
+
+    final Configuration driverConf = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(FailureDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "FailureREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, FailureDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FailureDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, FailureDriver.EvaluatorFailedHandler.class)
+        .build();
+
+    final LauncherStatus state = DriverLauncher.getLauncher(runtimeConfig).run(driverConf, timeout);
+    LOG.log(Level.INFO, "REEF job completed: {0}", state);
+    return state;
+  }
+
+  public static void main(final String[] args) throws InjectionException {
+    final Configuration commandLineConf = parseCommandLine(args);
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final boolean isLocal = injector.getNamedInstance(Local.class);
+    final int jobTimeout = injector.getNamedInstance(TimeOut.class) * 60 * 1000;
+    runFailureReef(getRunTimeConfiguration(isLocal), jobTimeout);
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+
+  @NamedParameter(doc = "Number of minutes before timeout",
+      short_name = "timeout", default_value = "2")
+  public static final class TimeOut implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java
new file mode 100644
index 0000000..36db2d3
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.tests.close_eval.CloseEvaluatorTest;
+import org.apache.reef.tests.driver.DriverTest;
+import org.apache.reef.tests.evaluatorfailure.EvaluatorFailureTest;
+import org.apache.reef.tests.evaluatorreuse.EvaluatorReuseTest;
+import org.apache.reef.tests.evaluatorsize.EvaluatorSizeTest;
+import org.apache.reef.tests.examples.ExamplesTestSuite;
+import org.apache.reef.tests.fail.FailTestSuite;
+import org.apache.reef.tests.files.FileResourceTest;
+import org.apache.reef.tests.messaging.driver.DriverMessagingTest;
+import org.apache.reef.tests.messaging.task.TaskMessagingTest;
+import org.apache.reef.tests.statepassing.StatePassingTest;
+import org.apache.reef.tests.subcontexts.SubContextTest;
+import org.apache.reef.tests.taskresubmit.TaskResubmitTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    DriverTest.class,
+    EvaluatorReuseTest.class,
+    EvaluatorSizeTest.class,
+    FailTestSuite.class,
+    FileResourceTest.class,
+    DriverMessagingTest.class,
+    TaskMessagingTest.class,
+    StatePassingTest.class,
+    SubContextTest.class,
+    TaskResubmitTest.class,
+    CloseEvaluatorTest.class,
+    EvaluatorFailureTest.class,
+    ExamplesTestSuite.class
+})
+public final class AllTestsSuite {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java
new file mode 100644
index 0000000..2c02d93
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.yarn.failure.FailureREEF;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FailureTest {
+
+  private static final int JOB_TIMEOUT = 2 * 60 * 1000;
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testFailureRestart() throws InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final LauncherStatus status = FailureREEF.runFailureReef(runtimeConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("FailureReef failed: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java
new file mode 100644
index 0000000..345b49c
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * A TestEnvironment for the local resourcemanager.
+ */
+public final class LocalTestEnvironment extends TestEnvironmentBase implements TestEnvironment {
+
+  /**
+   * The number of threads allocated to the local runtime.
+   */
+  public static final int NUMBER_OF_THREADS = 4;
+  // Used to make sure the tests call the methods in the right order.
+  private boolean ready = false;
+
+  @Override
+  public synchronized final void setUp() {
+    this.ready = true;
+  }
+
+  @Override
+  public synchronized final Configuration getRuntimeConfiguration() {
+    assert (this.ready);
+    final String rootFolder = System.getProperty("org.apache.reef.runtime.local.folder");
+    if (null == rootFolder) {
+      return LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUMBER_OF_THREADS)
+          .build();
+    } else {
+      return LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUMBER_OF_THREADS)
+          .set(LocalRuntimeConfiguration.RUNTIME_ROOT_FOLDER, rootFolder)
+          .build();
+
+    }
+  }
+
+  @Override
+  public synchronized final void tearDown() {
+    assert (this.ready);
+    this.ready = false;
+  }
+
+  @Override
+  public int getTestTimeout() {
+    return 60000; // 1 min.
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java
new file mode 100644
index 0000000..557c8b8
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.runtime.mesos.client.MesosClientConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+
+/**
+ * A TestEnvironment for the Mesos resourcemanager.
+ */
+public final class MesosTestEnvironment extends TestEnvironmentBase implements TestEnvironment {
+
+  // Used to make sure the tests call the methods in the right order.
+  private boolean ready = false;
+
+  @Override
+  public synchronized final void setUp() {
+    this.ready = true;
+  }
+
+  @Override
+  public synchronized final Configuration getRuntimeConfiguration() {
+    assert (this.ready);
+    try {
+      if (System.getenv("REEF_TEST_MESOS_MASTER_IP").equals("")) {
+        throw new RuntimeException("REEF_TEST_MESOS_MASTER_IP unspecified");
+      }
+
+      final String masterIp = System.getenv("REEF_TEST_MESOS_MASTER_IP");
+      return MesosClientConfiguration.CONF
+          .set(MesosClientConfiguration.MASTER_IP, masterIp)
+          .build();
+    } catch (final BindException ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+
+  @Override
+  public synchronized final void tearDown() {
+    assert (this.ready);
+    this.ready = false;
+  }
+
+  @Override
+  public int getTestTimeout() {
+    return 300000; // 5 minutes
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java
new file mode 100644
index 0000000..e9001f2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.tests.taskcounting.TaskCountingTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A test suite for probabilistic tests: Tests that run man, many times in order to check for HeisenBugs.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    TaskCountingTest.class
+})
+public final class ProbabilisticTests {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
new file mode 100644
index 0000000..664b526
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * Environment for REEF unit tests.
+ * <p/>
+ * The idea is to use an instance of this class to gain access
+ * to a REEF resource manager environment in order to make the tests
+ * portable amongst REEF runtimes (e.g. YARN, Local, ...)
+ */
+public interface TestEnvironment {
+
+  /**
+   * Setup the test environment. This is typically called in a method @Before the actual test.
+   */
+  void setUp();
+
+  /**
+   * @return a Configuration used to obtain a REEF resourcemanager for the tests.
+   * E.g. the local or YARN resource manager.
+   */
+  Configuration getRuntimeConfiguration();
+
+  /**
+   * Cleanup the test environment. This is typically called in a method @After the actual test.
+   */
+  void tearDown();
+
+  /**
+   * Return test timeout in milliseconds
+   * (we need longer timeouts on YARN comparing than in local mode).
+   *
+   * @return test timeout in milliseconds.
+   */
+  int getTestTimeout();
+
+  LauncherStatus run(final Configuration driverConfiguration);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java
new file mode 100644
index 0000000..1f925b0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+/**
+ * Abstract base class for TestEnvironments
+ */
+public abstract class TestEnvironmentBase implements TestEnvironment {
+
+  @Override
+  public LauncherStatus run(final Configuration driverConfiguration) {
+    try {
+      return DriverLauncher.getLauncher(getRuntimeConfiguration()).run(driverConfiguration, getTestTimeout());
+    } catch (final InjectionException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java
new file mode 100644
index 0000000..58f2072
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Factory for the TestEnvironment.
+ */
+public final class TestEnvironmentFactory {
+
+  private final static Logger LOG = Logger.getLogger(TestEnvironmentFactory.class.getName());
+
+  /**
+   * If $REEF_TEST_YARN environment variable is not set or is set to false,
+   * return the local test environment; otherwise, return the one for YARN.
+   *
+   * @return a new TestEnvironment instance.
+   */
+  public static TestEnvironment getNewTestEnvironment() {
+    final boolean isYarn = Boolean.parseBoolean(System.getenv("REEF_TEST_YARN"));
+    final boolean isMesos = Boolean.parseBoolean(System.getenv("REEF_TEST_MESOS"));
+
+    if (isYarn && isMesos) {
+      throw new RuntimeException("Cannot test on two runtimes at once");
+    } else if (isYarn) {
+      LOG.log(Level.INFO, "Running tests on YARN");
+      return new YarnTestEnvironment();
+    } else if (isMesos) {
+      LOG.log(Level.INFO, "Running tests on Mesos");
+      return new MesosTestEnvironment();
+    } else {
+      LOG.log(Level.INFO, "Running tests on Local");
+      return new LocalTestEnvironment();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java
new file mode 100644
index 0000000..c901ec2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.client.LauncherStatus;
+import org.junit.Assert;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class TestUtils {
+
+  private static final Logger LOG = Logger.getLogger(TestUtils.class.getName());
+
+  /**
+   * Make sure the launcher status is FAILED and it has the specified exception in the stack.
+   *
+   * @param status launcher status. Must be FAILED for test to pass.
+   * @param clazz  resourcemanager exception that should be in the stack of exceptions of the launcher status.
+   */
+  public static void assertLauncherFailure(
+      final LauncherStatus status, final Class<? extends Throwable> clazz) {
+    Assert.assertEquals(LauncherStatus.FAILED, status);
+    final Throwable ex = status.getError().orElse(null);
+    if (!hasCause(ex, clazz)) {
+      LOG.log(Level.WARNING, "Unexpected Error: " + status, status.getError().get());
+      Assert.fail("Unexpected error: " + status.getError().orElse(null));
+    }
+  }
+
+  /**
+   * Return True if cause chain of exception ex contains
+   * exception of class clazz (or one inherited from it).
+   *
+   * @param ex    exception to analyze (can be null)
+   * @param clazz class inherited from type Throwable.
+   * @return True if ex or any other exception in its cause chain is instance of class clazz.
+   */
+  public static boolean hasCause(Throwable ex, final Class<? extends Throwable> clazz) {
+    for (; ex != null; ex = ex.getCause()) {
+      if (clazz.isInstance(ex)) {
+        return true;
+      }
+    }
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java
new file mode 100644
index 0000000..409f091
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests;
+
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+
+/**
+ * A TestEnvironment for the YARN resourcemanager.
+ */
+public final class YarnTestEnvironment extends TestEnvironmentBase implements TestEnvironment {
+
+  // Used to make sure the tests call the methods in the right order.
+  private boolean ready = false;
+
+  @Override
+  public synchronized final void setUp() {
+    this.ready = true;
+  }
+
+  @Override
+  public synchronized final Configuration getRuntimeConfiguration() {
+    assert (this.ready);
+    try {
+      return YarnClientConfiguration.CONF.build();
+    } catch (final BindException ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+
+  @Override
+  public synchronized final void tearDown() {
+    assert (this.ready);
+    this.ready = false;
+  }
+
+  @Override
+  public int getTestTimeout() {
+    return 300000; // 5 minutes
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java
new file mode 100644
index 0000000..30821b6
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.close_eval;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class CloseEvaluatorDriver {
+
+  private static final Logger LOG = Logger.getLogger(CloseEvaluatorDriver.class.getName());
+
+  private static final int NUM_EVALUATORS = 16;
+
+  private final EvaluatorRequestor requestor;
+
+  @Inject
+  CloseEvaluatorDriver(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+
+      LOG.log(Level.FINE, "StartTime: {0} :: request {1} evaluators",
+          new Object[]{time, NUM_EVALUATORS});
+
+      requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(NUM_EVALUATORS).setMemory(256).setNumberOfCores(1).build());
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      LOG.log(Level.FINE, "Allocated Evaluator: {0} :: closing", eval);
+      eval.close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java
new file mode 100644
index 0000000..7766f50
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.close_eval;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests evaluator allocation by asking for allocations that it immediately closes.
+ */
+public class CloseEvaluatorTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @Test
+  public void testCloseEvaluator() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(CloseEvaluatorDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_CloseEvaluatorTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, CloseEvaluatorDriver.StartHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java
new file mode 100644
index 0000000..9a56c80
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.driver;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * This tests whether the noop driver gets shutdown properly.
+ */
+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 runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    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 = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java
new file mode 100644
index 0000000..a2dcc4b
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorexit;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.logging.Logger;
+
+/**
+ * Tests whether an unexpected Evaluator exit (via System.exit()) is reported as a FailedEvaluator to the Driver.
+ */
+public final class EvaluatorExitTest {
+  private static final Logger LOG = Logger.getLogger(EvaluatorExitTest.class.getName());
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testEvaluatorExit() {
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorExit")
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(EvaluatorExitTestDriver.class))
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorExitTestDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, EvaluatorExitTestDriver.EvaluatorFailureHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, EvaluatorExitTestDriver.StopHandler.class)
+        .build();
+    final LauncherStatus status = this.testEnvironment.run(driverConfiguration);
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java
new file mode 100644
index 0000000..86a7be5
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorexit;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorExitTestDriver {
+  private static final Logger LOG = Logger.getLogger(EvaluatorExitTestDriver.class.getName());
+  private final AtomicBoolean failedEvaluatorReceived = new AtomicBoolean(false);
+
+  @Inject
+  EvaluatorExitTestDriver() {
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      final Configuration taskConfiguration = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "EvaluatorExitTestTask")
+          .set(TaskConfiguration.TASK, EvaluatorExitTestTask.class)
+          .build();
+      allocatedEvaluator.submitTask(taskConfiguration);
+    }
+  }
+
+  final class EvaluatorFailureHandler implements EventHandler<FailedEvaluator> {
+
+    @Override
+    public void onNext(final FailedEvaluator failedEvaluator) {
+      LOG.log(Level.FINEST, "Received a FailedEvaluator for Evaluator {0}", failedEvaluator.getId());
+      failedEvaluatorReceived.set(true);
+    }
+  }
+
+  final class StopHandler implements EventHandler<StopTime> {
+
+    @Override
+    public void onNext(final StopTime stopTime) {
+      synchronized (failedEvaluatorReceived) {
+        if (failedEvaluatorReceived.get()) {
+          LOG.log(Level.FINE, "Received an expected FailedEvaluator before exit. All good.");
+        } else {
+          throw new DriverSideFailure("Did not receive an expected FailedEvaluator.");
+        }
+      }
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java
new file mode 100644
index 0000000..b19bec0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorexit;
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+
+/**
+ * Merely calls System.exit()
+ */
+final class EvaluatorExitTestTask implements Task {
+
+  @Inject
+  EvaluatorExitTestTask() {
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws Exception {
+    System.exit(0);
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java
new file mode 100644
index 0000000..fb4fe07
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * This tests whether an unexpected Evaluator exit (via System.exit()) is reported as a FailedEvaluator to the Driver.
+ */
+package org.apache.reef.tests.evaluatorexit;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java
new file mode 100644
index 0000000..2845601
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorfailure;
+
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.TestUtils;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorFailureDuringAlarmDriver {
+  private static final Logger LOG = Logger.getLogger(EvaluatorFailureDuringAlarmDriver.class.getName());
+  private final AtomicBoolean failedEvaluatorReceived = new AtomicBoolean(false);
+  private final AtomicBoolean otherFailuresReceived = new AtomicBoolean(false);
+
+  @Inject
+  EvaluatorFailureDuringAlarmDriver() {
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(AllocatedEvaluator allocatedEvaluator) {
+      final Configuration contextConfiguration = ContextConfiguration.CONF
+          .set(ContextConfiguration.IDENTIFIER, "FailingEvaluator")
+          .set(ContextConfiguration.ON_CONTEXT_STARTED, FailureSchedulingContextStartHandler.class)
+          .build();
+      allocatedEvaluator.submitContext(contextConfiguration);
+    }
+  }
+
+  final class EvaluatorFailureHandler implements EventHandler<FailedEvaluator> {
+
+    @Override
+    public void onNext(final FailedEvaluator failedEvaluator) {
+      if (TestUtils.hasCause(failedEvaluator.getEvaluatorException(), ExpectedException.class)) {
+        failedEvaluatorReceived.set(true);
+        LOG.log(Level.FINEST, "Received an expected exception. All good.");
+      } else {
+        throw new DriverSideFailure("Received an unexpected exception", failedEvaluator.getEvaluatorException());
+      }
+    }
+  }
+
+  final class ContextFailureHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext failedContext) {
+      LOG.log(Level.SEVERE, "Received FailedContext: {0}", failedContext);
+      otherFailuresReceived.set(true);
+    }
+  }
+
+  final class TaskFailureHandler implements EventHandler<FailedTask> {
+
+    @Override
+    public void onNext(final FailedTask failedTask) {
+      LOG.log(Level.SEVERE, "Received FailedTask: {0}", failedTask);
+      otherFailuresReceived.set(true);
+
+    }
+  }
+
+  final class StopHandler implements EventHandler<StopTime> {
+
+    @Override
+    public void onNext(final StopTime stopTime) {
+      if (failedEvaluatorReceived.get()) {
+        LOG.log(Level.FINEST, "Received FailedEvaluator.");
+      } else {
+        throw new DriverSideFailure("Never Received the FailedEvaluator.");
+      }
+
+      if (otherFailuresReceived.get()) {
+        throw new DriverSideFailure("Received more events than the FailedEvaluator.");
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java
new file mode 100644
index 0000000..5aa1893
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorfailure;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether evaluator failures are generated properly.
+ */
+public class EvaluatorFailureTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  /**
+   * Tests that only an EvaluatorFailure is generated by exceptions thrown on by an Alarm handler.
+   */
+  @Test
+  public void testEvaluatorFailureByAlarmHandler() throws InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(EvaluatorFailureDuringAlarmDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorFailureTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorFailureDuringAlarmDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, EvaluatorFailureDuringAlarmDriver.EvaluatorFailureHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, EvaluatorFailureDuringAlarmDriver.ContextFailureHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, EvaluatorFailureDuringAlarmDriver.TaskFailureHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, EvaluatorFailureDuringAlarmDriver.StopHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("EvaluatorFailureTest.testEvaluatorFailureByAlarmHandler() state = " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java
new file mode 100644
index 0000000..6c9c6a2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorfailure;
+
+/**
+ * Exception thrown when one is expected.
+ */
+final class ExpectedException extends RuntimeException {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java
new file mode 100644
index 0000000..fc631da
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorfailure;
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A handler for ContextStart that schedules an Alarm handler that throws an Exception.
+ */
+final class FailureSchedulingContextStartHandler implements EventHandler<ContextStart> {
+  private static final Logger LOG = Logger.getLogger(FailureSchedulingContextStartHandler.class.getName());
+  private final Clock clock;
+
+  @Inject
+  FailureSchedulingContextStartHandler(final Clock clock) {
+    this.clock = clock;
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+    this.clock.scheduleAlarm(0, new EventHandler<Alarm>() {
+      @Override
+      public void onNext(Alarm alarm) {
+        LOG.log(Level.INFO, "Invoked for {0}, throwing an Exception now.", alarm);
+        throw new ExpectedException();
+      }
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java
new file mode 100644
index 0000000..7d1ae13
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Tests of evaluator failure generation.
+ */
+package org.apache.reef.tests.evaluatorfailure;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java
new file mode 100644
index 0000000..aca50f7
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorreuse;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests the reuse of Evaluators across Tasks by submitting the EchoTask for a number of times.
+ */
+public class EvaluatorReuseTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testEvaluatorReuse() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(EvaluatorReuseTestDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorReuseTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, EvaluatorReuseTestDriver.TaskCompletedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorReuseTestDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, EvaluatorReuseTestDriver.ContextActiveHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("EvaluatorReuse state = " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java
new file mode 100644
index 0000000..b7422d0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorsize;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether Evaluator allocations requested with a given amount of memory are (over-)fullfilled.
+ */
+public class EvaluatorSizeTest {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  private LauncherStatus runEvaluatorSizeTest(final int megaBytes) throws BindException, InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration testConfiguration = EvaluatorSizeTestConfiguration.CONF
+        .set(EvaluatorSizeTestConfiguration.MEMORY_SIZE, 777)
+        .build();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorSizeTest-" + megaBytes)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, EvaluatorSizeTestDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorSizeTestDriver.EvaluatorAllocatedHandler.class).build();
+
+    final Configuration mergedDriverConfiguration = Tang.Factory.getTang()
+        .newConfigurationBuilder(driverConfiguration, testConfiguration).build();
+
+    final LauncherStatus state = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(mergedDriverConfiguration, this.testEnvironment.getTestTimeout());
+    return state;
+  }
+
+
+  @Test
+  public void testEvaluatorSize() throws BindException, InjectionException {
+    final LauncherStatus state = runEvaluatorSizeTest(777);
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java
new file mode 100644
index 0000000..97719eb
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorsize;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+public final class EvaluatorSizeTestConfiguration extends ConfigurationModuleBuilder {
+
+  public static final RequiredParameter<Integer> MEMORY_SIZE = new RequiredParameter<>();
+  public static final ConfigurationModule CONF = new EvaluatorSizeTestConfiguration()
+      .bindNamedParameter(MemorySize.class, MEMORY_SIZE)
+      .build();
+
+  @NamedParameter(doc = "The size of the Evaluator to test for")
+  public static class MemorySize implements Name<Integer> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java
new file mode 100644
index 0000000..e91f8fc
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorsize;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorSizeTestDriver {
+  private static final Logger LOG = Logger.getLogger(EvaluatorSizeTestDriver.class.getName());
+
+  private final EvaluatorRequestor evaluatorRequestor;
+
+  private final int memorySize;
+
+  @Inject
+  public EvaluatorSizeTestDriver(final EvaluatorRequestor evaluatorRequestor,
+                                 final @Parameter(EvaluatorSizeTestConfiguration.MemorySize.class) int memorySize) {
+    this.evaluatorRequestor = evaluatorRequestor;
+    this.memorySize = memorySize;
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      EvaluatorSizeTestDriver.this.evaluatorRequestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1)
+          .setMemory(EvaluatorSizeTestDriver.this.memorySize)
+          .setNumberOfCores(1)
+          .build());
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+
+      final int evaluatorMemory = allocatedEvaluator.getEvaluatorDescriptor().getMemory();
+
+      if (evaluatorMemory < EvaluatorSizeTestDriver.this.memorySize) {
+        throw new DriverSideFailure(
+            "Got an Evaluator with too little RAM. Asked for " + EvaluatorSizeTestDriver.this.memorySize
+                + "MB, but got " + evaluatorMemory + "MB.");
+      }
+
+      // ALL good on the Driver side. Let's move on to the Task
+      try {
+        final Configuration taskConfiguration = TaskConfiguration.CONF
+            .set(TaskConfiguration.TASK, MemorySizeTask.class)
+            .set(TaskConfiguration.IDENTIFIER, "EvaluatorSizeTestTask")
+            .build();
+
+        final Configuration testConfiguration = EvaluatorSizeTestConfiguration.CONF
+            .set(EvaluatorSizeTestConfiguration.MEMORY_SIZE, EvaluatorSizeTestDriver.this.memorySize)
+            .build();
+
+        final Configuration mergedTaskConfiguration = Tang.Factory.getTang()
+            .newConfigurationBuilder(taskConfiguration, testConfiguration).build();
+
+        allocatedEvaluator.submitTask(mergedTaskConfiguration);
+
+      } catch (final BindException e) {
+        throw new DriverSideFailure("Unable to launch Task", e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java
new file mode 100644
index 0000000..3f64c46
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.evaluatorsize;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.library.exceptions.TaskSideFailure;
+
+import javax.inject.Inject;
+
+final class MemorySizeTask implements Task {
+
+  private static final int MEGA = 1048576;
+  private static final int allowedDelta = 128; // TODO: This should'nt be necessary. Could be the perm size we set.
+  private final int memorySize;
+
+  @Inject
+  public MemorySizeTask(final @Parameter(EvaluatorSizeTestConfiguration.MemorySize.class) int memorySize) {
+    this.memorySize = memorySize;
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws Exception {
+    final long maxHeapSizeInBytes = Runtime.getRuntime().maxMemory();
+
+    final long maxHeapSizeMB = maxHeapSizeInBytes / MEGA;
+    if (maxHeapSizeMB < (this.memorySize - allowedDelta)) {
+      throw new TaskSideFailure("Got an Evaluator with too little RAM. Asked for " + this.memorySize
+          + "MB, but got " + maxHeapSizeMB + "MB.");
+    }
+    return new byte[0];
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java
new file mode 100644
index 0000000..e796438
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Test for the evaluator size request: Is it being honored by the resourcemanager?
+ */
+package org.apache.reef.tests.evaluatorsize;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java
new file mode 100644
index 0000000..4c48159
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.examples;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A Test suite that runs the REEF example tests.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    TestHelloREEF.class,
+    TestRetainedEvaluators.class
+})
+public final class ExamplesTestSuite {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java
new file mode 100644
index 0000000..2eae5d4
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.tests.examples;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.examples.hello.HelloDriver;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether the HelloREEF example runs sucesfully.
+ */
+public class TestHelloREEF {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testHelloREEF() {
+    final Configuration driverConf = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_HelloREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
+        .build();
+    final LauncherStatus state = this.testEnvironment.run(driverConf);
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+  }
+
+}