Search in sources :

Example 26 with Literal

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);
}
Also used : Literal(org.flyte.api.v1.Literal) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 27 with Literal

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);
}
Also used : Literal(org.flyte.api.v1.Literal) LiteralType(org.flyte.api.v1.LiteralType)

Example 28 with Literal

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)))));
}
Also used : HashMap(java.util.HashMap) Instant(java.time.Instant) Literal(org.flyte.api.v1.Literal) Duration(java.time.Duration) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Literal (org.flyte.api.v1.Literal)28 Test (org.junit.jupiter.api.Test)16 HashMap (java.util.HashMap)9 Instant (java.time.Instant)7 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)7 LiteralType (org.flyte.api.v1.LiteralType)6 RunnableTask (org.flyte.api.v1.RunnableTask)6 Map (java.util.Map)5 Duration (java.time.Duration)4 List (java.util.List)4 Blob (org.flyte.api.v1.Blob)4 Variable (org.flyte.api.v1.Variable)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Literals (flyteidl.core.Literals)3 Struct (org.flyte.api.v1.Struct)3 Var (com.google.errorprone.annotations.Var)2 UncheckedIOException (java.io.UncheckedIOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Collections.emptyMap (java.util.Collections.emptyMap)2