com.linkedin.parseq.Task.map()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中com.linkedin.parseq.Task.map()方法的一些代码示例,展示了Task.map()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.map()方法的具体详情如下:
包路径:com.linkedin.parseq.Task
类名称:Task
方法名:map

Task.map介绍

[英]Equivalent to map("map", func).
[中]相当于map(“map”,func)。

代码示例

代码示例来源:origin: linkedin/parseq

@Override
Task<?> createPlan() {
 return Task.value("kldfjlajflskjflsjfslkajflkasj").map("length", s -> s.length()).map("+1", s -> s + 1)
   .map("+2", s -> s + 2).map("+3", s -> s + 3);
}

代码示例来源:origin: linkedin/parseq

/**
 * Equivalent to {@code map("map", func)}.
 * @see #map(String, Function1)
 */
default <R> Task<R> map(final Function1<? super T, ? extends R> func) {
 return map("map: " + _taskDescriptor.getDescription(func.getClass().getName()), func);
}

代码示例来源:origin: linkedin/parseq

private Task<?> task() {
 return Task.value("kldfjlajflskjflsjfslkajflkasj").map("length", s -> s.length()).map("+1", s -> s + 1)
   .map("+2", s -> s + 2).map("+3", s -> s + 3).shareable().recoverWith(t -> Task.value(0))
   .flatMap(x -> Task.value(x * 40)).map(x -> x -10);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testMap4() {
 Task<Integer> task = Task.value("value", 1).map("m1", x -> x).map("m2", x -> x).map("m3", x -> x).map("m4", x -> x);
 runAndWait("FusionTaskTraceTest.testMap4", task);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testAsync4() {
 Task<Integer> task = Task.async("value", () -> {
  SettablePromise<Integer> p = Promises.settable();
  p.done(1);
  return p;
 }).map("m1", x -> x).map("m2", x -> x).map("m3", x -> x).map("m4", x -> x);
 runAndWait("FusionTaskTraceTest.testAsyncMap4", task);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testMap2() {
 Task<Integer> task = Task.value("value", 1).map("m1", x -> x).map("m2", x -> x);
 runAndWait("FusionTaskTraceTest.testMap2", task);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testAsync3() {
 Task<Integer> task = Task.async("value", () -> {
  SettablePromise<Integer> p = Promises.settable();
  p.done(1);
  return p;
 }).map("m1", x -> x).map("m2", x -> x).map("m3", x -> x);
 runAndWait("FusionTaskTraceTest.testAsyncMap3", task);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testWithTimeoutAsLastOperation() {
 Task<String> task = delayedValue("value", 250, TimeUnit.MILLISECONDS).map(x -> x + 1).map(x -> TASK_VALUE)
   .withTimeout(5, TimeUnit.MILLISECONDS);
 try {
  runAndWait("TestFusionTask.testWithTimeoutAsLastOperation", task);
  fail("should have failed!");
 } catch (Exception ex) {
  assertSame(ex.getCause().getClass(), Exceptions.TIMEOUT_EXCEPTION.getClass());
 }
}

代码示例来源:origin: linkedin/parseq

@Test
public void testWithTimeoutAsMiddleOperation() {
 Task<String> task = delayedValue("value", 250, TimeUnit.MILLISECONDS).map("first", x -> x + 3)
   .withTimeout(5, TimeUnit.MILLISECONDS).map("second", x -> TASK_VALUE);
 try {
  runAndWait("TestFusionTask.testWithTimeoutAsMiddleOperation", task);
  fail("should have failed!");
 } catch (Exception ex) {
  assertSame(ex.getCause().getClass(), Exceptions.TIMEOUT_EXCEPTION.getClass());
 }
}

代码示例来源:origin: linkedin/parseq

@Test
public void testMap1() {
 Task<Integer> task = Task.value("value", 1).map("m1", x -> x);
 runAndWait("FusionTaskTraceTest.testMap1", task);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testAsync2() {
 Task<Integer> task = Task.async("value", () -> {
  SettablePromise<Integer> p = Promises.settable();
  p.done(1);
  return p;
 }).map("m1", x -> x).map("m2", x -> x);
 runAndWait("FusionTaskTraceTest.testAsyncMap2", task);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testMapFork() {
 Task<Integer> base = Task.value("value", 1);
 Task<Integer> task = Task.par(base.map("m1", x -> x), base.map("m2", x -> x))
 .map("sum", (x, y) -> x + y);
 runAndWait("FusionTaskTraceTest.testMapFork", task);
}

代码示例来源:origin: linkedin/parseq

public void testNoRecover(int expectedNumberOfTasks) {
 Task<Integer> task = getFailureTask().map("strlen", String::length);
 try {
  runAndWait("AbstractTaskTest.testNoRecover", task);
  fail("should have failed");
 } catch (Exception ex) {
  assertEquals(ex.getCause().getMessage(), TASK_ERROR_MESSAGE);
 }
 assertEquals(countTasks(task.getTrace()), expectedNumberOfTasks);
}

代码示例来源:origin: linkedin/parseq

public void testFlattenTaskReturnNulll() {
 Function1<String, Task<String>> func = s -> null;
 Task<String> task = Task.flatten(getSuccessTask().map(func));
 runAndWaitException("AbstractTaskTest.testFlattenTaskReturnNulll", task, RuntimeException.class);
 assertTrue(task.getError().getMessage().contains("returned null"));
}

代码示例来源:origin: linkedin/parseq

public void testMap(int expectedNumberOfTasks) {
 Task<Integer> task = getSuccessTask().map(String::length);
 runAndWait("AbstractTaskTest.testMap", task);
 assertTrue(task.isDone());
 assertEquals((int) task.get(), TASK_VALUE.length());
 assertEquals(countTasks(task.getTrace()), expectedNumberOfTasks);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testSingleGetRequestIsNotBatchedWithProjection() {
 Task<Boolean> task = greetingGetWithProjection(1L, Greeting.fields().tone()).map(Response::getEntity).map(Greeting::hasMessage);
 runAndWait(getTestClassName() + ".testSingleGetRequestIsNotBatchedWithProjection", task);
 assertFalse(hasTask("greetings batch_get(reqs: 1, ids: 1)", task.getTrace()));
 assertFalse(task.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testAsyncMap1() {
 Task<Integer> task = Task.async("value", () -> {
  SettablePromise<Integer> p = Promises.settable();
  p.done(1);
  return p;
 }).map("m1", x -> x);
 runAndWait("FusionTaskTraceTest.testAsyncMa1p", task);
}

代码示例来源:origin: linkedin/parseq

public void testRecover(int expectedNumberOfTasks) {
 Task<Integer> success = getSuccessTask().map("strlen", String::length).recover(e -> -1);
 runAndWait("AbstractTaskTest.testRecoverSuccess", success);
 assertEquals((int) success.get(), TASK_VALUE.length());
 assertEquals(countTasks(success.getTrace()), expectedNumberOfTasks);
 Task<Integer> failure = getFailureTask().map("strlen", String::length).recover(e -> -1);
 runAndWait("AbstractTaskTest.testRecoverFailure", failure);
 assertEquals((int) failure.get(), -1);
 assertEquals(countTasks(failure.getTrace()), expectedNumberOfTasks);
}

代码示例来源:origin: linkedin/parseq

public void testCancelledRecover(int expectedNumberOfTasks) {
 Task<Integer> cancelled = getCancelledTask().map("strlen", String::length).recover(e -> -1);
 try {
  runAndWait("AbstractTaskTest.testCancelledRecover", cancelled);
  fail("should have failed");
 } catch (Exception ex) {
  assertTrue(cancelled.isFailed());
  assertTrue(Exceptions.isCancellation(cancelled.getError()));
 }
 assertEquals(countTasks(cancelled.getTrace()), expectedNumberOfTasks);
}

代码示例来源: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);
}

相关文章