/** * Equivalent to {@code value("value", value)}. * @see #value(String, Object) */ public static <T> Task<T> value(final T value) { return value("value", value); }
@Test public void testPar13AndThen() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8), Task.value(9), Task.value(10), Task.value(11), Task.value(12), Task.value(13)) .andThen((a, b, c, d, e, f, g, h, i, j, k, l, m) -> value.set(a + b + c + d + e + f + g + h + i + j + k + l + m)); runAndWait("TestTaskFactoryMethods.testPar13AndThen", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13); assertEquals(countTasks(task.getTrace()), 2 + 1 + 13); }
@Test public void testPar12AndThen() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8), Task.value(9), Task.value(10), Task.value(11), Task.value(12)) .andThen((a, b, c, d, e, f, g, h, i, j, k, l) -> value.set(a + b + c + d + e + f + g + h + i + j + k + l)); runAndWait("TestTaskFactoryMethods.testPar12AndThen", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12); assertEquals(countTasks(task.getTrace()), 2 + 1 + 12); }
@Test public void testPar11FlatMapDsc() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8), Task.value(9), Task.value(10), Task.value(11)) .flatMap("test", (a, b, c, d, e, f, g, h, i, j, k) -> Task.value(a + b + c + d + e + f + g + h + i + j + k)); runAndWait("TestTaskFactoryMethods.testPar11FlatMapDsc", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11); assertEquals(countTasks(task.getTrace()), 2 + 3 + 11); }
@Test public void testPar11AndThenDsc() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8), Task.value(9), Task.value(10), Task.value(11)) .andThen("test", (a, b, c, d, e, f, g, h, i, j, k) -> value.set(a + b + c + d + e + f + g + h + i + j + k)); runAndWait("TestTaskFactoryMethods.testPar11AndThenDsc", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11); assertEquals(countTasks(task.getTrace()), 2 + 1 + 11); }
@Test public void testPar10AndThen() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8), Task.value(9), Task.value(10)) .andThen((a, b, c, d, e, f, g, h, i, j) -> value.set(a + b + c + d + e + f + g + h + i + j)); runAndWait("TestTaskFactoryMethods.testPar10AndThen", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10); assertEquals(countTasks(task.getTrace()), 2 + 1 + 10); }
@Test public void testPar8FlatMap() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8)) .flatMap((a, b, c, d, e, f, g, h) -> Task.value(a + b + c + d + e + f + g + h)); runAndWait("TestTaskFactoryMethods.testPar8FlatMap", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); assertEquals(countTasks(task.getTrace()), 2 + 3 + 8); }
@Test public void testPar8AndThen() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7), Task.value(8)) .andThen((a, b, c, d, e, f, g, h) -> value.set(a + b + c + d + e + f + g + h)); runAndWait("TestTaskFactoryMethods.testPar8AndThen", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); assertEquals(countTasks(task.getTrace()), 2 + 1 + 8); }
@Test public void testPar7Dsc() { Task<Integer> task = Task .par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6), Task.value(7)) .map("test", (a, b, c, d, e, f, g) -> a + b + c + d + e + f + g); runAndWait("TestTaskFactoryMethods.testPar7Dsc", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7); assertEquals(countTasks(task.getTrace()), 2 + 1 + 7); }
@Test public void testPar6AndThenDsc() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6)) .andThen("test", (a, b, c, d, e, f) -> value.set(a + b + c + d + e + f)); runAndWait("TestTaskFactoryMethods.testPar6AndThenDsc", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6); assertEquals(countTasks(task.getTrace()), 2 + 1 + 6); }
@Test public void testPar6Dsc() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4), Task.value(5), Task.value(6)) .map("test", (a, b, c, d, e, f) -> a + b + c + d + e + f); runAndWait("TestTaskFactoryMethods.testPar6Dsc", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6); assertEquals(countTasks(task.getTrace()), 2 + 1 + 6); }
@Test public void testPar4() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4)) .map((a, b, c, d) -> a + b + c + d); runAndWait("TestTaskFactoryMethods.testPar4", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4); assertEquals(countTasks(task.getTrace()), 2 + 1 + 4); }
@Test public void testPar2AndThen() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2)).andThen((a, b) -> value.set(a + b)); runAndWait("TestTaskFactoryMethods.testPar2AndThen", task); assertEquals(value.get(), 1 + 2); assertEquals(countTasks(task.getTrace()), 2 + 1 + 2); }
@Test public void testSingle() { Task<String> task = Task.par(Task.value("0"), _strategy.batchable(1)) .map("concat", (s0, s1) -> s0 + s1); String result = runAndWait("TestTaskSimpleBatchingStrategy.testSingle", task); assertEquals(result, "01"); }
@Test public void testShutdownThenRunTask() throws InterruptedException { _engine.shutdown(); final Task<String> task = Task.value("task executed"); _engine.run(task); // Task should be cancelled immediately assertTrue(task.await(50, TimeUnit.MILLISECONDS)); assertTrue(task.isFailed()); }