Repository: reef
Updated Branches:
  refs/heads/master 6f02cb7e6 -> 07874cbb6


http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/driver/parameters/package-info.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/driver/parameters/package-info.java
 
b/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/driver/parameters/package-info.java
new file mode 100644
index 0000000..94c1cb8
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/driver/parameters/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.
+ */
+/**
+ * Parameters for multi runtime driver.
+ */
+package org.apache.reef.runtime.multi.driver.parameters;

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializer.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializer.java
 
b/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializer.java
new file mode 100644
index 0000000..ba836c1
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializer.java
@@ -0,0 +1,73 @@
+/*
+ * 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.runtime.multi.utils;
+
+import org.apache.avro.io.*;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.apache.avro.specific.SpecificDatumWriter;
+import org.apache.reef.runtime.multi.utils.avro.MultiRuntimeDefinition;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Serializer for MultiRuntimeDefinition.
+ */
+public final class MultiRuntimeDefinitionSerializer {
+
+  private static final String CHARSET_NAME = "UTF-8";
+
+  /**
+   * Serializes MultiRuntimeDefinition.
+   * @param runtimeDefinition the Avro object to toString
+   * @return Serialized avro string
+   */
+  public String toString(final MultiRuntimeDefinition runtimeDefinition){
+    final DatumWriter<MultiRuntimeDefinition> configurationWriter =
+            new SpecificDatumWriter<>(MultiRuntimeDefinition.class);
+    final String serializedConfiguration;
+    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+      final JsonEncoder encoder = 
EncoderFactory.get().jsonEncoder(runtimeDefinition.getSchema(), out);
+      configurationWriter.write(runtimeDefinition, encoder);
+      encoder.flush();
+      out.flush();
+      serializedConfiguration = out.toString(CHARSET_NAME);
+    } catch (final IOException e) {
+      throw new RuntimeException(e);
+    }
+
+    return serializedConfiguration;
+  }
+
+  /**
+   * Deserializes avro definition.
+   * @param serializedRuntimeDefinition serialized definition
+   * @return Avro object
+   * @throws IOException
+   */
+  public MultiRuntimeDefinition fromString(final String 
serializedRuntimeDefinition) throws
+          IOException{
+    final JsonDecoder decoder = DecoderFactory.get().
+            jsonDecoder(MultiRuntimeDefinition.getClassSchema(), 
serializedRuntimeDefinition);
+    final SpecificDatumReader<MultiRuntimeDefinition> reader = new 
SpecificDatumReader<>(MultiRuntimeDefinition.class);
+    final MultiRuntimeDefinition rd = reader.read(null, decoder);
+    return rd;
+  }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/package-info.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/package-info.java
 
b/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/package-info.java
new file mode 100644
index 0000000..e921931
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/main/java/org/apache/reef/runtime/multi/utils/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.
+ */
+/**
+ * Utils for multi runtime.
+ */
+package org.apache.reef.runtime.multi.utils;

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/RuntimesHostTest.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/RuntimesHostTest.java
 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/RuntimesHostTest.java
