use of org.flyte.api.v1.IfBlock 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));
}
use of org.flyte.api.v1.IfBlock in project flytekit-java by flyteorg.
the class IdentifierRewriteTest method shouldRewriteBranchNodes.
@Test
void shouldRewriteBranchNodes() {
ComparisonExpression comparison = ComparisonExpression.builder().operator(ComparisonExpression.Operator.EQ).leftValue(Operand.ofVar("a")).rightValue(Operand.ofVar("b")).build();
BooleanExpression condition = BooleanExpression.ofComparison(comparison);
PartialTaskIdentifier partialReference = PartialTaskIdentifier.builder().name("task-name").build();
PartialTaskIdentifier rewrittenReference = PartialTaskIdentifier.builder().name("task-name").domain("rewritten-domain").version("rewritten-version").project("rewritten-project").build();
TaskNode partialTaskNode = TaskNode.builder().referenceId(partialReference).build();
TaskNode rewrittenTaskNode = TaskNode.builder().referenceId(rewrittenReference).build();
Node partialNode = Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).taskNode(partialTaskNode).build();
Node rewrittenNode = Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).taskNode(rewrittenTaskNode).build();
IfBlock partialIfBlock = IfBlock.builder().condition(condition).thenNode(partialNode).build();
IfBlock rewrittenIfBlock = IfBlock.builder().condition(condition).thenNode(rewrittenNode).build();
BranchNode partialBranchNode = BranchNode.builder().ifElse(IfElseBlock.builder().case_(partialIfBlock).other(ImmutableList.of(partialIfBlock)).elseNode(partialNode).build()).build();
BranchNode rewrittenBranchNode = BranchNode.builder().ifElse(IfElseBlock.builder().case_(rewrittenIfBlock).other(ImmutableList.of(rewrittenIfBlock)).elseNode(rewrittenNode).build()).build();
assertThat(rewriter.visitor().visitBranchNode(partialBranchNode), equalTo(rewrittenBranchNode));
}
Aggregations