Task implements Serializable { public static NamedTaskBuilder named(String taskName, Object... args) { return new NTB(TaskId.create(taskName, args)); }  abstract TaskId id(); abstract Class<T> type(); abstract List<TaskContext<?, ? super T>> contexts(); List<Task<?>> inputs(); static NamedTaskBuilder named(String taskName, Object... args); static Task<T> create(Fn<T> code, Class<T> type, String taskName, Object... args);  }
@Test(expected = IllegalArgumentException.class) public void shouldDisallowMultipleTaskOperators() { Task.named("task") .ofType(String.class) .operator(operator1) .operator(operator2) .process((a, b) -> { throw new AssertionError(); }); }
@Test(expected = IllegalArgumentException.class) public void shouldDisallowMultipleTaskOutputs() { Task.named("task") .ofType(String.class) .output(tcs1) .output(tcs2) .process((a, b) -> { throw new AssertionError(); }); }
@Test public void shouldEvaluate0N() throws Exception { Task<String> task = Task.named("InContext").ofType(String.class) .process(() -> "constant"); AwaitValue<String> val = new AwaitValue<>(); ControlledBlockingContext context = new ControlledBlockingContext(); context.evaluate(task).consume(val); context.waitFor(task); context.release(task); context.waitUntilNumConcurrent(0); assertThat(val.awaitAndGet(), is("constant")); }
@Test public void shouldEvaluate1N_I() throws Exception { Task<String> task = Task.named("InContext").ofType(String.class) .input(() -> leaf("A")) .process((a) -> "done: " + a); validateEvaluation(task, "done: A", leaf("A")); }
@Test public void shouldEvaluate2N_II() throws Exception { Task<String> task = Task.named("InContext").ofType(String.class) .input(() -> leaf("A")) .input(() -> leaf("B")) .process((a, b) -> "done: " + a + " - " + b); validateEvaluation(task, "done: A - B", leaf("A"), leaf("B")); }
@Test public void shouldEvaluate3N_III() throws Exception { Task<String> task = Task.named("InContext").ofType(String.class) .input(() -> leaf("A")) .input(() -> leaf("B")) .input(() -> leaf("C")) .process((a, b, c) -> "done: " + a + " - " + b +" - " + c); validateEvaluation(task, "done: A - B - C", leaf("A"), leaf("B"), leaf("C")); }
@Test public void shouldRequireSerializableProcessFn() { final TaskBuilder<String> b = Task.named("foo").ofType(String.class); final Object o = new Object(); final F0<String> fn = () -> o.toString(); exception.expect(IllegalArgumentException.class); exception.expectMessage("process fn not serializable: " + fn); exception.expectCause(is(instanceOf(SerializationException.class))); b.process(fn); }
@Test public void shouldRequireSerializableInput() { final TaskBuilder<String> b = Task.named("foo").ofType(String.class); final Object o = new Object(); final Fn<Task<String>> input = () -> Task.named(o.toString()).ofType(String.class).process(() -> "foo"); exception.expect(IllegalArgumentException.class); exception.expectMessage("input not serializable: " + input); exception.expectCause(is(instanceOf(SerializationException.class))); b.input(input); }
@Test public void shouldRequireSerializableOperator() { final TaskBuilder<String> b = Task.named("foo").ofType(String.class); final TaskOperator<String, String, String> operator = new TaskOperator<String, String, String>() { private final Object o = new Object(); @Override public String perform(String spec, Listener listener) { return ""; } @Override public String provide(EvalContext evalContext) { return ""; } }; exception.expect(IllegalArgumentException.class); exception.expectMessage("operator not serializable: " + operator); exception.expectCause(is(instanceOf(SerializationException.class))); b.operator(operator); }
@Test public void shouldRequireSerializableContext() { final TaskBuilder<String> b = Task.named("foo").ofType(String.class); final TaskContextGeneric<String> context = new TaskContextGeneric<String>() { private final Object o = new Object(); @Override public String provide(EvalContext evalContext) { return ""; } }; exception.expect(IllegalArgumentException.class); exception.expectMessage("context not serializable: " + context); exception.expectCause(is(instanceOf(SerializationException.class))); b.context(context); }