Search in sources :

Example 1 with Condition

use of flyteidl.core.Condition in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldSerializeBranchNode.

@Test
void shouldSerializeBranchNode() {
    ComparisonExpression comparison = ComparisonExpression.builder().operator(ComparisonExpression.Operator.EQ).leftValue(Operand.ofVar("a")).rightValue(Operand.ofVar("b")).build();
    Condition.ComparisonExpression comparisonProto = Condition.ComparisonExpression.newBuilder().setOperator(Condition.ComparisonExpression.Operator.EQ).setLeftValue(Condition.Operand.newBuilder().setVar("a").build()).setRightValue(Condition.Operand.newBuilder().setVar("b").build()).build();
    IfBlock ifBlock = IfBlock.builder().condition(BooleanExpression.ofComparison(comparison)).thenNode(Node.builder().id("node-1").upstreamNodeIds(ImmutableList.of()).inputs(ImmutableList.of()).build()).build();
    Workflow.IfBlock ifBlockProto = Workflow.IfBlock.newBuilder().setThenNode(Workflow.Node.newBuilder().setId("node-1").build()).setCondition(Condition.BooleanExpression.newBuilder().setComparison(comparisonProto).build()).build();
    IfElseBlock ifElse = IfElseBlock.builder().case_(ifBlock).other(ImmutableList.of(ifBlock)).elseNode(ifBlock.thenNode()).build();
    Workflow.IfElseBlock ifElseProto = Workflow.IfElseBlock.newBuilder().setCase(ifBlockProto).addOther(ifBlockProto).setElseNode(ifBlockProto.getThenNode()).build();
    BranchNode branchNode = BranchNode.builder().ifElse(ifElse).build();
    Workflow.BranchNode branchNodeProto = Workflow.BranchNode.newBuilder().setIfElse(ifElseProto).build();
    assertThat(ProtoUtil.serialize(branchNode), equalTo(branchNodeProto));
}
Also used : Condition(flyteidl.core.Condition) ComparisonExpression(org.flyte.api.v1.ComparisonExpression) IfElseBlock(org.flyte.api.v1.IfElseBlock) BranchNode(org.flyte.api.v1.BranchNode) Workflow(flyteidl.core.Workflow) IfBlock(org.flyte.api.v1.IfBlock) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Condition (flyteidl.core.Condition)1 Workflow (flyteidl.core.Workflow)1 BranchNode (org.flyte.api.v1.BranchNode)1 ComparisonExpression (org.flyte.api.v1.ComparisonExpression)1 IfBlock (org.flyte.api.v1.IfBlock)1 IfElseBlock (org.flyte.api.v1.IfElseBlock)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1