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:40 UTC

[07/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-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java
new file mode 100644
index 0000000..7205d4a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java
@@ -0,0 +1,27 @@
+/**
+ * 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.tang.test;
+
+/**
+ * Interface used for the set injecttion test.
+ */
+interface SetInterface {
+
+  void aMethod();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java
new file mode 100644
index 0000000..3d9f0c7
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java
@@ -0,0 +1,56 @@
+/**
+ * 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.tang.test;
+
+import javax.inject.Inject;
+
+/**
+ * Created by mweimer on 3/18/14.
+ */
+final class SetInterfaceImplOne implements SetInterface {
+
+  private final int magicNumber;
+
+  @Inject
+  public SetInterfaceImplOne() {
+    this.magicNumber = 42;
+  }
+
+  @Override
+  public void aMethod() {
+
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetInterfaceImplOne that = (SetInterfaceImplOne) o;
+
+    if (magicNumber != that.magicNumber) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return magicNumber;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java
new file mode 100644
index 0000000..4e8bb3a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.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.tang.test;
+
+import javax.inject.Inject;
+
+final class SetInterfaceImplTwo implements SetInterface {
+
+  private final double magicNumber;
+
+  @Inject
+  SetInterfaceImplTwo() {
+    this.magicNumber = 42.0;
+  }
+
+  @Override
+  public void aMethod() {
+
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetInterfaceImplTwo that = (SetInterfaceImplTwo) o;
+
+    if (Double.compare(that.magicNumber, magicNumber) != 0) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    long temp = Double.doubleToLongBits(magicNumber);
+    return (int) (temp ^ (temp >>> 32));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java
new file mode 100644
index 0000000..fda1504
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java
@@ -0,0 +1,85 @@
+/**
+ * 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.tang.test;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.Set;
+
+/**
+ * A class that depends on sets of base types.
+ */
+final class SetOfBaseTypes {
+  private final Set<Integer> integers;
+  private final Set<Double> doubles;
+  private final Set<String> strings;
+  private final Set<Integer> moreIntegers;
+
+  @Inject
+  SetOfBaseTypes(@Parameter(Integers.class) final Set<Integer> integers,
+                 @Parameter(Doubles.class) final Set<Double> doubles,
+                 @Parameter(Strings.class) final Set<String> strings,
+                 @Parameter(MoreIntegers.class) final Set<Integer> moreIntegers) {
+    this.integers = integers;
+    this.doubles = doubles;
+    this.strings = strings;
+    this.moreIntegers = moreIntegers;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetOfBaseTypes that = (SetOfBaseTypes) o;
+
+    if (!doubles.equals(that.doubles)) return false;
+    if (!integers.equals(that.integers)) return false;
+    if (!strings.equals(that.strings)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = integers.hashCode();
+    result = 31 * result + doubles.hashCode();
+    result = 31 * result + strings.hashCode();
+    return result;
+  }
+
+  @NamedParameter
+  public static class Integers implements Name<Set<Integer>> {
+  }
+
+  @NamedParameter(default_values = {"1", "2", "3"})
+  public static class MoreIntegers implements Name<Set<Integer>> {
+  }
+
+  @NamedParameter
+  public static class Doubles implements Name<Set<Double>> {
+  }
+
+  @NamedParameter
+  public static class Strings implements Name<Set<String>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java
new file mode 100644
index 0000000..5372af2
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java
@@ -0,0 +1,55 @@
+/**
+ * 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.tang.test;
+
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.Set;
+
+final class SetOfImplementations {
+
+  private final Set<SetInterface> theInstances;
+
+  @Inject
+  SetOfImplementations(@Parameter(TestConfiguration.SetOfInstances.class) final Set<SetInterface> theInstances) {
+    this.theInstances = theInstances;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetOfImplementations that = (SetOfImplementations) o;
+
+    if (!theInstances.equals(that.theInstances)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return theInstances.hashCode();
+  }
+
+  public boolean isValid() {
+    return this.theInstances.size() == 2;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java
new file mode 100644
index 0000000..98f1329
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java
@@ -0,0 +1,110 @@
+/**
+ * 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.tang.test;
+
+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.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * All the configuration parameters and options for the test.
+ */
+public class TestConfiguration extends ConfigurationModuleBuilder {
+  public static final String REQUIRED_STRING_VALUE = "Required String Value";
+  public static final String OPTIONAL_STRING_VALUE = "Optional String Value";
+  public static final RequiredParameter<String> REQUIRED_STRING = new RequiredParameter<>();
+  public static final OptionalParameter<String> OPTIONAL_STRING = new OptionalParameter<>();
+  public static final int NAMED_PARAMETER_INTEGER_VALUE = 42;
+  public static final double NAMED_PARAMETER_DOUBLE_VALUE = 42.0;
+  // Pre-defined lists used in injection
+  private static final List<Class<? extends ListInterface>> injectedImplList = Arrays.asList(ListInterfaceImplOne.class,
+      ListInterfaceImplTwo.class);
+  private static final List<String> injectedIntegerList = Arrays.asList("1", "2", "3");
+  private static final List<String> injectedDoubleList = Arrays.asList("1", "2", "3");
+  private static final List<String> injectedStringList = Arrays.asList("1", "2", "3");
+
+  public static final ConfigurationModule CONF = new TestConfiguration()
+      .bindImplementation(RootInterface.class, RootImplementation.class)
+      .bindNamedParameter(IntegerHandler.class, UnitClass.IntegerHandler.class)
+      .bindNamedParameter(StringHandler.class, UnitClass.StringHandler.class)
+      .bindNamedParameter(NamedParameterInteger.class, String.valueOf(NAMED_PARAMETER_INTEGER_VALUE))
+      .bindNamedParameter(NamedParameterDouble.class, String.valueOf(NAMED_PARAMETER_DOUBLE_VALUE))
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplOne.class)
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplTwo.class)
+          // Adds list implementations
+      .bindList(ListOfInstances.class, injectedImplList)
+      .bindNamedParameter(RequiredString.class, REQUIRED_STRING)
+      .bindNamedParameter(OptionalString.class, OPTIONAL_STRING)
+          // Sets of base types
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "3")
+          // Lists of base types
+      .bindList(ListOfBaseTypes.Integers.class, injectedIntegerList)
+      .bindList(ListOfBaseTypes.Doubles.class, injectedDoubleList)
+      .bindList(ListOfBaseTypes.Strings.class, injectedStringList)
+      .build();
+
+  @NamedParameter()
+  public static final class RequiredString implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "default_string_default_value")
+  public static final class OptionalString implements Name<String> {
+  }
+
+  @NamedParameter()
+  public static final class IntegerHandler implements Name<Handler<Integer>> {
+  }
+
+  @NamedParameter()
+  public static final class StringHandler implements Name<Handler<String>> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterInteger implements Name<Integer> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterDouble implements Name<Double> {
+  }
+
+  @NamedParameter
+  public static final class SetOfInstances implements Name<Set<SetInterface>> {
+  }
+
+  @NamedParameter
+  public static final class ListOfInstances implements Name<List<ListInterface>> {
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java
new file mode 100644
index 0000000..36b9704
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java
@@ -0,0 +1,92 @@
+/**
+ * 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.tang.test;
+
+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.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.util.Set;
+
+/**
+ * All the configuration parameters and options for the test without list
+ */
+public class TestConfigurationWithoutList extends ConfigurationModuleBuilder {
+  public static final String REQUIRED_STRING_VALUE = "Required String Value";
+  public static final String OPTIONAL_STRING_VALUE = "Optional String Value";
+  public static final RequiredParameter<String> REQUIRED_STRING = new RequiredParameter<>();
+  public static final OptionalParameter<String> OPTIONAL_STRING = new OptionalParameter<>();
+  public static final int NAMED_PARAMETER_INTEGER_VALUE = 42;
+  public static final double NAMED_PARAMETER_DOUBLE_VALUE = 42.0;
+  public static final ConfigurationModule CONF = new TestConfigurationWithoutList()
+      .bindImplementation(RootInterface.class, RootImplementationWithoutList.class)
+      .bindNamedParameter(IntegerHandler.class, UnitClass.IntegerHandler.class)
+      .bindNamedParameter(StringHandler.class, UnitClass.StringHandler.class)
+      .bindNamedParameter(NamedParameterInteger.class, String.valueOf(NAMED_PARAMETER_INTEGER_VALUE))
+      .bindNamedParameter(NamedParameterDouble.class, String.valueOf(NAMED_PARAMETER_DOUBLE_VALUE))
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplOne.class)
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplTwo.class)
+          // Adds list implementations
+      .bindNamedParameter(RequiredString.class, REQUIRED_STRING)
+      .bindNamedParameter(OptionalString.class, OPTIONAL_STRING)
+          // Sets of base types
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "3")
+          // Lists of base types
+      .build();
+
+  // TODO: Remove this method after #192 is fixed
+  @NamedParameter()
+  public static final class RequiredString implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "default_string_default_value")
+  public static final class OptionalString implements Name<String> {
+  }
+
+  @NamedParameter()
+  public static final class IntegerHandler implements Name<Handler<Integer>> {
+  }
+
+  @NamedParameter()
+  public static final class StringHandler implements Name<Handler<String>> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterInteger implements Name<Integer> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterDouble implements Name<Double> {
+  }
+
+  @NamedParameter
+  public static final class SetOfInstances implements Name<Set<SetInterface>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java
new file mode 100644
index 0000000..684a09f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java
@@ -0,0 +1,119 @@
+/**
+ * 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.tang.test;
+
+import org.apache.reef.tang.annotations.Unit;
+
+import javax.inject.Inject;
+
+/**
+ * A test user for the @Unit annotation
+ */
+@Unit
+final class UnitClass {
+  private String stringValue;
+  private int intValue;
+
+  @Inject
+  UnitClass() {
+
+  }
+
+  public String getStringValue() {
+    return stringValue;
+  }
+
+  public int getIntValue() {
+    return intValue;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    UnitClass unitClass = (UnitClass) o;
+
+    if (intValue != unitClass.intValue) return false;
+    if (stringValue != null ? !stringValue.equals(unitClass.stringValue) : unitClass.stringValue != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = stringValue != null ? stringValue.hashCode() : 0;
+    result = 31 * result + intValue;
+    return result;
+  }
+
+  final class IntegerHandler implements Handler<Integer> {
+    final int foo = 42;
+
+    @Override
+    public void process(final Integer value) {
+      UnitClass.this.intValue = value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      IntegerHandler that = (IntegerHandler) o;
+
+      if (foo != that.foo) return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return foo;
+    }
+  }
+
+  final class StringHandler implements Handler<String> {
+    final int bar = -42;
+
+    @Override
+    public void process(final String value) {
+      UnitClass.this.stringValue = value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      StringHandler that = (StringHandler) o;
+
+      if (bar != that.bar) return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return bar;
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java
new file mode 100644
index 0000000..5fb2159
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/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 holds an integration test of most if not all of Tang's functionality.
+ */
+package org.apache.reef.tang.test;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/resources/Event.bin
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/resources/Event.bin b/lang/java/reef-tang/tang/src/test/resources/Event.bin
new file mode 100644
index 0000000..7f21ea6
Binary files /dev/null and b/lang/java/reef-tang/tang/src/test/resources/Event.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/resources/Task.bin
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/resources/Task.bin b/lang/java/reef-tang/tang/src/test/resources/Task.bin
new file mode 100644
index 0000000..a71273e
Binary files /dev/null and b/lang/java/reef-tang/tang/src/test/resources/Task.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/pom.xml b/lang/java/reef-tests/pom.xml
new file mode 100644
index 0000000..ee21633
--- /dev/null
+++ b/lang/java/reef-tests/pom.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0"?>
+<!--
+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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>reef-tests</artifactId>
+    <name>REEF Tests</name>
+    <description>Integration tests for REEF</description>
+
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-mesos</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-poison</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-examples</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptors>
+                        <descriptor>src/main/assembly/test-jar-with-dependencies.xml</descriptor>
+                    </descriptors>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+
+    <profiles>
+        <profile>
+            <id>test</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <forkMode>pertest</forkMode>
+                            <!-- <useManifestOnlyJar>false</useManifestOnlyJar>
+                            <useSystemClassLoader>false</useSystemClassLoader> -->
+                            <systemPropertyVariables>
+                                <propertyName>java.util.logging.config.class</propertyName>
+                                <propertyValue>org.apache.reef.util.logging.Config</propertyValue>
+                            </systemPropertyVariables>
+                            <additionalClasspathElements>
+                                <additionalClasspathElement>${env.YARN_CONF_DIR}</additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/common/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/common/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/contrib/capacity-scheduler/*.jar
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/hdfs
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/hdfs/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/hdfs/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/yarn/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/yarn/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/mapreduce/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/mapreduce/*
+                                </additionalClasspathElement>
+                            </additionalClasspathElements>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml b/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml
new file mode 100644
index 0000000..b0fb0a1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml
@@ -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.
+
+-->
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+    <id>test-jar-with-dependencies</id>
+    <formats>
+        <format>jar</format>
+    </formats>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <dependencySets>
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <useProjectAttachments>true</useProjectAttachments>
+            <unpack>true</unpack>
+            <scope>test</scope>
+        </dependencySet>
+    </dependencySets>
+</assembly>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java
new file mode 100644
index 0000000..96f3172
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java
@@ -0,0 +1,132 @@
+/**
+ * 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.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.client.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A launcher for REEF Drivers. It behaves exactly like the original DriverLauncher,
+ * but does not dump the exception stack trace to the log. (it writes only a short INFO message).
+ * It is used in TestFailDriver etc. unit tests.
+ */
+@Public
+@Provided
+@ClientSide
+@Unit
+public final class TestDriverLauncher {
+
+  private static final Logger LOG = Logger.getLogger(TestDriverLauncher.class.getName());
+
+  private final DriverLauncher launcher;
+
+  @Inject
+  private TestDriverLauncher(final DriverLauncher launcher) {
+    this.launcher = launcher;
+  }
+
+  /**
+   * Instantiate a launcher for the given Configuration.
+   *
+   * @param runtimeConfiguration the resourcemanager configuration to be used
+   * @return a DriverLauncher based on the given resourcemanager configuration
+   * @throws org.apache.reef.tang.exceptions.BindException      on configuration errors
+   * @throws org.apache.reef.tang.exceptions.InjectionException on configuration errors
+   */
+  public static TestDriverLauncher getLauncher(
+      final Configuration runtimeConfiguration) throws BindException, InjectionException {
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, DriverLauncher.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, DriverLauncher.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, SilentRuntimeErrorHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, SilentFailedTestJobHandler.class)
+        .build();
+
+    return Tang.Factory.getTang()
+        .newInjector(runtimeConfiguration, clientConfiguration)
+        .getInstance(TestDriverLauncher.class);
+  }
+
+  public void close() {
+    this.launcher.close();
+  }
+
+  /**
+   * Run a job. Waits indefinitely for the job to complete.
+   *
+   * @param driverConfig the configuration for the driver. See DriverConfiguration for details.
+   * @return the state of the job after execution.
+   */
+  public LauncherStatus run(final Configuration driverConfig) {
+    return this.launcher.run(driverConfig);
+  }
+
+  /**
+   * Run a job with a waiting timeout after which it will be killed, if it did not complete yet.
+   *
+   * @param driverConfig the configuration for the driver. See DriverConfiguration for details.
+   * @param timeOut      timeout on the job.
+   * @return the state of the job after execution.
+   */
+  public LauncherStatus run(final Configuration driverConfig, final long timeOut) {
+    return this.launcher.run(driverConfig, timeOut);
+  }
+
+  @Override
+  public String toString() {
+    return this.launcher.toString();
+  }
+
+  /**
+   * Handler an error in the job driver.
+   */
+  protected final class SilentRuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.INFO, "Received a runtime error: {0}", error);
+      launcher.setStatusAndNotify(LauncherStatus.FAILED(error.getReason()));
+    }
+  }
+
+  /**
+   * Job driver notifies us that the job had failed.
+   */
+  protected final class SilentFailedTestJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      final Optional<Throwable> ex = job.getReason();
+      LOG.log(Level.INFO, "Received an error for job {0}: {1}", new Object[]{job.getId(), ex});
+      launcher.setStatusAndNotify(LauncherStatus.FAILED(ex));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java
new file mode 100644
index 0000000..1431fe2
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A StartHandler that does nothing.
+ */
+final class DriverTestStartHandler implements EventHandler<StartTime> {
+  private static final Logger LOG = Logger.getLogger(DriverTestStartHandler.class.getName());
+
+
+  @Inject
+  DriverTestStartHandler() {
+  }
+
+  @Override
+  public void onNext(final StartTime startTime) {
+    LOG.log(Level.FINE, "StartTime: {0}", startTime);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java
new file mode 100644
index 0000000..37544a1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/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 whether a Driver can successfully be launched and shut down.
+ */
+package org.apache.reef.tests.driver;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java
new file mode 100644
index 0000000..b1be469
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java
@@ -0,0 +1,118 @@
+/**
+ * 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.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+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.UnexpectedTaskReturnValue;
+import org.apache.reef.tests.library.tasks.EchoTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import javax.xml.bind.DatatypeConverter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorReuseTestDriver {
+
+  private static final Logger LOG = Logger.getLogger(EvaluatorReuseTestDriver.class.getName());
+
+  private final int numberOfIterations;
+  private final JobMessageObserver client;
+
+  private int counter = 0;
+  private String lastMessage = null;
+
+  @Inject
+  EvaluatorReuseTestDriver(final @Parameter(NumberOfIterations.class) int n,
+                           final JobMessageObserver client) {
+    this.numberOfIterations = n;
+    this.client = client;
+  }
+
+  private void startTask(final ActiveContext context) {
+    if (counter < numberOfIterations) {
+      try {
+        this.lastMessage = "ECHO-" + counter;
+        client.sendMessageToClient(("Submitting iteration " + counter).getBytes());
+        final String memento = DatatypeConverter.printBase64Binary(this.lastMessage.getBytes());
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, this.lastMessage)
+            .set(TaskConfiguration.TASK, EchoTask.class)
+            .set(TaskConfiguration.MEMENTO, memento)
+            .build());
+        counter += 1;
+      } catch (final BindException e) {
+        context.close();
+        throw new RuntimeException(e);
+      }
+    } else {
+      client.sendMessageToClient("Done. Closing the Context".getBytes());
+      context.close();
+    }
+  }
+
+  @NamedParameter(default_value = "3", short_name = "i")
+  class NumberOfIterations implements Name<Integer> {
+  }
+
+  final class TaskCompletedHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask completed) {
+      final String returned = new String(completed.get());
+      final String msg = "CompletedTask returned: \"" + returned + "\"";
+      client.sendMessageToClient(msg.getBytes());
+      if (!returned.equals(lastMessage)) {
+        throw new UnexpectedTaskReturnValue(lastMessage, returned);
+      } else {
+        startTask(completed.getActiveContext());
+      }
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eb) {
+      LOG.log(Level.FINE, "AllocatedEvaluator: " + eb);
+      try {
+        eb.submitContext(ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "EvaluatorReuse").build());
+      } catch (BindException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  final class ContextActiveHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      startTask(context);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java
new file mode 100644
index 0000000..fe021c1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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 package contains a test of the Evaluator reuse. It submits the EchoTask several times to the same Evaluator.
+ * This test also incidentially tests whether the memento is transferred correctly from and to the Task.
+ */
+package org.apache.reef.tests.evaluatorreuse;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java
new file mode 100644
index 0000000..51883e1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java
@@ -0,0 +1,98 @@
+/**
+ * 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.fail.driver;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ContextConfiguration;
+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.FailedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.fail.task.FailTaskCall;
+import org.apache.reef.tests.library.exceptions.SimulatedDriverFailure;
+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
+public final class DriverFailOnFail {
+
+  private static final Logger LOG = Logger.getLogger(DriverFailOnFail.class.getName());
+
+  private final transient JobMessageObserver client;
+  private final transient EvaluatorRequestor requestor;
+
+  @Inject
+  public DriverFailOnFail(final JobMessageObserver client, final EvaluatorRequestor requestor) {
+    this.client = client;
+    this.requestor = requestor;
+  }
+
+  public final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+
+      try {
+
+        LOG.log(Level.INFO, "Submit task: Fail2");
+
+        final Configuration contextConfig = ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "Fail2")
+            .build();
+
+        final Configuration taskConfig = TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "Fail2")
+            .set(TaskConfiguration.TASK, FailTaskCall.class)
+            .build();
+
+        eval.submitContextAndTask(contextConfig, taskConfig);
+
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  public final class FailedTaskHandler implements EventHandler<FailedTask> {
+    @Override
+    public void onNext(final FailedTask task) throws SimulatedDriverFailure {
+      final SimulatedDriverFailure error = new SimulatedDriverFailure(
+          "Simulated Failure at DriverFailOnFail :: " + task.getClass().getName(), task.asError());
+      LOG.log(Level.INFO, "Simulated Failure: {0}", error);
+      throw error;
+    }
+  }
+
+  public final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      LOG.log(Level.INFO, "StartTime: {0}", time);
+      DriverFailOnFail.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java
new file mode 100644
index 0000000..1769e53
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.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.fail.driver;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+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.TestDriverLauncher;
+import org.apache.reef.util.EnvironmentUtils;
+
+/**
+ * Client for the test REEF job that fails on different stages of execution.
+ */
+public final class FailClient {
+
+  public static LauncherStatus run(final Class<?> failMsgClass,
+                                   final Configuration runtimeConfig,
+                                   final int timeOut) throws BindException, InjectionException {
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(FailDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "Fail_" + failMsgClass.getSimpleName())
+        .set(DriverConfiguration.ON_DRIVER_STARTED, FailDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, FailDriver.StopHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FailDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, FailDriver.CompletedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, FailDriver.FailedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, FailDriver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_MESSAGE, FailDriver.ContextMessageHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, FailDriver.ClosedContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, FailDriver.FailedContextHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, FailDriver.RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_SUSPENDED, FailDriver.SuspendedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_MESSAGE, FailDriver.TaskMessageHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, FailDriver.FailedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, FailDriver.CompletedTaskHandler.class)
+        .build();
+
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.addConfiguration(driverConfig);
+    cb.bindNamedParameter(FailDriver.FailMsgClassName.class, failMsgClass.getName());
+
+    return TestDriverLauncher.getLauncher(runtimeConfig).run(cb.build(), timeOut);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java
new file mode 100644
index 0000000..15f70c7
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java
@@ -0,0 +1,371 @@
+/**
+ * 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.fail.driver;
+
+import org.apache.reef.driver.context.*;
+import org.apache.reef.driver.evaluator.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+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.tests.library.exceptions.SimulatedDriverFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import javax.xml.bind.DatatypeConverter;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.apache.reef.tests.fail.driver.FailDriver.ExpectedMessage.RequiredFlag.OPTIONAL;
+import static org.apache.reef.tests.fail.driver.FailDriver.ExpectedMessage.RequiredFlag.REQUIRED;
+
+@Unit
+public final class FailDriver {
+
+  private static final Logger LOG = Logger.getLogger(FailDriver.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final byte[] HELLO_STR = CODEC.encode("MESSAGE::HELLO");
+  /**
+   * Send message to the Task MSG_DELAY milliseconds after start.
+   */
+  private static final int MSG_DELAY = 1000;
+  private static final ExpectedMessage[] EVENT_SEQUENCE = {
+      new ExpectedMessage(FailDriver.class, REQUIRED),
+      new ExpectedMessage(StartTime.class, REQUIRED),
+      new ExpectedMessage(AllocatedEvaluator.class, REQUIRED),
+      new ExpectedMessage(FailedEvaluator.class, OPTIONAL),
+      new ExpectedMessage(ActiveContext.class, REQUIRED),
+      new ExpectedMessage(ContextMessage.class, OPTIONAL),
+      new ExpectedMessage(FailedContext.class, OPTIONAL),
+      new ExpectedMessage(RunningTask.class, REQUIRED),
+      new ExpectedMessage(Alarm.class, REQUIRED),
+      new ExpectedMessage(TaskMessage.class, REQUIRED),
+      new ExpectedMessage(Alarm.class, REQUIRED),
+      new ExpectedMessage(SuspendedTask.class, REQUIRED),
+      new ExpectedMessage(RunningTask.class, REQUIRED),
+      new ExpectedMessage(Alarm.class, REQUIRED),
+      new ExpectedMessage(FailedTask.class, OPTIONAL),
+      new ExpectedMessage(CompletedTask.class, REQUIRED),
+      new ExpectedMessage(ClosedContext.class, OPTIONAL),
+      new ExpectedMessage(CompletedEvaluator.class, REQUIRED),
+      new ExpectedMessage(StopTime.class, REQUIRED)
+  };
+  private final transient Class<?> failMsgClass;
+  private final transient EvaluatorRequestor requestor;
+  private final transient Clock clock;
+  private transient RunningTask task = null;
+  private transient int expectIdx = 0;
+  private transient DriverState state = DriverState.INIT;
+
+  @Inject
+  public FailDriver(final @Parameter(FailMsgClassName.class) String failMsgClassName,
+                    final EvaluatorRequestor requestor, final Clock clock)
+      throws ClassNotFoundException {
+    this.failMsgClass = ClassLoader.getSystemClassLoader().loadClass(failMsgClassName);
+    this.requestor = requestor;
+    this.clock = clock;
+    this.checkMsgOrder(this);
+  }
+
+  /**
+   * Check if observer methods are called in the right order
+   * and generate an exception at the given point in the message sequence.
+   *
+   * @param msg a message from one of the observers.
+   * @throws SimulatedDriverFailure if failMsgClass matches the message class.
+   * @throws DriverSideFailure      if messages are out of order.
+   */
+  private void checkMsgOrder(final Object msg) throws SimulatedDriverFailure, DriverSideFailure {
+
+    final String msgClassName = msg.getClass().getName();
+    LOG.log(Level.FINE, "At {0} {1}:{2}", new Object[]{
+        this.state, this.expectIdx, msgClassName});
+
+    if (this.state == DriverState.FAILED) {
+      // If already failed, do not do anything
+      return;
+    }
+
+    // Simulate failure at this step?
+    if (this.failMsgClass.isInstance(msg)) {
+      this.state = DriverState.FAILED;
+    }
+
+    // Make sure events arrive in the right order (specified in EVENT_SEQUENCE):
+    boolean notFound = true;
+    for (; this.expectIdx < EVENT_SEQUENCE.length; ++this.expectIdx) {
+      if (EVENT_SEQUENCE[expectIdx].msgClass.isInstance(msg)) {
+        notFound = false;
+        break;
+      } else if (EVENT_SEQUENCE[expectIdx].requiredFlag == REQUIRED) {
+        break;
+      }
+    }
+
+    if (notFound) {
+      LOG.log(Level.SEVERE, "Event out of sequence: {0} {1}:{2}",
+          new Object[]{this.state, this.expectIdx, msgClassName});
+      throw new DriverSideFailure("Event out of sequence: " + msgClassName);
+    }
+
+    LOG.log(Level.INFO, "{0}: send: {1} got: {2}", new Object[]{
+        this.state, EVENT_SEQUENCE[this.expectIdx], msgClassName});
+
+    ++this.expectIdx;
+
+    if (this.state == DriverState.FAILED) {
+      final SimulatedDriverFailure ex = new SimulatedDriverFailure(
+          "Simulated Failure at FailDriver :: " + msgClassName);
+      LOG.log(Level.INFO, "Simulated Failure: {0}", ex);
+      throw ex;
+    }
+  }
+
+  private enum DriverState {INIT, SEND_MSG, SUSPEND, RESUME, CLOSE, FAILED}
+
+  /**
+   * Name of the message class to specify the failing message handler.
+   */
+  @NamedParameter(doc = "Full name of the message class to fail on", short_name = "fail")
+  public static final class FailMsgClassName implements Name<String> {
+  }
+
+  public static final class ExpectedMessage {
+
+    public final transient Class<?> msgClass;
+    public final transient RequiredFlag requiredFlag;
+    private final transient String repr;
+
+    public ExpectedMessage(final Class<?> clazz, final RequiredFlag requiredFlag) {
+      this.msgClass = clazz;
+      this.requiredFlag = requiredFlag;
+      this.repr = this.msgClass.getSimpleName() + ":" + this.requiredFlag;
+    }
+
+    @Override
+    public String toString() {
+      return this.repr;
+    }
+
+    public enum RequiredFlag {OPTIONAL, REQUIRED}
+  }
+
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      checkMsgOrder(eval);
+      try {
+        eval.submitContext(ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "FailContext_" + eval.getId())
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Context configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  final class CompletedEvaluatorHandler implements EventHandler<CompletedEvaluator> {
+    @Override
+    public void onNext(final CompletedEvaluator eval) {
+      checkMsgOrder(eval);
+      // noop
+    }
+  }
+
+  final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator eval) {
+      LOG.log(Level.WARNING, "Evaluator failed: " + eval.getId(), eval.getEvaluatorException());
+      checkMsgOrder(eval);
+      throw new RuntimeException(eval.getEvaluatorException());
+    }
+  }
+
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      checkMsgOrder(context);
+      try {
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "FailTask_" + context.getId())
+            .set(TaskConfiguration.TASK, NoopTask.class)
+            .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
+            .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
+            .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
+            .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
+            .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Task configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  final class ContextMessageHandler implements EventHandler<ContextMessage> {
+    @Override
+    public void onNext(final ContextMessage message) {
+      checkMsgOrder(message);
+      // noop
+    }
+  }
+
+  final class ClosedContextHandler implements EventHandler<ClosedContext> {
+    @Override
+    public void onNext(final ClosedContext context) {
+      checkMsgOrder(context);
+      // noop
+    }
+  }
+
+  final class FailedContextHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext context) {
+      LOG.log(Level.WARNING, "Context failed: " + context.getId(), context.getReason().orElse(null));
+      checkMsgOrder(context);
+      // TODO: notify client?
+
+      // if (context.getParentContext().isPresent()) {
+      //   context.getParentContext().get().close();
+      // }
+    }
+  }
+
+  final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      checkMsgOrder(task);
+      FailDriver.this.task = task;
+      switch (state) {
+        case INIT:
+          state = DriverState.SEND_MSG;
+          break;
+        case RESUME:
+          state = DriverState.CLOSE;
+          break;
+        default:
+          LOG.log(Level.WARNING, "Unexpected state at TaskRuntime: {0}", state);
+          throw new DriverSideFailure("Unexpected state: " + state);
+      }
+      // After a delay, send message or suspend the task:
+      clock.scheduleAlarm(MSG_DELAY, new AlarmHandler());
+    }
+  }
+
+  final class SuspendedTaskHandler implements EventHandler<SuspendedTask> {
+    @Override
+    public void onNext(final SuspendedTask task) {
+      checkMsgOrder(task);
+      state = DriverState.RESUME;
+      try {
+        task.getActiveContext().submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, task.getId() + "_RESUMED")
+            .set(TaskConfiguration.TASK, NoopTask.class)
+            .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
+            .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
+            .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
+            .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
+            .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
+            .set(TaskConfiguration.MEMENTO, DatatypeConverter.printBase64Binary(HELLO_STR))
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.SEVERE, "Task configuration error", ex);
+        throw new DriverSideFailure("Task configuration error", ex);
+      }
+    }
+  }
+
+  final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage msg) {
+      checkMsgOrder(msg);
+      assert (Arrays.equals(HELLO_STR, msg.get()));
+      assert (state == DriverState.SEND_MSG);
+      state = DriverState.SUSPEND;
+      clock.scheduleAlarm(MSG_DELAY, new AlarmHandler());
+    }
+  }
+
+  final class FailedTaskHandler implements EventHandler<FailedTask> {
+    @Override
+    public void onNext(final FailedTask task) {
+      LOG.log(Level.WARNING, "Task failed: " + task.getId(), task.getReason().orElse(null));
+      checkMsgOrder(task);
+      if (task.getActiveContext().isPresent()) {
+        task.getActiveContext().get().close();
+      }
+    }
+  }
+
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      checkMsgOrder(task);
+      task.getActiveContext().close();
+    }
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      FailDriver.this.checkMsgOrder(time);
+      FailDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+
+  final class AlarmHandler implements EventHandler<Alarm> {
+    @Override
+    public void onNext(final Alarm time) {
+      FailDriver.this.checkMsgOrder(time);
+      switch (FailDriver.this.state) {
+        case SEND_MSG:
+          FailDriver.this.task.send(HELLO_STR);
+          break;
+        case SUSPEND:
+          FailDriver.this.task.suspend();
+          break;
+        case CLOSE:
+          FailDriver.this.task.close();
+          break;
+        default:
+          LOG.log(Level.WARNING, "Unexpected state at AlarmHandler: {0}", FailDriver.this.state);
+          throw new DriverSideFailure("Unexpected state: " + FailDriver.this.state);
+      }
+    }
+  }
+
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      FailDriver.this.checkMsgOrder(time);
+      // noop
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java
new file mode 100644
index 0000000..332a4c9
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java
@@ -0,0 +1,128 @@
+/**
+ * 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.fail.driver;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+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.RunningTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public final class FailDriverDelayedMsg {
+
+  private static final Logger LOG = Logger.getLogger(FailDriverDelayedMsg.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final byte[] HELLO_STR = CODEC.encode("MESSAGE::HELLO");
+
+  private final transient EvaluatorRequestor requestor;
+  private final transient Clock clock;
+  private transient RunningTask task = null;
+
+  @Inject
+  public FailDriverDelayedMsg(final EvaluatorRequestor requestor, final Clock clock) {
+    LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.<init>");
+    this.requestor = requestor;
+    this.clock = clock;
+  }
+
+  public final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(AllocatedEvaluator): {0}", eval);
+      try {
+        eval.submitContext(ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "Context_" + eval.getId())
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Context configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  public final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(ActiveContext): {0}", context);
+      try {
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "Task_" + context.getId())
+            .set(TaskConfiguration.TASK, NoopTask.class)
+            .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
+            .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
+            .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
+            .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
+            .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Task configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  public final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      FailDriverDelayedMsg.this.task = task;
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(TaskRuntime): {0}", task);
+      FailDriverDelayedMsg.this.clock.scheduleAlarm(2000, new EventHandler<Alarm>() {
+        @Override
+        public void onNext(final Alarm time) {
+          LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(Alarm): {0}", time);
+          task.send(HELLO_STR);
+        }
+      });
+    }
+  }
+
+  public final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage msg) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(TaskMessage): {0}", msg);
+      assert (Arrays.equals(HELLO_STR, msg.get()));
+      FailDriverDelayedMsg.this.task.close();
+    }
+  }
+
+  public final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(StartTime): {0}", time);
+      FailDriverDelayedMsg.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java
new file mode 100644
index 0000000..7250004
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java
@@ -0,0 +1,117 @@
+/**
+ * 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.fail.driver;
+
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.TaskMessage;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that quite successfully does nothing.
+ */
+@Unit
+public final class NoopTask implements Task, TaskMessageSource {
+
+  private static final Logger LOG = Logger.getLogger(NoopTask.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final TaskMessage INIT_MESSAGE = TaskMessage.from("", CODEC.encode("MESSAGE::INIT"));
+  private transient boolean isRunning = true;
+  private transient Optional<TaskMessage> message = Optional.empty();
+
+  @Inject
+  public NoopTask() {
+    LOG.info("NoopTask created.");
+  }
+
+  @Override
+  public synchronized byte[] call(final byte[] memento) {
+    this.isRunning = true;
+    while (this.isRunning) {
+      try {
+        LOG.info("NoopTask.call(): Waiting for the message.");
+        this.wait();
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.WARNING, "NoopTask.wait() interrupted.", ex);
+      }
+    }
+    LOG.log(Level.INFO, "NoopTask.call(): Exiting with message {0}",
+        CODEC.decode(this.message.orElse(INIT_MESSAGE).get()));
+    return this.message.orElse(INIT_MESSAGE).get();
+  }
+
+  @Override
+  public synchronized Optional<TaskMessage> getMessage() {
+    LOG.log(Level.INFO, "NoopTask.getMessage() invoked: {0}",
+        CODEC.decode(this.message.orElse(INIT_MESSAGE).get()));
+    return this.message;
+  }
+
+  private synchronized void stopTask() {
+    LOG.info("NoopTask.stopTask() invoked.");
+    this.isRunning = false;
+    this.notify();
+  }
+
+  public class TaskSuspendHandler implements EventHandler<SuspendEvent> {
+    @Override
+    public void onNext(final SuspendEvent suspendEvent) {
+      LOG.info("NoopTask.TaskSuspendHandler.send() invoked.");
+      NoopTask.this.stopTask();
+    }
+  }
+
+  public class TaskStopHandler implements EventHandler<TaskStop> {
+    @Override
+    public void onNext(final TaskStop event) {
+      LOG.info("NoopTask.TaskStopHandler.send() invoked.");
+      NoopTask.this.stopTask();
+    }
+  }
+
+  public class TaskCloseHandler implements EventHandler<CloseEvent> {
+    @Override
+    public void onNext(final CloseEvent closeEvent) {
+      LOG.info("NoopTask.TaskCloseHandler.send() invoked.");
+      NoopTask.this.stopTask();
+    }
+  }
+
+  public class DriverMessageHandler implements EventHandler<DriverMessage> {
+    @Override
+    public void onNext(DriverMessage driverMessage) {
+      final byte[] msg = driverMessage.get().get();
+      LOG.log(Level.INFO, "NoopTask.DriverMessageHandler.send() invoked: {0}", CODEC.decode(msg));
+      synchronized (NoopTask.this) {
+        NoopTask.this.message = Optional.of(TaskMessage.from(NoopTask.this.toString(), msg));
+      }
+    }
+  }
+}