private Task<?> fetchAndLog(final String url) { final Task<String> fetch = fetchUrl(_httpClient, url); final Task<?> logResult = logResult(url, fetch); return seq(fetch, logResult); }
private Task<?> truthMapQueryClassifyTask(final String name, final int remainder, final Classification classification) { final Task<Map<Long, Boolean>> svcCall = clientRequestTask(new TruthMapRequest("get" + name, remainder, _unclassified)); final Task<?> classifyResult = truthMapClassifyTask(name, classification, svcCall); return seq(svcCall, classifyResult); }
@SuppressWarnings("deprecation") @Test public void testIterableSeqWithEmptyList() { try { seq(Collections.<Task<?>> emptyList()); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { // Expected case } }
@SuppressWarnings("deprecation") @Test public void testIterableSeqWithSingletonList() throws InterruptedException { final String valueStr = "value"; final Task<String> task = value("value", valueStr); final Task<List<String>> seq = seq(Collections.singleton(task)); runAndWait("TestSeqTask.testIterableSeqWithSingletonList", seq); assertEquals(valueStr, seq.get()); }
@Override protected void doRunExample(final Engine engine) throws Exception { final MockService<String> httpClient = getService(); final Task<String> fetch = fetch404Url(httpClient, "http://www.google.com"); final Task<Integer> length = callable("length", new Callable<Integer>() { @Override public Integer call() { return fetch.getOrDefault("").length(); } }); final Task<Integer> fetchAndLength = seq(fetch, length); engine.run(fetchAndLength); fetchAndLength.await(); System.out.println("Response length: " + fetchAndLength.get()); ExampleUtil.printTracingResults(fetchAndLength); } }
@Override protected void doRunExample(final Engine engine) throws Exception { final MockService<String> httpClient = getService(); final FanoutTask fanout = new FanoutTask(httpClient); final Task<?> printResults = action("printResults", new Runnable() { @Override public void run() { System.out.println(fanout.get()); } }); final Task<?> plan = seq(fanout, printResults); engine.run(plan); plan.await(); printTracingResults(plan); }
@Override public Promise<String> run(final Context ctx) { final Task<String> twoStage = seq(par(fetchAndLog("http://www.bing.com"), fetchAndLog("http://www.yahoo.com")), par(fetchAndLog("http://www.google.com"), fetchAndLog("https://duckduckgo.com/")), buildResult()); ctx.run(twoStage); return twoStage; }
@SuppressWarnings("deprecation") @Test public void testSeq2() throws InterruptedException { final Task<String> seq = seq(value(1), value("result")); runAndWait("TestSeqTask.testSeq2", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testCompositeTaskWithRootLoggerTrace() throws InterruptedException { final Task<?> child1 = Task.value("t1", "value"); final Task<?> child2 = TestUtil.noop(); final Task<?> parent = Tasks.seq(child1, child2); setLogLevel(ROOT_LOGGER, ListLogger.LEVEL_TRACE); runAndWait("TestTaskLogging.testCompositeTaskWithRootLoggerTrace", parent); assertTaskLogged(parent, "null", ROOT_LOGGER, ListLogger.LEVEL_TRACE); final List<ListLogger.Entry> entries = getLogEntries(ROOT_LOGGER); assertEquals("Should only log start and stop for the root trace: " + entries, 2, entries.size()); }
@SuppressWarnings("deprecation") @Test public void testSeq3() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value("result")); runAndWait("TestSeqTask.testSeq3", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testSeq4() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value("result")); runAndWait("TestSeqTask.testSeq4", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testTraceWithSuccessChild() throws InterruptedException { final Task<String> task = value("taskName", "value"); final Task<?> seq = Tasks.seq(Arrays.asList(task)); runAndWait("TestTaskToTrace.testTraceWithSuccessChild", seq); verifyShallowTrace(task); verifyShallowTrace(seq); assertEquals(1, getRelationships(seq.getTrace(), seq.getId()).size()); assertTrue(seq.getTrace().getRelationships() .contains(new TraceRelationship(seq.getShallowTraceBuilder(), task.getShallowTraceBuilder(), Relationship.PARENT_OF))); }
@SuppressWarnings("deprecation") @Test public void testSeq5() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value(4), value("result")); runAndWait("TestSeqTask.testSeq5", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testCompositeTaskWithAllLoggerTrace() throws InterruptedException { final Task<?> child1 = Task.value("t1", "value"); child1.setTraceValueSerializer(Object::toString); final Task<?> child2 = TestUtil.noop(); final Task<?> parent = Tasks.seq(child1, child2); setLogLevel(ALL_LOGGER, ListLogger.LEVEL_TRACE); runAndWait("TestTaskLogging.testCompositeTaskWithAllLoggerTrace", parent); assertTaskLogged(parent, "null", ALL_LOGGER, ListLogger.LEVEL_TRACE); assertTaskLogged(child1, "value", ALL_LOGGER, ListLogger.LEVEL_TRACE); assertTaskLogged(child2, "null", ALL_LOGGER, ListLogger.LEVEL_TRACE); }
@SuppressWarnings("deprecation") @Test public void testSeq6() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value(4), value(5), value("result")); runAndWait("TestSeqTask.testSeq6", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testCompositeTaskWithPlanClassLoggerTrace() throws InterruptedException { final Task<?> child1 = Task.value("t1", "value"); child1.setTraceValueSerializer(Object::toString); final Task<?> child2 = TestUtil.noop(); final Task<?> parent = Tasks.seq(child1, child2); final String planClassLogger = planClassLogger(parent); setLogLevel(planClassLogger, ListLogger.LEVEL_TRACE); runAndWait("TestTaskLogging.testCompositeTaskWithPlanClassLoggerTrace", parent); assertTaskLogged(parent, "null", planClassLogger, ListLogger.LEVEL_TRACE); assertTaskLogged(child1, "value", planClassLogger, ListLogger.LEVEL_TRACE); assertTaskLogged(child2, "null", planClassLogger, ListLogger.LEVEL_TRACE); }
@SuppressWarnings("deprecation") @Test public void testSeq7() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value(4), value(5), value(6), value("result")); runAndWait("TestSeqTask.testSeq7", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testSeq8() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value(4), value(5), value(6), value(7), value("result")); runAndWait("TestSeqTask.testSeq8", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testSeq9() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value(4), value(5), value(6), value(7), value(8), value("result")); runAndWait("TestSeqTask.testSeq9", seq); assertEquals("result", seq.get()); }
@SuppressWarnings("deprecation") @Test public void testSeq10() throws InterruptedException { final Task<String> seq = seq(value(1), value(2), value(3), value(4), value(5), value(6), value(7), value(8), value(9), value("result")); runAndWait("TestSeqTask.testSeq10", seq); assertEquals("result", seq.get()); }