use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.
the class ChainedExecutionListenerTest method testChaining.
@Test
public void testChaining() {
TestingListener listener1 = new TestingListener();
TestingListener listener2 = new TestingListener();
ExecutionListener chained = ChainedExecutionListener.of(ImmutableList.of(listener1, listener2));
ExecutionNode node = ExecutionNode.builder().nodeId("node-1").upstreamNodeIds(ImmutableList.of()).bindings(ImmutableList.of()).runnableTask(new EmptyRunnableTask()).attempts(1).build();
Literal a = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(42L)));
Literal b = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(1337L)));
chained.pending(node);
chained.starting(node, ImmutableMap.of("a", a));
chained.retrying(node, ImmutableMap.of("a", a), new RuntimeException("oops"), /* attempt= */
0);
chained.completed(node, ImmutableMap.of("a", a), ImmutableMap.of("b", b));
chained.error(node, ImmutableMap.of("a", a), new RuntimeException("oops"));
List<List<Object>> expected = ImmutableList.of(ofPending("node-1"), ofStarting("node-1", ImmutableMap.of("a", a)), ofRetrying("node-1", ImmutableMap.of("a", a), "oops", /* attempt= */
0), ofCompleted("node-1", ImmutableMap.of("a", a), ImmutableMap.of("b", b)), ofError("node-1", ImmutableMap.of("a", a), "oops"));
assertEquals(expected, listener1.actions);
assertEquals(expected, listener2.actions);
}
use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.
the class TestingSdkWorkflowBuilder method inputOf.
@Override
public SdkBindingData inputOf(String name, LiteralType literalType, String help) {
LiteralType fixedInputType = fixedInputTypeMap.get(name);
Literal fixedInput = fixedInputMap.get(name);
checkArgument(fixedInputType != null, "Fixed input [%s] (of type %s) isn't defined, use SdkTestingExecutor#withFixedInput", name, LiteralTypes.toPrettyString(literalType));
checkArgument(fixedInputType.equals(literalType), "Fixed input [%s] (of type %s) doesn't match expected type %s", name, LiteralTypes.toPrettyString(fixedInputType), LiteralTypes.toPrettyString(literalType));
return SdkBindingData.create(Literals.toBindingData(fixedInput), fixedInputType);
}
use of org.flyte.api.v1.Literal in project flytekit-java by flyteorg.
the class SdkLaunchPlanTest method shouldAddFixedInputs.
@Test
void shouldAddFixedInputs() {
Instant now = Instant.now();
Duration duration = Duration.ofSeconds(123);
Map<String, Literal> fixedInputs = new HashMap<>();
fixedInputs.put("inputsFoo", Literals.ofInteger(456));
fixedInputs.put("inputsBar", Literals.ofFloat(4.56));
SdkLaunchPlan plan = SdkLaunchPlan.of(new TestWorkflow()).withFixedInput("integer", 123L).withFixedInput("float", 1.23).withFixedInput("string", "123").withFixedInput("boolean", true).withFixedInput("datetime", now).withFixedInput("duration", duration).withFixedInputs(TestSdkType.of("inputsFoo", LiteralTypes.INTEGER, "inputsBar", LiteralTypes.FLOAT), fixedInputs);
assertThat(plan.fixedInputs(), allOf(hasEntry("integer", asLiteral(Primitive.ofIntegerValue(123))), hasEntry("float", asLiteral(Primitive.ofFloatValue(1.23))), hasEntry("string", asLiteral(Primitive.ofStringValue("123"))), hasEntry("boolean", asLiteral(Primitive.ofBooleanValue(true))), hasEntry("datetime", asLiteral(Primitive.ofDatetime(now))), hasEntry("duration", asLiteral(Primitive.ofDuration(duration))), hasEntry("inputsFoo", asLiteral(Primitive.ofIntegerValue(456))), hasEntry("inputsBar", asLiteral(Primitive.ofFloatValue(4.56)))));
}
Aggregations