Last active
January 15, 2021 19:29
-
-
Save robzienert/548e18fd981d0f1a8d8bc02caf712d1f to your computer and use it in GitHub Desktop.
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
| /* | |
| * Copyright 2021 Netflix, Inc. | |
| * | |
| * Licensed 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 com.netflix.mast.loadtest.rabbit | |
| import io.temporal.activity.ActivityOptions | |
| import io.temporal.api.enums.v1.ParentClosePolicy | |
| import io.temporal.workflow.Async | |
| import io.temporal.workflow.ChildWorkflowOptions | |
| import io.temporal.workflow.Promise | |
| import io.temporal.workflow.Workflow | |
| import io.temporal.workflow.WorkflowInterface | |
| import io.temporal.workflow.WorkflowMethod | |
| import java.time.Duration | |
| enum class Behavior { | |
| SPAWN_AND_WAIT, | |
| SPAWN_AND_TERMINATE, | |
| SPAWN_AND_CANCEL | |
| } | |
| data class RabbitBehaviorConfig( | |
| val behavior: Behavior, | |
| val fanOut: Int, | |
| val depth: Int | |
| ) | |
| @WorkflowInterface | |
| interface RabbitLoadScenarioWorkflow { | |
| @WorkflowMethod | |
| fun startAndWait(config: RabbitBehaviorConfig) | |
| } | |
| class BranchRabbitLoadScenarioWorkflow : RabbitLoadScenarioWorkflow { | |
| override fun startAndWait(config: RabbitBehaviorConfig) { | |
| when (config.behavior) { | |
| Behavior.SPAWN_AND_WAIT -> spawnAndWait(config) | |
| else -> TODO("behavior not implemented") | |
| } | |
| } | |
| private fun spawnAndWait(config: RabbitBehaviorConfig) { | |
| val taskQueue = if (config.depth == 0) "leaf" else "branch" | |
| val promises = mutableListOf<Promise<Unit>>() | |
| repeat(config.fanOut) { | |
| val child = Workflow.newChildWorkflowStub( | |
| RabbitLoadScenarioWorkflow::class.java, | |
| ChildWorkflowOptions.newBuilder() | |
| .setTaskQueue("rabbit-$taskQueue") | |
| .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_TERMINATE) | |
| .build() | |
| ) | |
| promises.add(Async.function { child.startAndWait(config.copy(depth = config.depth - 1)) }) | |
| } | |
| Promise.allOf(promises).get() | |
| } | |
| } | |
| class LeafRabbitLoadScenarioWorkflow : RabbitLoadScenarioWorkflow { | |
| private val rabbitActivities: RabbitActivities = Workflow.newActivityStub( | |
| RabbitActivities::class.java, | |
| ActivityOptions.newBuilder() | |
| .setStartToCloseTimeout(Duration.ofMinutes(1)) | |
| .build() | |
| ) | |
| override fun startAndWait(config: RabbitBehaviorConfig) { | |
| rabbitActivities.hippityHop() | |
| rabbitActivities.munchOnLeafyGreens() | |
| rabbitActivities.wiggleNose() | |
| } | |
| } |
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
| [ | |
| { | |
| "eventId": "1", | |
| "eventTime": { | |
| "seconds": "1610737414", | |
| "nanos": 980991315 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", | |
| "version": "0", | |
| "taskId": "1048576", | |
| "workflowExecutionStartedEventAttributes": { | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| }, | |
| "parentWorkflowNamespace": "", | |
| "parentInitiatedEventId": "0", | |
| "taskQueue": { | |
| "name": "rabbit-branch", | |
| "kind": "TASK_QUEUE_KIND_NORMAL" | |
| }, | |
| "input": { | |
| "payloads": [ | |
| { | |
| "metadata": { | |
| "encoding": "anNvbi9wbGFpbg==" | |
| }, | |
| "data": "eyJiZWhhdmlvciI6IlNQQVdOX0FORF9XQUlUIiwiZmFuT3V0IjoyLCJkZXB0aCI6NH0=" | |
| } | |
| ] | |
| }, | |
| "workflowExecutionTimeout": { | |
| "seconds": "1800", | |
| "nanos": 0 | |
| }, | |
| "workflowRunTimeout": { | |
| "seconds": "1800", | |
| "nanos": 0 | |
| }, | |
| "workflowTaskTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "continuedExecutionRunId": "", | |
| "initiator": "CONTINUE_AS_NEW_INITIATOR_UNSPECIFIED", | |
| "originalExecutionRunId": "d7139319-5534-4acf-9791-b60c0e28839d", | |
| "identity": "54901@Robs-MacBook-Pro.local", | |
| "firstExecutionRunId": "d7139319-5534-4acf-9791-b60c0e28839d", | |
| "attempt": 1, | |
| "workflowExecutionExpirationTime": { | |
| "seconds": "1610739214", | |
| "nanos": 980000000 | |
| }, | |
| "cronSchedule": "", | |
| "firstWorkflowTaskBackoff": { | |
| "seconds": "0", | |
| "nanos": 0 | |
| }, | |
| "header": { | |
| "fields": {} | |
| } | |
| }, | |
| "attributes": "workflowExecutionStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "2", | |
| "eventTime": { | |
| "seconds": "1610737414", | |
| "nanos": 981023287 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_SCHEDULED", | |
| "version": "0", | |
| "taskId": "1048577", | |
| "workflowTaskScheduledEventAttributes": { | |
| "taskQueue": { | |
| "name": "rabbit-branch", | |
| "kind": "TASK_QUEUE_KIND_NORMAL" | |
| }, | |
| "startToCloseTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "attempt": 1 | |
| }, | |
| "attributes": "workflowTaskScheduledEventAttributes" | |
| }, | |
| { | |
| "eventId": "3", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 3394350 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_STARTED", | |
| "version": "0", | |
| "taskId": "1048582", | |
| "workflowTaskStartedEventAttributes": { | |
| "scheduledEventId": "2", | |
| "identity": "54901@Robs-MacBook-Pro.local", | |
| "requestId": "0dbd046a-bead-498a-8d3a-401f6d2cff49" | |
| }, | |
| "attributes": "workflowTaskStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "4", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 328653966 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048585", | |
| "workflowTaskCompletedEventAttributes": { | |
| "scheduledEventId": "2", | |
| "startedEventId": "3", | |
| "identity": "54901@Robs-MacBook-Pro.local", | |
| "binaryChecksum": "" | |
| }, | |
| "attributes": "workflowTaskCompletedEventAttributes" | |
| }, | |
| { | |
| "eventId": "5", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 328763218 | |
| }, | |
| "eventType": "EVENT_TYPE_START_CHILD_WORKFLOW_EXECUTION_INITIATED", | |
| "version": "0", | |
| "taskId": "1048586", | |
| "startChildWorkflowExecutionInitiatedEventAttributes": { | |
| "namespace": "", | |
| "workflowId": "f2ec2875-afca-3cdf-bde3-cd22b24f717a", | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| }, | |
| "taskQueue": { | |
| "name": "rabbit-branch", | |
| "kind": "TASK_QUEUE_KIND_UNSPECIFIED" | |
| }, | |
| "input": { | |
| "payloads": [ | |
| { | |
| "metadata": { | |
| "encoding": "anNvbi9wbGFpbg==" | |
| }, | |
| "data": "eyJiZWhhdmlvciI6IlNQQVdOX0FORF9XQUlUIiwiZmFuT3V0IjoyLCJkZXB0aCI6M30=" | |
| } | |
| ] | |
| }, | |
| "workflowExecutionTimeout": { | |
| "seconds": "0", | |
| "nanos": 0 | |
| }, | |
| "workflowRunTimeout": { | |
| "seconds": "0", | |
| "nanos": 0 | |
| }, | |
| "workflowTaskTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "parentClosePolicy": "PARENT_CLOSE_POLICY_TERMINATE", | |
| "control": "", | |
| "workflowTaskCompletedEventId": "4", | |
| "workflowIdReusePolicy": "WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE", | |
| "cronSchedule": "" | |
| }, | |
| "attributes": "startChildWorkflowExecutionInitiatedEventAttributes" | |
| }, | |
| { | |
| "eventId": "6", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 328807983 | |
| }, | |
| "eventType": "EVENT_TYPE_START_CHILD_WORKFLOW_EXECUTION_INITIATED", | |
| "version": "0", | |
| "taskId": "1048587", | |
| "startChildWorkflowExecutionInitiatedEventAttributes": { | |
| "namespace": "", | |
| "workflowId": "6c02c6b4-9c03-3e90-954b-95e0d9c740dd", | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| }, | |
| "taskQueue": { | |
| "name": "rabbit-branch", | |
| "kind": "TASK_QUEUE_KIND_UNSPECIFIED" | |
| }, | |
| "input": { | |
| "payloads": [ | |
| { | |
| "metadata": { | |
| "encoding": "anNvbi9wbGFpbg==" | |
| }, | |
| "data": "eyJiZWhhdmlvciI6IlNQQVdOX0FORF9XQUlUIiwiZmFuT3V0IjoyLCJkZXB0aCI6M30=" | |
| } | |
| ] | |
| }, | |
| "workflowExecutionTimeout": { | |
| "seconds": "0", | |
| "nanos": 0 | |
| }, | |
| "workflowRunTimeout": { | |
| "seconds": "0", | |
| "nanos": 0 | |
| }, | |
| "workflowTaskTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "parentClosePolicy": "PARENT_CLOSE_POLICY_TERMINATE", | |
| "control": "", | |
| "workflowTaskCompletedEventId": "4", | |
| "workflowIdReusePolicy": "WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE", | |
| "cronSchedule": "" | |
| }, | |
| "attributes": "startChildWorkflowExecutionInitiatedEventAttributes" | |
| }, | |
| { | |
| "eventId": "7", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 608057742 | |
| }, | |
| "eventType": "EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_STARTED", | |
| "version": "0", | |
| "taskId": "1048591", | |
| "childWorkflowExecutionStartedEventAttributes": { | |
| "namespace": "", | |
| "initiatedEventId": "6", | |
| "workflowExecution": { | |
| "workflowId": "6c02c6b4-9c03-3e90-954b-95e0d9c740dd", | |
| "runId": "6708ecc6-fad1-426b-8230-a0bd87d19829" | |
| }, | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| } | |
| }, | |
| "attributes": "childWorkflowExecutionStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "8", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 608067741 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_SCHEDULED", | |
| "version": "0", | |
| "taskId": "1048593", | |
| "workflowTaskScheduledEventAttributes": { | |
| "taskQueue": { | |
| "name": "54901@Robs-MacBook-Pro.local:6de5857d-81dd-4358-ac80-08543870b820", | |
| "kind": "TASK_QUEUE_KIND_STICKY" | |
| }, | |
| "startToCloseTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "attempt": 1 | |
| }, | |
| "attributes": "workflowTaskScheduledEventAttributes" | |
| }, | |
| { | |
| "eventId": "9", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 667511087 | |
| }, | |
| "eventType": "EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_STARTED", | |
| "version": "0", | |
| "taskId": "1048597", | |
| "childWorkflowExecutionStartedEventAttributes": { | |
| "namespace": "", | |
| "initiatedEventId": "5", | |
| "workflowExecution": { | |
| "workflowId": "f2ec2875-afca-3cdf-bde3-cd22b24f717a", | |
| "runId": "23c33b24-6912-4a70-bb72-5437d4c16ae8" | |
| }, | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| } | |
| }, | |
| "attributes": "childWorkflowExecutionStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "10", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 701923060 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_STARTED", | |
| "version": "0", | |
| "taskId": "1048599", | |
| "workflowTaskStartedEventAttributes": { | |
| "scheduledEventId": "8", | |
| "identity": "6de5857d-81dd-4358-ac80-08543870b820", | |
| "requestId": "57c65a1a-d17c-40e7-ad30-cf8da4375287" | |
| }, | |
| "attributes": "workflowTaskStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "11", | |
| "eventTime": { | |
| "seconds": "1610737415", | |
| "nanos": 883647915 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048602", | |
| "workflowTaskCompletedEventAttributes": { | |
| "scheduledEventId": "8", | |
| "startedEventId": "10", | |
| "identity": "54901@Robs-MacBook-Pro.local", | |
| "binaryChecksum": "" | |
| }, | |
| "attributes": "workflowTaskCompletedEventAttributes" | |
| }, | |
| { | |
| "eventId": "12", | |
| "eventTime": { | |
| "seconds": "1610737418", | |
| "nanos": 492287414 | |
| }, | |
| "eventType": "EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048604", | |
| "childWorkflowExecutionCompletedEventAttributes": { | |
| "namespace": "", | |
| "workflowExecution": { | |
| "workflowId": "f2ec2875-afca-3cdf-bde3-cd22b24f717a", | |
| "runId": "23c33b24-6912-4a70-bb72-5437d4c16ae8" | |
| }, | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| }, | |
| "initiatedEventId": "5", | |
| "startedEventId": "9" | |
| }, | |
| "attributes": "childWorkflowExecutionCompletedEventAttributes" | |
| }, | |
| { | |
| "eventId": "13", | |
| "eventTime": { | |
| "seconds": "1610737418", | |
| "nanos": 492297361 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_SCHEDULED", | |
| "version": "0", | |
| "taskId": "1048606", | |
| "workflowTaskScheduledEventAttributes": { | |
| "taskQueue": { | |
| "name": "54901@Robs-MacBook-Pro.local:6de5857d-81dd-4358-ac80-08543870b820", | |
| "kind": "TASK_QUEUE_KIND_STICKY" | |
| }, | |
| "startToCloseTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "attempt": 1 | |
| }, | |
| "attributes": "workflowTaskScheduledEventAttributes" | |
| }, | |
| { | |
| "eventId": "14", | |
| "eventTime": { | |
| "seconds": "1610737418", | |
| "nanos": 511157097 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_STARTED", | |
| "version": "0", | |
| "taskId": "1048610", | |
| "workflowTaskStartedEventAttributes": { | |
| "scheduledEventId": "13", | |
| "identity": "6de5857d-81dd-4358-ac80-08543870b820", | |
| "requestId": "5befacc0-6b70-4800-b66a-cb3fb0f6c790" | |
| }, | |
| "attributes": "workflowTaskStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "15", | |
| "eventTime": { | |
| "seconds": "1610737418", | |
| "nanos": 683691758 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048613", | |
| "workflowTaskCompletedEventAttributes": { | |
| "scheduledEventId": "13", | |
| "startedEventId": "14", | |
| "identity": "54901@Robs-MacBook-Pro.local", | |
| "binaryChecksum": "" | |
| }, | |
| "attributes": "workflowTaskCompletedEventAttributes" | |
| }, | |
| { | |
| "eventId": "16", | |
| "eventTime": { | |
| "seconds": "1610737419", | |
| "nanos": 169928759 | |
| }, | |
| "eventType": "EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048615", | |
| "childWorkflowExecutionCompletedEventAttributes": { | |
| "namespace": "", | |
| "workflowExecution": { | |
| "workflowId": "6c02c6b4-9c03-3e90-954b-95e0d9c740dd", | |
| "runId": "6708ecc6-fad1-426b-8230-a0bd87d19829" | |
| }, | |
| "workflowType": { | |
| "name": "RabbitLoadScenarioWorkflow" | |
| }, | |
| "initiatedEventId": "6", | |
| "startedEventId": "7" | |
| }, | |
| "attributes": "childWorkflowExecutionCompletedEventAttributes" | |
| }, | |
| { | |
| "eventId": "17", | |
| "eventTime": { | |
| "seconds": "1610737419", | |
| "nanos": 169938541 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_SCHEDULED", | |
| "version": "0", | |
| "taskId": "1048617", | |
| "workflowTaskScheduledEventAttributes": { | |
| "taskQueue": { | |
| "name": "54901@Robs-MacBook-Pro.local:6de5857d-81dd-4358-ac80-08543870b820", | |
| "kind": "TASK_QUEUE_KIND_STICKY" | |
| }, | |
| "startToCloseTimeout": { | |
| "seconds": "10", | |
| "nanos": 0 | |
| }, | |
| "attempt": 1 | |
| }, | |
| "attributes": "workflowTaskScheduledEventAttributes" | |
| }, | |
| { | |
| "eventId": "18", | |
| "eventTime": { | |
| "seconds": "1610737419", | |
| "nanos": 188749868 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_STARTED", | |
| "version": "0", | |
| "taskId": "1048621", | |
| "workflowTaskStartedEventAttributes": { | |
| "scheduledEventId": "17", | |
| "identity": "6de5857d-81dd-4358-ac80-08543870b820", | |
| "requestId": "ab3989b1-657f-4cab-b0d7-6ae75b785e75" | |
| }, | |
| "attributes": "workflowTaskStartedEventAttributes" | |
| }, | |
| { | |
| "eventId": "19", | |
| "eventTime": { | |
| "seconds": "1610737419", | |
| "nanos": 359953868 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_TASK_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048624", | |
| "workflowTaskCompletedEventAttributes": { | |
| "scheduledEventId": "17", | |
| "startedEventId": "18", | |
| "identity": "54901@Robs-MacBook-Pro.local", | |
| "binaryChecksum": "" | |
| }, | |
| "attributes": "workflowTaskCompletedEventAttributes" | |
| }, | |
| { | |
| "eventId": "20", | |
| "eventTime": { | |
| "seconds": "1610737419", | |
| "nanos": 359996042 | |
| }, | |
| "eventType": "EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED", | |
| "version": "0", | |
| "taskId": "1048625", | |
| "workflowExecutionCompletedEventAttributes": { | |
| "workflowTaskCompletedEventId": "19" | |
| }, | |
| "attributes": "workflowExecutionCompletedEventAttributes" | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment