本文整理了Java中com.linkedin.parseq.Task.par()
方法的一些代码示例,展示了Task.par()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.par()
方法的具体详情如下:
包路径:com.linkedin.parseq.Task
类名称:Task
方法名:par
[英]Creates a new task that will run given tasks in parallel. Returned task will be resolved with results of all tasks as soon as all of them has been completed successfully.
// this task will asynchronously fetch user and company in parallel
// and create signature in a form
" working for "Task
signature =
Task.par(fetchUser(userId), fetchCompany(companyId))
.map((user, company)
->user.getFirstName() + user.getLastName() + " working for " + company.getName());
If any of tasks passed in as a parameter fails then returned task will also fail immediately. In this case returned task will be resolved with error from the first of failing tasks and other tasks will be cancelled if they have not been completed yet. Tasks will be started in an arbitrary order.
[中]创建将并行运行给定任务的新任务。一旦所有任务都成功完成,返回的任务将与所有任务的结果一起解决
// this task will asynchronously fetch user and company in parallel
// and create signature in a form
" working for "Task
signature =
Task.par(fetchUser(userId), fetchCompany(companyId))
.map((user, company)
->user.getFirstName() + user.getLastName() + " working for " + company.getName());
如果作为参数传入的任何任务失败,则返回的任务也将立即失败。在这种情况下,返回的任务将与第一个失败任务中的错误一起解决,如果尚未完成,则其他任务将被取消。任务将以任意顺序启动。
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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()));
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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");
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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()));
}
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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()));
}
代码示例来源:origin: linkedin/parseq
@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);
}
代码示例来源:origin: linkedin/parseq
@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()));
}
代码示例来源:origin: linkedin/parseq
@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()));
}
内容来源于网络,如有侵权,请联系作者删除!