new file mode 100644
index 0000000..5f855f1
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/RuntimesHostTest.java
@@ -0,0 +1,359 @@
+/*
+ * 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.runtime.multi.driver;
+
+import org.apache.reef.runtime.common.driver.api.*;
+import 
org.apache.reef.runtime.common.driver.resourcemanager.NodeDescriptorEvent;
+import 
org.apache.reef.runtime.common.driver.resourcemanager.ResourceAllocationEvent;
+import 
org.apache.reef.runtime.common.driver.resourcemanager.ResourceStatusEvent;
+import 
org.apache.reef.runtime.common.driver.resourcemanager.RuntimeStatusEvent;
+import org.apache.reef.runtime.local.driver.*;
+import org.apache.reef.runtime.multi.client.MultiRuntimeDefinitionBuilder;
+import 
org.apache.reef.runtime.multi.client.parameters.SerializedRuntimeDefinition;
+import org.apache.reef.runtime.multi.utils.MultiRuntimeDefinitionSerializer;
+import org.apache.reef.runtime.multi.utils.avro.MultiRuntimeDefinition;
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStart;
+import org.apache.reef.wake.time.runtime.event.RuntimeStop;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Tests for RuntimesHost.
+ */
+public class RuntimesHostTest {
+  private Injector injector;
+  private static Queue<Object> commandsQueue = new LinkedBlockingQueue<>();
+
+  @SuppressWarnings("unchecked")
+  @Before
+  public void setUp() throws InjectionException {
+    final JavaConfigurationBuilder cb = 
Tang.Factory.getTang().newConfigurationBuilder()
+            .bindNamedParameter(
+                    RuntimeParameters.NodeDescriptorHandler.class,
+                    RuntimesHostTest.TestNodeDescriptorHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceStatusHandler.class,
+                    RuntimesHostTest.TestResourceStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.RuntimeStatusHandler.class,
+                    RuntimesHostTest.TestRuntimeStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceAllocationHandler.class,
+                    RuntimesHostTest.TestResourceAllocationHandler.class);
+
+    this.injector = Tang.Factory.getTang().newInjector(cb.build());
+    RuntimesHostTest.commandsQueue.clear();
+  }
+
+  @Test(expected = InjectionException.class)
+  public void testRuntimesHostInitializedWithCorruptedRuntimesList() throws 
InjectionException {
+    final JavaConfigurationBuilder cb = 
Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindNamedParameter(
+            SerializedRuntimeDefinition.class,
+            "corrupted avro");
+
+    final Injector forked = injector.forkInjector(cb.build());
+    final RuntimesHost rHost = forked.getInstance(RuntimesHost.class);
+    rHost.onRuntimeStart(new RuntimeStart(System.currentTimeMillis()));
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void testRuntimesHostInitializedWithMissingNodeDescriptorHandler() 
throws InjectionException {
+    final Configuration configuration = LocalDriverConfiguration.CONF
+            .set(LocalDriverConfiguration.MAX_NUMBER_OF_EVALUATORS, 1)
+            .set(LocalDriverConfiguration.ROOT_FOLDER, "")
+            .set(LocalDriverConfiguration.JVM_HEAP_SLACK, 1024)
+            .set(LocalDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.JOB_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.RACK_NAMES, "").build();
+
+    final String config = getRuntimeDefinition(new 
MultiRuntimeDefinitionBuilder().addRuntime(configuration, "local")
+            .build());
+
+    final JavaConfigurationBuilder cb = 
Tang.Factory.getTang().newConfigurationBuilder()
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceStatusHandler.class,
+                    RuntimesHostTest.TestResourceStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.RuntimeStatusHandler.class,
+                    RuntimesHostTest.TestRuntimeStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceAllocationHandler.class,
+                    RuntimesHostTest
+                            .TestResourceAllocationHandler.class);
+    Injector badInjector = Tang.Factory.getTang().newInjector(cb.build());
+
+    final JavaConfigurationBuilder cbtest = 
Tang.Factory.getTang().newConfigurationBuilder();
+    cbtest.bindNamedParameter(
+            SerializedRuntimeDefinition.class,
+            config);
+
+    Injector forked = badInjector.forkInjector(cbtest.build());
+    final RuntimesHost rHost = forked.getInstance(RuntimesHost.class);
+    rHost.onRuntimeStart(new RuntimeStart(System.currentTimeMillis()));
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void testRuntimesHostInitializedWithMissingResourceStatusHandler() 
throws InjectionException {
+    final Configuration configuration = LocalDriverConfiguration.CONF
+            .set(LocalDriverConfiguration.MAX_NUMBER_OF_EVALUATORS, 1)
+            .set(LocalDriverConfiguration.ROOT_FOLDER, "")
+            .set(LocalDriverConfiguration.JVM_HEAP_SLACK, 1024)
+            .set(LocalDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.JOB_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.RACK_NAMES, "").build();
+
+
+    final String config = getRuntimeDefinition(new 
MultiRuntimeDefinitionBuilder().addRuntime(configuration, "local")
+            .build());
+    final JavaConfigurationBuilder cb = 
Tang.Factory.getTang().newConfigurationBuilder()
+            .bindNamedParameter(
+                    RuntimeParameters.NodeDescriptorHandler.class,
+                    RuntimesHostTest.TestNodeDescriptorHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.RuntimeStatusHandler.class,
+                    RuntimesHostTest.TestRuntimeStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceAllocationHandler.class,
+                    RuntimesHostTest.TestResourceAllocationHandler.class);
+
+    Injector badInjector = Tang.Factory.getTang().newInjector(cb.build());
+
+    final JavaConfigurationBuilder cbtest = 
Tang.Factory.getTang().newConfigurationBuilder();
+    cbtest.bindNamedParameter(
+            SerializedRuntimeDefinition.class,
+            config);
+
+    Injector forked = badInjector.forkInjector(cbtest.build());
+    final RuntimesHost rHost = forked.getInstance(RuntimesHost.class);
+    rHost.onRuntimeStart(new RuntimeStart(System.currentTimeMillis()));
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void testRuntimesHostInitializedWithMissingRuntimeStatusHandler() 
throws InjectionException {
+    final Configuration configuration = LocalDriverConfiguration.CONF
+            .set(LocalDriverConfiguration.MAX_NUMBER_OF_EVALUATORS, 1)
+            .set(LocalDriverConfiguration.ROOT_FOLDER, "")
+            .set(LocalDriverConfiguration.JVM_HEAP_SLACK, 1024)
+            .set(LocalDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.JOB_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.RACK_NAMES, "").build();
+
+    final String config = getRuntimeDefinition(new 
MultiRuntimeDefinitionBuilder().addRuntime(configuration, "local")
+            .build());
+    final JavaConfigurationBuilder cb = 
Tang.Factory.getTang().newConfigurationBuilder()
+            .bindNamedParameter(
+                    RuntimeParameters.NodeDescriptorHandler.class,
+                    RuntimesHostTest.TestNodeDescriptorHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.RuntimeStatusHandler.class,
+                    RuntimesHostTest.TestRuntimeStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceAllocationHandler.class,
+                    RuntimesHostTest.TestResourceAllocationHandler.class);
+
+    Injector badInjector = Tang.Factory.getTang().newInjector(cb.build());
+
+    final JavaConfigurationBuilder cbtest = 
Tang.Factory.getTang().newConfigurationBuilder();
+    cbtest.bindNamedParameter(
+            SerializedRuntimeDefinition.class,
+            config);
+
+    Injector forked = badInjector.forkInjector(cbtest.build());
+    final RuntimesHost rHost = forked.getInstance(RuntimesHost.class);
+    rHost.onRuntimeStart(new RuntimeStart(System.currentTimeMillis()));
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void 
testRuntimesHostInitializedWithMissingResourceAllocationHandler() throws 
InjectionException {
+    final Configuration configuration = LocalDriverConfiguration.CONF
+            .set(LocalDriverConfiguration.MAX_NUMBER_OF_EVALUATORS, 1)
+            .set(LocalDriverConfiguration.ROOT_FOLDER, "")
+            .set(LocalDriverConfiguration.JVM_HEAP_SLACK, 1024)
+            .set(LocalDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.JOB_IDENTIFIER, "ID")
+            .set(LocalDriverConfiguration.RACK_NAMES, "").build();
+
+
+    final String config = getRuntimeDefinition(new 
MultiRuntimeDefinitionBuilder().addRuntime(configuration, "local")
+            .build());
+    final JavaConfigurationBuilder cb = 
Tang.Factory.getTang().newConfigurationBuilder()
+            .bindNamedParameter(
+                    RuntimeParameters.NodeDescriptorHandler.class,
+                    RuntimesHostTest.TestNodeDescriptorHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.RuntimeStatusHandler.class,
+                    RuntimesHostTest.TestRuntimeStatusHandler.class)
+            .bindNamedParameter(
+                    RuntimeParameters.ResourceAllocationHandler.class,
+                    RuntimesHostTest.TestResourceAllocationHandler.class);
+
+    Injector badInjector = Tang.Factory.getTang().newInjector(cb.build());
+
+    final JavaConfigurationBuilder cbtest = 
Tang.Factory.getTang().newConfigurationBuilder();
+    cbtest.bindNamedParameter(
+            SerializedRuntimeDefinition.class,
+            config);
+
+    Injector forked = badInjector.forkInjector(cbtest.build());
+    final RuntimesHost rHost = forked.getInstance(RuntimesHost.class);
+    rHost.onRuntimeStart(new RuntimeStart(System.currentTimeMillis()));
+  }
+
+  @Test
+  public void testRuntimesHostRoutedToDefaultRuntime() throws 
InjectionException {
+    final String serializedConfiguration = getRuntimeDefinition(
+            new 
MultiRuntimeDefinitionBuilder().addRuntime(TestDriverConfiguration.CONF.build(),
 "test")
+            .build());
+
+    final JavaConfigurationBuilder cbtest = 
Tang.Factory.getTang().newConfigurationBuilder();
+    cbtest.bindNamedParameter(
+            SerializedRuntimeDefinition.class,
+            serializedConfiguration);
+
+    Injector forked = injector.forkInjector(cbtest.build());
+    final RuntimesHost rHost = forked.getInstance(RuntimesHost.class);
+    rHost.onRuntimeStart(new RuntimeStart(System.currentTimeMillis()));
+    Assert.assertEquals(1, RuntimesHostTest.commandsQueue.size());
+    Object obj = RuntimesHostTest.commandsQueue.poll();
+    Assert.assertTrue(obj instanceof RuntimeStart);
+  }
+
+  private String getRuntimeDefinition(final MultiRuntimeDefinition rd) {
+    return new MultiRuntimeDefinitionSerializer().toString(rd);
+  }
+
+  static class TestResourceStatusHandler implements 
EventHandler<ResourceStatusEvent> {
+    @Inject
+    TestResourceStatusHandler() {
+    }
+
+    @Override
+    public void onNext(final ResourceStatusEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  static class TestRuntimeStatusHandler implements 
EventHandler<RuntimeStatusEvent> {
+    @Inject
+    TestRuntimeStatusHandler() {
+    }
+
+    @Override
+    public void onNext(final RuntimeStatusEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  static class TestNodeDescriptorHandler implements 
EventHandler<NodeDescriptorEvent> {
+    @Inject
+    TestNodeDescriptorHandler() {
+    }
+
+    @Override
+    public void onNext(final NodeDescriptorEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  static class TestResourceAllocationHandler implements 
EventHandler<ResourceAllocationEvent> {
+    @Inject
+    TestResourceAllocationHandler() {
+    }
+
+    @Override
+    public void onNext(final ResourceAllocationEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  static class TestDriverConfiguration extends ConfigurationModuleBuilder {
+    public static final ConfigurationModule CONF = new 
TestDriverConfiguration()
+            .bindImplementation(ResourceLaunchHandler.class, 
TestResourceLaunchHandler.class)
+            .bindImplementation(ResourceRequestHandler.class, 
TestResourceRequestHandler.class)
+            .bindImplementation(ResourceReleaseHandler.class, 
TestResourceReleaseHandler.class)
+            .bindImplementation(ResourceManagerStartHandler.class, 
TestResourceManagerStartHandler.class)
+            .bindImplementation(ResourceManagerStopHandler.class, 
TestResourceManagerStopHandler.class).build();
+  }
+
+  private static class TestResourceLaunchHandler implements 
ResourceLaunchHandler {
+    @Inject
+    TestResourceLaunchHandler() {
+    }
+
+    @Override
+    public void onNext(final ResourceLaunchEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  private static class TestResourceRequestHandler implements 
ResourceRequestHandler {
+    @Inject
+    TestResourceRequestHandler() {
+    }
+
+    @Override
+    public void onNext(final ResourceRequestEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  private static class TestResourceReleaseHandler implements 
ResourceReleaseHandler {
+    @Inject
+    TestResourceReleaseHandler() {
+    }
+
+    @Override
+    public void onNext(final ResourceReleaseEvent value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  private static class TestResourceManagerStartHandler implements 
ResourceManagerStartHandler {
+    @Inject
+    TestResourceManagerStartHandler() {
+    }
+
+    @Override
+    public void onNext(final RuntimeStart value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+
+  private static class TestResourceManagerStopHandler implements 
ResourceManagerStopHandler {
+    @Inject
+    TestResourceManagerStopHandler() {
+    }
+
+    @Override
+    public void onNext(final RuntimeStop value) {
+      RuntimesHostTest.commandsQueue.add(value);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/package-info.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/package-info.java
 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/driver/package-info.java
new file mode 100644
index 0000000..f1eca9d
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/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 for runtime host.
+ */
+package org.apache.reef.runtime.multi.driver;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializerTests.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializerTests.java
 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializerTests.java
new file mode 100644
index 0000000..b596880
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/MultiRuntimeDefinitionSerializerTests.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.runtime.multi.utils;
+
+import org.apache.reef.runtime.multi.utils.avro.MultiRuntimeDefinition;
+import org.apache.reef.runtime.multi.utils.avro.RuntimeDefinition;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * Created by bshulman on 3/2/2016.
+ */
+public class MultiRuntimeDefinitionSerializerTests {
+  @Test
+  public void testSerailze() throws IOException {
+    final MultiRuntimeDefinitionSerializer serializer = new 
MultiRuntimeDefinitionSerializer();
+    final MultiRuntimeDefinition def = new MultiRuntimeDefinition();
+    final RuntimeDefinition rd = new RuntimeDefinition();
+    rd.setRuntimeName("default");
+    rd.setSerializedConfiguration("config");
+    def.setDefaultRuntimeName("default");
+    def.setRuntimes(Arrays.asList(new RuntimeDefinition[]{rd}));
+    final String serialized = serializer.toString(def);
+    final MultiRuntimeDefinition fromStringdef = 
serializer.fromString(serialized);
+    Assert.assertEquals(def, fromStringdef);
+  }
+
+  @Test(expected = IOException.class)
+  public void testDeseerailzeThrowsOnBadData() throws IOException {
+    final MultiRuntimeDefinitionSerializer serializer = new 
MultiRuntimeDefinitionSerializer();
+    serializer.fromString("bad data");
+  }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/package-info.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/package-info.java
 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/package-info.java
new file mode 100644
index 0000000..7a770ec
--- /dev/null
+++ 
b/lang/java/reef-runtime-multi/src/test/java/org/apache/reef/runtime/multi/utils/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 for multi-runtime utilsA local implementation of REEF that uses local 
JVMs for execution.
+ */
+package org.apache.reef.runtime.multi.utils;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/ExtensibleYarnClientConfiguration.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/ExtensibleYarnClientConfiguration.java
 
b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/ExtensibleYarnClientConfiguration.java
index 516c600..f123c6e 100644
--- 
a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/ExtensibleYarnClientConfiguration.java
+++ 
b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/ExtensibleYarnClientConfiguration.java
@@ -56,18 +56,16 @@ public final class ExtensibleYarnClientConfiguration 
extends ConfigurationModule
   public static final RequiredImpl<DriverConfigurationProvider> 
DRIVER_CONFIGURATION_PROVIDER = new RequiredImpl<>();
 
   public static final ConfigurationModule CONF = new 
ExtensibleYarnClientConfiguration()
-      .merge(CommonRuntimeConfiguration.CONF)
-          // Bind YARN
-      .bindImplementation(JobSubmissionHandler.class, 
YarnJobSubmissionHandler.class)
-      .bindImplementation(DriverConfigurationProvider.class, 
DRIVER_CONFIGURATION_PROVIDER)
-          // Bind the parameters given by the user
-      .bindNamedParameter(JobQueue.class, YARN_QUEUE_NAME)
-      .bindNamedParameter(JobPriority.class, YARN_PRIORITY)
-      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
-      .bindImplementation(RuntimeClasspathProvider.class, 
YarnClasspathProvider.class)
-          // Bind external constructors. Taken from  
YarnExternalConstructors.registerClientConstructors
-      .bindConstructor(org.apache.hadoop.yarn.conf.YarnConfiguration.class, 
YarnConfigurationConstructor.class)
-      .bindSetEntry(DriverConfigurationProviders.class, 
DRIVER_CONFIGURATION_PROVIDERS)
-      .build();
-
+            .merge(CommonRuntimeConfiguration.CONF)
+            // Bind YARN
+            .bindImplementation(JobSubmissionHandler.class, 
YarnJobSubmissionHandler.class)
+            .bindImplementation(DriverConfigurationProvider.class, 
DRIVER_CONFIGURATION_PROVIDER)
+            // Bind the parameters given by the user
+            .bindNamedParameter(JobQueue.class, YARN_QUEUE_NAME)
+            .bindNamedParameter(JobPriority.class, YARN_PRIORITY)
+            .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+            .bindImplementation(RuntimeClasspathProvider.class, 
YarnClasspathProvider.class)
+            // Bind external constructors. Taken from  
YarnExternalConstructors.registerClientConstructors
+            
.bindConstructor(org.apache.hadoop.yarn.conf.YarnConfiguration.class, 
YarnConfigurationConstructor.class)
+            .bindSetEntry(DriverConfigurationProviders.class, 
DRIVER_CONFIGURATION_PROVIDERS).build();
 }

http://git-wip-us.apache.org/repos/asf/reef/blob/07874cbb/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEFMultiRuntime.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEFMultiRuntime.java
 
b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEFMultiRuntime.java
new file mode 100644
index 0000000..ca7491d
--- /dev/null
+++ 
b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEFMultiRuntime.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.examples;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.examples.hellomultiruntime.HelloMultiRuntimeDriver;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.YarnTestEnvironment;
+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 successfully.
+ */
+public class TestHelloREEFMultiRuntime {
+  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 testHelloREEFMultiRuntime() {
+    if(this.testEnvironment instanceof YarnTestEnvironment){
+      // multi runtime can be tested on yarn only
+      final Configuration driverConf = DriverConfiguration.CONF
+              .set(DriverConfiguration.GLOBAL_LIBRARIES, 
EnvironmentUtils.getClassLocation(this.getClass()))
+              .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_HelloREEF")
+              .set(DriverConfiguration.ON_DRIVER_STARTED, 
HelloMultiRuntimeDriver.StartHandler.class)
+              .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, 
HelloMultiRuntimeDriver.EvaluatorAllocatedHandler.class)
+              .build();
+      final LauncherStatus state = this.testEnvironment.run(driverConf);
+      Assert.assertTrue("Job state after execution: " + state, 
state.isSuccess());
+    }
+  }
+
+}

Reply via email to