本文整理了Java中com.linkedin.parseq.Task.toTry()
方法的一些代码示例,展示了Task.toTry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.toTry()
方法的具体详情如下:
包路径:com.linkedin.parseq.Task
类名称:Task
方法名:toTry
[英]Equivalent to toTry("toTry").
[中]相当于toTry(“toTry”)。
代码示例来源:origin: linkedin/parseq
/**
* Equivalent to {@code toTry("toTry")}.
* @see #toTry(String)
*/
default Task<Try<T>> toTry() {
return toTry("toTry");
}
代码示例来源:origin: linkedin/parseq
@Test
public void testHappyPath() throws InterruptedException {
final Task<Try<String>> task = Task.callable("test", () -> "hello").toTry();
runAndWait("TestWithTry.testHappyPath", task);
assertFalse(task.get().isFailed());
assertEquals("hello", task.get().get());
}
代码示例来源:origin: linkedin/parseq
@Test
public void testToTryCancelled() throws InterruptedException {
Task<String> cancelMain = delayedValue("value", 6000, TimeUnit.MILLISECONDS);
Task<Try<String>> task = cancelMain.toTry();
run(task);
assertTrue(cancelMain.cancel(new Exception("canceled")));
task.await();
assertTrue(task.isDone());
assertTrue(task.isFailed());
assertTrue(Exceptions.isCancellation(task.getError()));
logTracingResults("AbstractTaskTest.testToTryCancelled", task);
}
代码示例来源:origin: linkedin/parseq
@Test
public void testError() throws InterruptedException {
@SuppressWarnings("unused")
final Task<Try<String>> task = Task.callable("test", () -> {
if (true) {
throw new RuntimeException("boom");
}
return "hello";
} ).toTry();
runAndWait("TestWithTry.testError", task);
assertTrue(task.get().isFailed());
assertTrue(task.get().getError() instanceof RuntimeException);
assertEquals(task.get().getError().getMessage(), "boom");
}
代码示例来源:origin: linkedin/parseq
public void testToTry(int expectedNumberOfTasks) {
Task<Try<Integer>> success = getSuccessTask().map("strlen", String::length).toTry();
runAndWait("AbstractTaskTest.testToTrySuccess", success);
assertFalse(success.get().isFailed());
assertEquals((int) success.get().get(), TASK_VALUE.length());
assertEquals(countTasks(success.getTrace()), expectedNumberOfTasks);
Task<Try<Integer>> failure = getFailureTask().map("strlen", String::length).toTry();
runAndWait("AbstractTaskTest.testToTryFailure", failure);
assertTrue(failure.get().isFailed());
assertEquals(failure.get().getError().getMessage(), TASK_ERROR_MESSAGE);
assertEquals(countTasks(failure.getTrace()), expectedNumberOfTasks);
}
代码示例来源:origin: linkedin/parseq
@Test
public void testConfiguredD2TimeoutOutboundOp() {
setInboundRequestContext(new InboundRequestContextBuilder().setName("withD2Timeout").build());
Task<?> task = greetingDel(9999L).toTry();
runAndWait(getTestClassName() + ".testConfiguredD2TimeoutOutboundOp", task);
assertTrue(hasTask("withTimeout 5000ms src: withD2Timeout.*/greetings.*", task.getTrace()));
}
代码示例来源:origin: linkedin/parseq
@Test
public void testConfiguredTimeoutOutboundOp() {
try {
setInboundRequestContext(new InboundRequestContextBuilder()
.setName("blah")
.setMethod("GET")
.build());
Task<?> task = greetingDel(9999L).toTry();
runAndWait(getTestClassName() + ".testConfiguredTimeoutOutboundOp", task);
assertTrue(hasTask("withTimeout 10001ms src: *.*/greetings.*", task.getTrace()));
} finally {
clearInboundRequestContext();
}
}
代码示例来源:origin: com.linkedin.parseq/parseq
/**
* Equivalent to {@code toTry("toTry")}.
* @see #toTry(String)
*/
default Task<Try<T>> toTry() {
return toTry("toTry");
}
内容来源于网络,如有侵权,请联系作者删除!