Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple subworkflows mocks #281

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,11 @@ public <InputT, OutputT> SdkTestingExecutor withWorkflowOutput(

// replace workflow
SdkWorkflow<InputT, OutputT> mockWorkflow =
new TestingWorkflow<>(inputType, outputType, fixedTask.fixedOutputs);
new TestingWorkflow<>(inputType, outputType, fixedTask.fixedOutputs, workflow.getName());

return toBuilder()
.putWorkflowTemplate(workflow.getName(), mockWorkflow.toIdlTemplate())
.putFixedTask(workflow.getName(), fixedTask)
.putFixedTask(TestingWorkflow.TestingSdkRunnableTask.class.getName(), fixedTask)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@
class TestingWorkflow<InputT, OutputT> extends SdkWorkflow<InputT, OutputT> {

private final Map<InputT, OutputT> outputs;
private final String name;

TestingWorkflow(
SdkType<InputT> inputType, SdkType<OutputT> outputType, Map<InputT, OutputT> outputs) {
SdkType<InputT> inputType,
SdkType<OutputT> outputType,
Map<InputT, OutputT> outputs,
String name) {
super(inputType, outputType);
this.outputs = outputs;
this.name = name;
}

@Override
public OutputT expand(SdkWorkflowBuilder builder, InputT input) {
return builder
.apply(new TestingSdkRunnableTask<>(getInputType(), getOutputType(), outputs), input)
.apply(new TestingSdkRunnableTask<>(getInputType(), getOutputType(), outputs, name), input)
.getOutputs();
}

Expand All @@ -45,11 +50,21 @@ public static class TestingSdkRunnableTask<InputT, OutputT>
private static final long serialVersionUID = 6106269076155338045L;

private final Map<InputT, OutputT> outputs;
private final String name;

@Override
public String getName() {
return name;
}

public TestingSdkRunnableTask(
SdkType<InputT> inputType, SdkType<OutputT> outputType, Map<InputT, OutputT> outputs) {
SdkType<InputT> inputType,
SdkType<OutputT> outputType,
Map<InputT, OutputT> outputs,
String name) {
super(inputType, outputType);
this.outputs = outputs;
this.name = name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public void test() {
SubWorkflowInputs.create(SdkBindingDataFactory.of(1)),
JacksonSdkType.of(SubWorkflowOutputs.class),
SubWorkflowOutputs.create(SdkBindingDataFactory.of(10)))
.withWorkflowOutput(
new SubWorkflow1(),
JacksonSdkType.of(SubWorkflowInputs1.class),
SubWorkflowInputs1.create(SdkBindingDataFactory.of(11)),
JacksonSdkType.of(SubWorkflowOutputs1.class),
SubWorkflowOutputs1.create(SdkBindingDataFactory.of(110)))
.withWorkflowOutput(
new SubWorkflow(),
JacksonSdkType.of(SubWorkflowInputs.class),
Expand All @@ -64,10 +70,22 @@ public SubWorkflowOutputs expand(SdkWorkflowBuilder builder, SubWorkflowInputs i
var subOut1 =
builder
.apply(
"sub", new SubWorkflow(), SubWorkflowInputs.create(SdkBindingDataFactory.of(1)))
"subworkflow-1",
new SubWorkflow(),
SubWorkflowInputs.create(SdkBindingDataFactory.of(1)))
.getOutputs();
builder
.apply("sub1", new SubWorkflow(), SubWorkflowInputs.create(SdkBindingDataFactory.of(2)))
.apply(
"subworkflow1-1",
new SubWorkflow1(),
SubWorkflowInputs1.create(SdkBindingDataFactory.of(11)))
.getOutputs();

builder
.apply(
"subworkflow-2",
new SubWorkflow(),
SubWorkflowInputs.create(SdkBindingDataFactory.of(2)))
.getOutputs();

return SubWorkflowOutputs.create(subOut1.o());
Expand Down Expand Up @@ -104,4 +122,36 @@ public static MockSubWorkflowsTest.SubWorkflowOutputs create(SdkBindingData<Long
return new AutoValue_MockSubWorkflowsTest_SubWorkflowOutputs(o);
}
}

public static class SubWorkflow1 extends SdkWorkflow<SubWorkflowInputs1, SubWorkflowOutputs1> {
public SubWorkflow1() {
super(
JacksonSdkType.of(SubWorkflowInputs1.class),
JacksonSdkType.of(SubWorkflowOutputs1.class));
}

@Override
public SubWorkflowOutputs1 expand(SdkWorkflowBuilder builder, SubWorkflowInputs1 inputs) {

return SubWorkflowOutputs1.create(inputs.a1());
}
}

@AutoValue
public abstract static class SubWorkflowInputs1 {
public abstract SdkBindingData<Long> a1();

public static MockSubWorkflowsTest.SubWorkflowInputs1 create(SdkBindingData<Long> a1) {
return new AutoValue_MockSubWorkflowsTest_SubWorkflowInputs1(a1);
}
}

@AutoValue
public abstract static class SubWorkflowOutputs1 {
public abstract SdkBindingData<Long> o1();

public static MockSubWorkflowsTest.SubWorkflowOutputs1 create(SdkBindingData<Long> o1) {
return new AutoValue_MockSubWorkflowsTest_SubWorkflowOutputs1(o1);
}
}
}
Loading