-
Notifications
You must be signed in to change notification settings - Fork 751
[GOBBLIN-2160] Setup Temporal docker Cluster for CI Tests and added tests for AbstractNestingExecWorkflowImpl #4059
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
Open
pratapaditya04
wants to merge
7
commits into
apache:master
Choose a base branch
from
pratapaditya04:temporal_module_unit_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3950d10
added some unit tests for gobblin temporal module
353190b
merged with master
949df4a
integrated with docker to prevent mocking temporal workflows
f34caa9
integrated with docker to prevent mocking temporal workflows
f4876c0
Merge remote-tracking branch 'origin/temporal_module_unit_tests' into…
4cd7e08
removed unnecessary files
857a70f
added docker compose for temporal
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
...va/org/apache/gobblin/temporal/ddm/workflow/impl/AbstractNestingExecWorkflowImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.gobblin.temporal.ddm.workflow.impl; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import io.temporal.api.common.v1.WorkflowExecution; | ||
import io.temporal.api.history.v1.History; | ||
import io.temporal.api.history.v1.HistoryEvent; | ||
import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryReverseRequest; | ||
import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryReverseResponse; | ||
import io.temporal.client.WorkflowClient; | ||
import io.temporal.client.WorkflowOptions; | ||
import io.temporal.serviceclient.WorkflowServiceStubs; | ||
import io.temporal.worker.Worker; | ||
import io.temporal.worker.WorkerFactory; | ||
import io.temporal.api.enums.v1.EventType; | ||
|
||
|
||
import org.apache.gobblin.temporal.loadgen.activity.IllustrationItemActivity; | ||
import org.apache.gobblin.temporal.loadgen.work.IllustrationItem; | ||
import org.apache.gobblin.temporal.loadgen.work.SimpleGeneratedWorkload; | ||
import org.apache.gobblin.temporal.loadgen.workflow.impl.NestingExecOfIllustrationItemActivityWorkflowImpl; | ||
import org.apache.gobblin.temporal.util.nesting.work.WorkflowAddr; | ||
import org.apache.gobblin.temporal.util.nesting.work.Workload; | ||
import org.apache.gobblin.temporal.util.nesting.workflow.NestingExecWorkflow; | ||
|
||
|
||
public class AbstractNestingExecWorkflowImplTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AbstractNestingExecWorkflowImplTest.class); | ||
|
||
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to log / or print something in tests, can we please remove them ? |
||
private WorkflowServiceStubs service; | ||
private WorkflowClient client; | ||
private WorkerFactory factory; | ||
private Worker worker; | ||
private final String TEMPORAL_TASK_QUEUE = "test-task-queue"; | ||
|
||
@BeforeMethod | ||
public void setUp() throws Exception { | ||
// Connect to the Temporal service running in Docker | ||
service = WorkflowServiceStubs.newInstance(); | ||
client = WorkflowClient.newInstance(service); | ||
factory = WorkerFactory.newInstance(client); | ||
worker = factory.newWorker(TEMPORAL_TASK_QUEUE); | ||
worker.registerWorkflowImplementationTypes(NestingExecOfIllustrationItemActivityWorkflowImpl.class); | ||
worker.registerActivitiesImplementations(new MockHandleItemActivityImpl()); | ||
factory.start(); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() { | ||
factory.shutdown(); | ||
service.shutdown(); | ||
} | ||
|
||
@Test | ||
public void testPerformWorkloadWithEmptyWorkload() { | ||
final String workFlowId = UUID.randomUUID().toString(); | ||
final NestingExecWorkflow workflow = client.newWorkflowStub(NestingExecWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(TEMPORAL_TASK_QUEUE).setWorkflowId(workFlowId).build()); | ||
|
||
Workload<IllustrationItem> workload = SimpleGeneratedWorkload.createAs(0); | ||
|
||
int result = workflow.performWorkload(WorkflowAddr.ROOT, workload, 0, 900, 30, Optional.empty()); | ||
Assert.assertEquals(0, result); | ||
Assert.assertEquals(0, getDepthLevelOfWorkFlowNesting(workFlowId)); | ||
} | ||
|
||
@Test | ||
public void testPerformWorkloadWithPartialSpan() { | ||
final String workFlowId = UUID.randomUUID().toString(); | ||
final NestingExecWorkflow workflow = client.newWorkflowStub(NestingExecWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(TEMPORAL_TASK_QUEUE).setWorkflowId(workFlowId).build()); | ||
|
||
Workload workload = SimpleGeneratedWorkload.createAs(500); | ||
|
||
int result = workflow.performWorkload(new WorkflowAddr(0), workload, 0, 900, 30, Optional.empty()); | ||
Assert.assertEquals(500, result); | ||
Assert.assertEquals(0, getDepthLevelOfWorkFlowNesting(workFlowId)); | ||
} | ||
|
||
@Test | ||
public void testPerformWorkloadWithTwoLevelsOfNesting() { | ||
final String workFlowId = UUID.randomUUID().toString(); | ||
final NestingExecWorkflow workflow = client.newWorkflowStub(NestingExecWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(TEMPORAL_TASK_QUEUE).setWorkflowId(workFlowId).build()); | ||
|
||
Workload workload = SimpleGeneratedWorkload.createAs(2048); | ||
|
||
int result = workflow.performWorkload(new WorkflowAddr(0), workload, 0, 900, 30, Optional.empty()); | ||
Assert.assertEquals(2048, result); | ||
Assert.assertEquals(2, getDepthLevelOfWorkFlowNesting(workFlowId)); | ||
} | ||
|
||
@Test | ||
public void testPerformWorkloadWithMaxBranchesExceeded_WithTreeDepth_1() { | ||
final String workFlowId = UUID.randomUUID().toString(); | ||
final NestingExecWorkflow workflow = client.newWorkflowStub(NestingExecWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(TEMPORAL_TASK_QUEUE).setWorkflowId(workFlowId).build()); | ||
|
||
Workload workload = SimpleGeneratedWorkload.createAs(1024); | ||
|
||
int result = workflow.performWorkload(new WorkflowAddr(0), workload, 0, 1025, 30, Optional.empty()); | ||
|
||
logger.info("PerformWorkload method returned"); | ||
Assert.assertEquals(1024, result); | ||
Assert.assertEquals(1, getDepthLevelOfWorkFlowNesting(workFlowId)); | ||
} | ||
|
||
@Test | ||
public void testPerformWorkloadWithMaxSubTreesOverride_WithTreeDepth_0() { | ||
final String workFlowId = UUID.randomUUID().toString(); | ||
final NestingExecWorkflow workflow = client.newWorkflowStub(NestingExecWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(TEMPORAL_TASK_QUEUE).setWorkflowId(workFlowId).build()); | ||
|
||
logger.info("Calling performWorkload method on workflow with max sub-trees override"); | ||
Workload workload = SimpleGeneratedWorkload.createAs(1024); | ||
|
||
int result = workflow.performWorkload(new WorkflowAddr(0), workload, 0, 1024, 30, Optional.of(0)); | ||
Assert.assertEquals(1024, result); | ||
Assert.assertEquals(0, getDepthLevelOfWorkFlowNesting(workFlowId)); | ||
} | ||
|
||
private int getDepthLevelOfWorkFlowNesting(String workFlowId) { | ||
final GetWorkflowExecutionHistoryReverseResponse workflowExecutionHistoryResponse = client.getWorkflowServiceStubs() | ||
.blockingStub() | ||
.getWorkflowExecutionHistoryReverse(GetWorkflowExecutionHistoryReverseRequest.newBuilder() | ||
.setNamespace("default") | ||
.setExecution(WorkflowExecution.newBuilder().setWorkflowId(workFlowId).build()) | ||
.build()); | ||
int depth = 0; | ||
final History history = workflowExecutionHistoryResponse.getHistory(); | ||
for (HistoryEvent historyEvent : history.getEventsList()) { | ||
if (historyEvent.getEventType().equals(EventType.EVENT_TYPE_START_CHILD_WORKFLOW_EXECUTION_INITIATED)) { | ||
depth++; | ||
} | ||
} | ||
return depth; | ||
} | ||
|
||
private class MockHandleItemActivityImpl implements IllustrationItemActivity { | ||
@Override | ||
public String handleItem(IllustrationItem item) { | ||
return null; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.