Skip to content

Add sync workflow replayer test #16816

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

Merged
merged 2 commits into from
Sep 16, 2022
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 @@ -8,6 +8,7 @@
import static org.mockito.Mockito.when;

import io.airbyte.workers.temporal.support.TemporalProxyHelper;
import io.airbyte.workers.temporal.sync.SyncWorkflowImpl;
import io.micronaut.context.BeanRegistration;
import io.micronaut.inject.BeanIdentifier;
import io.temporal.activity.ActivityOptions;
Expand All @@ -24,12 +25,11 @@
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
class WorkflowReplayingTest {

private ActivityOptions activityOptions;
private TemporalProxyHelper temporalProxyHelper;

@BeforeEach
void setUp() {
activityOptions = ActivityOptions.newBuilder()
ActivityOptions activityOptions = ActivityOptions.newBuilder()
.setHeartbeatTimeout(Duration.ofSeconds(30))
.setStartToCloseTimeout(Duration.ofSeconds(120))
.setRetryOptions(RetryOptions.newBuilder()
Expand All @@ -39,25 +39,47 @@ void setUp() {
.build())
.build();

final BeanIdentifier shortActivitiesBeanIdentifier = mock(BeanIdentifier.class);
final BeanRegistration shortActivityOptionsBeanRegistration = mock(BeanRegistration.class);
when(shortActivitiesBeanIdentifier.getName()).thenReturn("shortActivityOptions");
when(shortActivityOptionsBeanRegistration.getIdentifier()).thenReturn(shortActivitiesBeanIdentifier);
when(shortActivityOptionsBeanRegistration.getBean()).thenReturn(activityOptions);
temporalProxyHelper = new TemporalProxyHelper(List.of(shortActivityOptionsBeanRegistration));
final BeanRegistration shortActivityOptionsBeanRegistration = getActivityOptionBeanRegistration("shortActivityOptions", activityOptions);
final BeanRegistration longActivityOptionsBeanRegistration = getActivityOptionBeanRegistration("longRunActivityOptions", activityOptions);

temporalProxyHelper = new TemporalProxyHelper(List.of(shortActivityOptionsBeanRegistration, longActivityOptionsBeanRegistration));
}

@Test
void replaySimpleSuccessfulWorkflow() throws Exception {
void replaySimpleSuccessfulConnectionManagerWorkflow() throws Exception {
// This test ensures that a new version of the workflow doesn't break an in-progress execution
// This JSON file is exported from Temporal directly (e.g.
// `http://${temporal-ui}/namespaces/default/workflows/connection_manager_-${uuid}/${uuid}/history`)
// and export
final URL historyPath = getClass().getClassLoader().getResource("workflowHistory.json");
final URL historyPath = getClass().getClassLoader().getResource("connectionManagerWorkflowHistory.json");

final File historyFile = new File(historyPath.toURI());

WorkflowReplayer.replayWorkflowExecution(historyFile, temporalProxyHelper.proxyWorkflowClass(ConnectionManagerWorkflowImpl.class));
}

@Test
void replaySyncWorkflowWithNormalization() throws Exception {
// This test ensures that a new version of the workflow doesn't break an in-progress execution
// This JSON file is exported from Temporal directly (e.g.
// `http://${temporal-ui}/namespaces/default/workflows/connection_manager_-${uuid}/${uuid}/history`)
// and export

final URL historyPath = getClass().getClassLoader().getResource("syncWorkflowHistory.json");

final File historyFile = new File(historyPath.toURI());

WorkflowReplayer.replayWorkflowExecution(historyFile, temporalProxyHelper.proxyWorkflowClass(SyncWorkflowImpl.class));
}

private BeanRegistration getActivityOptionBeanRegistration(String name, ActivityOptions activityOptions) {
final BeanIdentifier activitiesBeanIdentifier = mock(BeanIdentifier.class);
final BeanRegistration activityOptionsBeanRegistration = mock(BeanRegistration.class);
when(activitiesBeanIdentifier.getName()).thenReturn(name);
when(activityOptionsBeanRegistration.getIdentifier()).thenReturn(activitiesBeanIdentifier);
when(activityOptionsBeanRegistration.getBean()).thenReturn(activityOptions);

return activityOptionsBeanRegistration;
}

}
Loading