Repository: reef Updated Branches: refs/heads/master 86654acd4 -> a1f622519
http://git-wip-us.apache.org/repos/asf/reef/blob/a1f62251/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/RunningWorkersTest.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/RunningWorkersTest.java b/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/RunningWorkersTest.java index 2828ccb..110143f 100644 --- a/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/RunningWorkersTest.java +++ b/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/RunningWorkersTest.java @@ -20,6 +20,7 @@ package org.apache.reef.vortex.driver; import org.apache.reef.tang.Tang; import org.apache.reef.tang.exceptions.InjectionException; +import org.apache.reef.vortex.common.AggregateFunctionRepository; import org.junit.Test; import java.util.ArrayList; http://git-wip-us.apache.org/repos/asf/reef/blob/a1f62251/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/TestUtil.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/TestUtil.java b/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/TestUtil.java index 1b9abac..2b7cf54 100644 --- a/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/TestUtil.java +++ b/lang/java/reef-applications/reef-vortex/src/test/java/org/apache/reef/vortex/driver/TestUtil.java @@ -76,13 +76,14 @@ public final class TestUtil { public Object answer(final InvocationOnMock invocation) throws Throwable { final VortexRequest request = (VortexRequest)invocation.getArguments()[1]; if (request instanceof TaskletCancellationRequest) { - final TaskletReport cancelReport = new TaskletCancelledReport(request.getTaskletId()); + final TaskletReport cancelReport = new TaskletCancelledReport( + ((TaskletCancellationRequest)request).getTaskletId()); master.workerReported(workerManager.getId(), new WorkerReport(Collections.singleton(cancelReport))); } return null; } - }).when(vortexRequestor).send(any(RunningTask.class), any(VortexRequest.class)); + }).when(vortexRequestor).sendAsync(any(RunningTask.class), any(VortexRequest.class)); return workerManager; } http://git-wip-us.apache.org/repos/asf/reef/blob/a1f62251/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/addone/AddOneTest.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/addone/AddOneTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/addone/AddOneTest.java index 69b04c6..4dfa9e7 100644 --- a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/addone/AddOneTest.java +++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/addone/AddOneTest.java @@ -85,7 +85,7 @@ public final class AddOneTest { .set(VortexMasterConf.WORKER_MEM, 64) .set(VortexMasterConf.WORKER_CORES, 4) .set(VortexMasterConf.WORKER_CAPACITY, 2000) - .set(VortexMasterConf.VORTEX_START, AddOneCallbackTestStart.class) + .set(VortexMasterConf.VORTEX_START, AddOneTestStart.class) .build(); final VortexJobConf vortexJobConf = VortexJobConf.newBuilder() http://git-wip-us.apache.org/repos/asf/reef/blob/a1f62251/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTest.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTest.java new file mode 100644 index 0000000..7a2f229 --- /dev/null +++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTest.java @@ -0,0 +1,76 @@ +/* + * 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.applications.vortex.sumones; + +import org.apache.reef.client.LauncherStatus; +import org.apache.reef.tang.Configuration; +import org.apache.reef.tests.TestEnvironment; +import org.apache.reef.tests.TestEnvironmentFactory; +import org.apache.reef.vortex.driver.VortexJobConf; +import org.apache.reef.vortex.driver.VortexMasterConf; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Launch the SumOnes Vortex test. + */ +public final class SumOnesTest { + private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment(); + + /** + * Set up the test environment. + */ + @Before + public void setUp() throws Exception { + this.testEnvironment.setUp(); + } + + /** + * Tear down the test environment. + */ + @After + public void tearDown() throws Exception { + this.testEnvironment.tearDown(); + } + + /** + * Run the SumOnes test. + */ + @Test + public void testVortexSumOnes() { + + final Configuration vortexMasterConf = VortexMasterConf.CONF + .set(VortexMasterConf.WORKER_NUM, 2) + .set(VortexMasterConf.WORKER_MEM, 64) + .set(VortexMasterConf.WORKER_CORES, 4) + .set(VortexMasterConf.WORKER_CAPACITY, 2000) + .set(VortexMasterConf.VORTEX_START, SumOnesTestStart.class) + .build(); + + final VortexJobConf vortexJobConf = VortexJobConf.newBuilder() + .setJobName("TEST_Vortex_SumOnesTest") + .setVortexMasterConf(vortexMasterConf) + .build(); + + final LauncherStatus status = this.testEnvironment.run(vortexJobConf.getConfiguration()); + Assert.assertTrue("Job state after execution: " + status, status.isSuccess()); + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/a1f62251/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTestStart.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTestStart.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTestStart.java new file mode 100644 index 0000000..c742d3e --- /dev/null +++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/SumOnesTestStart.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.tests.applications.vortex.sumones; + +import org.apache.reef.vortex.api.*; +import org.apache.reef.vortex.examples.sumones.AdditionAggregateFunction; +import org.apache.reef.vortex.examples.sumones.IdentityFunction; + +import javax.inject.Inject; +import java.util.Vector; + +/** + * Test correctness of an aggregation function that adds integer outputs (ones) on Vortex. + */ +public final class SumOnesTestStart implements VortexStart { + @Inject + private SumOnesTestStart() { + } + + /** + * Test correctness of an aggregation function that adds integer outputs (ones) on Vortex. + */ + @Override + public void start(final VortexThreadPool vortexThreadPool) { + final int numberOfOnesToSum = 1000; + final Vector<Integer> inputVector = new Vector<>(); + for (int i = 0; i < numberOfOnesToSum; i++) { + inputVector.add(1); + } + + final VortexAggregateFuture<Integer, Integer> future = + vortexThreadPool.submit(new AdditionAggregateFunction(), new IdentityFunction(), inputVector); + + try { + AggregateResultSynchronous<Integer, Integer> result; + int allSum = 0; + + result = future.get(); + allSum += getAggregateResult(result); + + while (result.hasNext()) { + result = future.get(); + + final int sumResult = getAggregateResult(result); + + int sumInputs = 0; + for (int i : result.getAggregatedInputs()) { + sumInputs += 1; + } + + assert sumResult == sumInputs; + allSum += sumResult; + } + + assert allSum == numberOfOnesToSum; + + } catch (final InterruptedException ie) { + throw new RuntimeException(ie); + } + } + + private static int getAggregateResult(final AggregateResultSynchronous<Integer, Integer> result) { + try { + return result.getAggregateResult(); + } catch (final VortexAggregateException e) { + throw new RuntimeException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/a1f62251/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/package-info.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/package-info.java new file mode 100644 index 0000000..e2f18de --- /dev/null +++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/applications/vortex/sumones/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. + */ +/** + * Vortex SumOnes Aggregation test. + */ +package org.apache.reef.tests.applications.vortex.sumones;
