@Test public void testPar2AndThenDsc() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2)).andThen("test", (a, b) -> value.set(a + b)); runAndWait("TestTaskFactoryMethods.testPar2AndThenDsc", task); assertEquals(value.get(), 1 + 2); assertEquals(countTasks(task.getTrace()), 2 + 1 + 2); }
@Test public void testPar3AndThenDsc() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3)).andThen("test", (a, b, c) -> value.set(a + b + c)); runAndWait("TestTaskFactoryMethods.testPar3AndThenDsc", task); assertEquals(value.get(), 1 + 2 + 3); assertEquals(countTasks(task.getTrace()), 2 + 1 + 3); }
@Test public void testPar4AndThenDsc() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3), Task.value(4)).andThen("test", (a, b, c, d) -> value.set(a + b + c + d)); runAndWait("TestTaskFactoryMethods.testPar4AndThenDsc", task); assertEquals(value.get(), 1 + 2 + 3 + 4); assertEquals(countTasks(task.getTrace()), 2 + 1 + 4); }
@Test public void testPar2Dsc() { Task<Integer> task = Task.par(Task.value(1), Task.value(2)).map("test", (a, b) -> a + b); runAndWait("TestTaskFactoryMethods.testPar2Dsc", task); assertEquals((int)task.get(), 1 + 2); assertEquals(countTasks(task.getTrace()), 2 + 1 + 2); }
@Test public void testDuplicateGetRequestIsNotBatched() { Task<?> task = Task.par(greetingGet(1L), greetingGet(1L)); runAndWait(getTestClassName() + ".testDuplicateGetRequestIsNotBatched", task); assertFalse(hasTask("greetings batch_get(reqs: 1, ids: 1)", task.getTrace())); }
@Test public void testLongRunningBatchTaskFailure() { Task<String> batchTask = _strategy.batchable(1); Task<String> failingTask = delayedFailure(new UnsupportedOperationException("not supported!"), 5, TimeUnit.MILLISECONDS); Task<String> finalTask = Task.par(batchTask, failingTask).map("concat", (s, t) -> s + t).recover("recover", throwable -> "hello"); runAndWaitForPlanToComplete("TestTaskSimpleBatchingStrategyBlocking.testLongRunningBatchTaskFailure", finalTask, 5, TimeUnit.SECONDS); verifyBatchFinished(finalTask); }
@Test public void testPar7AndThenDsc() { 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)) .andThen("test", (a, b, c, d, e, f, g) -> value.set(a + b + c + d + e + f + g)); runAndWait("TestTaskFactoryMethods.testPar7AndThenDsc", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7); assertEquals(countTasks(task.getTrace()), 2 + 1 + 7); }
@Test public void testShareable() { Task<String> task = Task.par(_strategy.batchable(0).shareable(), _strategy.batchable(1).shareable()) .map("concat", (s0, s1) -> s0 + s1); String result = runAndWait("TestSimpleBatchingStrategy.testShareable", task); assertEquals(result, "01"); }
@Test public void testPar3Dsc() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3)).map("test", (a, b, c) -> a + b + c); runAndWait("TestTaskFactoryMethods.testPar3Dsc", task); assertEquals((int)task.get(), 1 + 2 + 3); assertEquals(countTasks(task.getTrace()), 2 + 1 + 3); }
@Test public void testPar9AndThen() { 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)) .andThen((a, b, c, d, e, f, g, h, i) -> value.set(a + b + c + d + e + f + g + h + i)); runAndWait("TestTaskFactoryMethods.testPar9AndThen", task); assertEquals(value.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); assertEquals(countTasks(task.getTrace()), 2 + 1 + 9); }
@Test public void testPar3FlatMap() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3)).flatMap((a, b, c) -> Task.value(a + b + c)); runAndWait("TestTaskFactoryMethods.testPar3FlatMap", task); assertEquals((int)task.get(), 1 + 2 + 3); assertEquals(countTasks(task.getTrace()), 2 + 3 + 3); }
@Test public void testPar3FlatMapDsc() { Task<Integer> task = Task.par(Task.value(1), Task.value(2), Task.value(3)).flatMap("test", (a, b, c) -> Task.value(a + b + c)); runAndWait("TestTaskFactoryMethods.testPar3FlatMapDsc", task); assertEquals((int)task.get(), 1 + 2 + 3); assertEquals(countTasks(task.getTrace()), 2 + 3 + 3); }
@Test public void testGetRequestsWithErrorOverrides() { Task<String> task = Task.par(toMessage(greetingGet(1L, overrides())), toMessage(greetingGet(-1L, overrides())).recover(e -> "failed")) .map("combine", (x, y) -> x + y); runAndWait(getTestClassName() + ".testGetRequestsWithErrorOverrides", task); assertEquals(task.get(), "Good morning!failed"); if (expectBatchingOverrides()) { assertTrue(hasTask("greetings batch_get(reqs: 2, ids: 2)", task.getTrace())); } else { assertFalse(hasTask("greetings batch_get(reqs: 2, ids: 2)", task.getTrace())); } }
@Test public void testPar9Dsc() { 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)) .map("test", (a, b, c, d, e, f, g, h, i) -> a + b + c + d + e + f + g + h + i); runAndWait("TestTaskFactoryMethods.testPar9Dsc", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); assertEquals(countTasks(task.getTrace()), 2 + 1 + 9); }
@Test public void testPar11Dsc() { 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)) .map("test", (a, b, c, d, e, f, g, h, i, j, k) -> a + b + c + d + e + f + g + h + i + j + k); runAndWait("TestTaskFactoryMethods.testPar11Dsc", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11); assertEquals(countTasks(task.getTrace()), 2 + 1 + 11); }
@Test public void testPar13FlatMap() { 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), Task.value(12), Task.value(13)) .flatMap((a, b, c, d, e, f, g, h, i, j, k, l, m) -> Task.value(a + b + c + d + e + f + g + h + i + j + k + l + m)); runAndWait("TestTaskFactoryMethods.testPar13FlatMap", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13); assertEquals(countTasks(task.getTrace()), 2 + 3 + 13); }
@Test public void testGetRequestsWithDifferentCustomQueryParamValuesNoBatching() { Task<?> t1 = _parseqClient.createTask(new GreetingsBuilders().get().id(1L) .addParam("K1", "V1").build()); Task<?> t2 = _parseqClient.createTask(new GreetingsBuilders().get().id(2L) .addParam("K1", "V2").build()); Task<?> task = Task.par(t1, t2); runAndWait(getTestClassName() + ".testGetRequestsWithDifferentCustomQueryParamValuesNoBatching", task); assertFalse(hasTask("greetings batch_get(reqs: 2, ids: 2)", task.getTrace())); }
@Test public void testPar14FlatMapDsc() { 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), Task.value(12), Task.value(13), Task.value(14)) .flatMap("test", (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Task.value(a + b + c + d + e + f + g + h + i + j + k + l + m + n)); runAndWait("TestTaskFactoryMethods.testPar14FlatMapDsc", task); assertEquals((int)task.get(), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14); assertEquals(countTasks(task.getTrace()), 2 + 3 + 14); }
@Test public void testGetRequestsWithDifferentCustomQueryParamValuesNoBatchingOverrides() { Task<?> t1 = _parseqClient.createTask(new GreetingsBuilders().get().id(1L) .addParam("K1", "V1").build(), overrides()); Task<?> t2 = _parseqClient.createTask(new GreetingsBuilders().get().id(2L) .addParam("K1", "V2").build(), overrides()); Task<?> task = Task.par(t1, t2); runAndWait(getTestClassName() + ".testGetRequestsWithDifferentCustomQueryParamValuesNoBatchingOverrides", task); assertFalse(hasTask("greetings batch_get(reqs: 2, ids: 2)", task.getTrace())); }
@Test public void testGetRequestsWithDifferentCustomHeaderValuesNoBatchingOverrides() { Task<?> t1 = _parseqClient.createTask(new GreetingsBuilders().get().id(1L) .addHeader("H1", "V1").build(), overrides()); Task<?> t2 = _parseqClient.createTask(new GreetingsBuilders().get().id(2L) .addHeader("H1", "V2").build(), overrides()); Task<?> task = Task.par(t1, t2); runAndWait(getTestClassName() + ".testGetRequestsWithDifferentCustomHeaderValuesNoBatchingOverrides", task); assertFalse(hasTask("greetings batch_get(reqs: 2, ids: 2)", task.getTrace())); }