From fa4e359483571b8e6c5d82bb71f22bd873ec9554 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Wed, 13 Jun 2018 17:00:38 -0700 Subject: [PATCH 1/8] add metric for corrupted signal --- .../com/uber/cadence/internal/metrics/MetricsType.java | 3 +++ .../internal/sync/POJOWorkflowImplementationFactory.java | 8 +++++++- .../uber/cadence/internal/sync/SyncWorkflowWorker.java | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uber/cadence/internal/metrics/MetricsType.java b/src/main/java/com/uber/cadence/internal/metrics/MetricsType.java index 63898aa48..f27c39223 100644 --- a/src/main/java/com/uber/cadence/internal/metrics/MetricsType.java +++ b/src/main/java/com/uber/cadence/internal/metrics/MetricsType.java @@ -121,6 +121,9 @@ public class MetricsType { public static final String UNHANDLED_SIGNALS_COUNTER = CADENCE_METRICS_PREFIX + "unhandled-signals"; + public static final String CORRUPTED_SIGNALS_COUNTER = + CADENCE_METRICS_PREFIX + "corrupted-signals"; + public static final String WORKER_START_COUNTER = CADENCE_METRICS_PREFIX + "worker-start"; public static final String POLLER_START_COUNTER = CADENCE_METRICS_PREFIX + "poller-start"; diff --git a/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java b/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java index 1713a151b..49f24ab27 100644 --- a/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java +++ b/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java @@ -23,6 +23,7 @@ import com.uber.cadence.converter.DataConverterException; import com.uber.cadence.internal.common.CheckedExceptionWrapper; import com.uber.cadence.internal.common.InternalUtils; +import com.uber.cadence.internal.metrics.MetricsType; import com.uber.cadence.internal.replay.ReplayWorkflow; import com.uber.cadence.internal.replay.ReplayWorkflowFactory; import com.uber.cadence.internal.worker.WorkflowExecutionException; @@ -35,6 +36,7 @@ import com.uber.cadence.workflow.WorkflowInfo; import com.uber.cadence.workflow.WorkflowInterceptor; import com.uber.cadence.workflow.WorkflowMethod; +import com.uber.m3.tally.Scope; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collections; @@ -64,14 +66,17 @@ final class POJOWorkflowImplementationFactory implements ReplayWorkflowFactory { Collections.synchronizedMap(new HashMap<>()); private final ExecutorService threadPool; + private final Scope metricsScope; POJOWorkflowImplementationFactory( DataConverter dataConverter, ExecutorService threadPool, - Function interceptorFactory) { + Function interceptorFactory, + Scope metricsScope) { this.dataConverter = Objects.requireNonNull(dataConverter); this.threadPool = Objects.requireNonNull(threadPool); this.interceptorFactory = Objects.requireNonNull(interceptorFactory); + this.metricsScope = metricsScope; } void setWorkflowImplementationTypes(Class[] workflowImplementationTypes) { @@ -295,6 +300,7 @@ public void processSignal(String signalName, byte[] input, long eventId) { + eventId + ". Dropping it.", targetException); + metricsScope.counter(MetricsType.CORRUPTED_SIGNALS_COUNTER).inc(1); } else { throw new Error( "Failure processing \"" + signalName + "\" at eventID " + eventId, targetException); diff --git a/src/main/java/com/uber/cadence/internal/sync/SyncWorkflowWorker.java b/src/main/java/com/uber/cadence/internal/sync/SyncWorkflowWorker.java index 2cb8dd930..312986e39 100644 --- a/src/main/java/com/uber/cadence/internal/sync/SyncWorkflowWorker.java +++ b/src/main/java/com/uber/cadence/internal/sync/SyncWorkflowWorker.java @@ -54,7 +54,10 @@ public SyncWorkflowWorker( new SynchronousQueue<>()); factory = new POJOWorkflowImplementationFactory( - options.getDataConverter(), workflowThreadPool, interceptorFactory); + options.getDataConverter(), + workflowThreadPool, + interceptorFactory, + options.getMetricsScope()); DecisionTaskHandler taskHandler = new ReplayDecisionTaskHandler(domain, factory, options); worker = new WorkflowWorker(service, domain, taskList, options, taskHandler); this.options = options; From a24d9b77d3fddffc04ea7924f945b16bf63ea282 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Tue, 19 Jun 2018 13:26:51 -0700 Subject: [PATCH 2/8] add unit for reporting metrics for corrupted signal --- .../POJOWorkflowImplementationFactory.java | 24 ++-- .../sync/TestWorkflowEnvironmentInternal.java | 17 ++- .../testing/TestWorkflowEnvironment.java | 11 ++ .../uber/cadence/workflow/MetricsTest.java | 41 +++++- ...uptedSignalWorkflowInterceptorFactory.java | 36 +++++ .../SignalWorkflowInterceptor.java | 129 ++++++++++++++++++ .../ReceiveSignalObject_ChildWorkflow.java | 34 +++++ ...ReceiveSignalObject_ChildWorkflowImpl.java | 43 ++++++ .../samples/SendSignalObject_Workflow.java | 26 ++++ .../SendSignalObject_WorkflowImpl.java | 39 ++++++ .../uber/cadence/workflow/samples/Signal.java | 23 ++++ 11 files changed, 405 insertions(+), 18 deletions(-) create mode 100644 src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java create mode 100644 src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java create mode 100644 src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java create mode 100644 src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java create mode 100644 src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java create mode 100644 src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java create mode 100644 src/test/java/com/uber/cadence/workflow/samples/Signal.java diff --git a/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java b/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java index 49f24ab27..29d6b9a85 100644 --- a/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java +++ b/src/main/java/com/uber/cadence/internal/sync/POJOWorkflowImplementationFactory.java @@ -284,23 +284,18 @@ public void processSignal(String signalName, byte[] input, long eventId) { + signalHandlers.keySet()); return; } - Object[] args = dataConverter.fromDataArray(input, signalMethod.getParameterTypes()); try { + Object[] args = dataConverter.fromDataArray(input, signalMethod.getParameterTypes()); newInstance(); signalMethod.invoke(workflow, args); } catch (IllegalAccessException e) { throw new Error("Failure processing \"" + signalName + "\" at eventID " + eventId, e); + } catch (DataConverterException e){ + logSerializationException(signalName, eventId, e); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof DataConverterException) { - log.error( - "Failure deserializing signal input for \"" - + signalName - + "\" at eventID " - + eventId - + ". Dropping it.", - targetException); - metricsScope.counter(MetricsType.CORRUPTED_SIGNALS_COUNTER).inc(1); + logSerializationException(signalName, eventId, (DataConverterException)targetException); } else { throw new Error( "Failure processing \"" + signalName + "\" at eventID " + eventId, targetException); @@ -309,6 +304,17 @@ public void processSignal(String signalName, byte[] input, long eventId) { } } + void logSerializationException(String signalName, Long eventId, DataConverterException exception){ + log.error( + "Failure deserializing signal input for \"" + + signalName + + "\" at eventID " + + eventId + + ". Dropping it.", + exception); + metricsScope.counter(MetricsType.CORRUPTED_SIGNALS_COUNTER).inc(1); + } + static WorkflowExecutionException mapToWorkflowExecutionException( Exception failure, DataConverter dataConverter) { failure = CheckedExceptionWrapper.unwrap(failure); diff --git a/src/main/java/com/uber/cadence/internal/sync/TestWorkflowEnvironmentInternal.java b/src/main/java/com/uber/cadence/internal/sync/TestWorkflowEnvironmentInternal.java index 44c207f36..3f99419d2 100644 --- a/src/main/java/com/uber/cadence/internal/sync/TestWorkflowEnvironmentInternal.java +++ b/src/main/java/com/uber/cadence/internal/sync/TestWorkflowEnvironmentInternal.java @@ -85,6 +85,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.function.Function; import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; import org.slf4j.Logger; @@ -110,16 +111,22 @@ public TestWorkflowEnvironmentInternal(TestEnvironmentOptions options) { @Override public Worker newWorker(String taskList) { + return newWorker(taskList, x->x); + } + + @Override + public Worker newWorker(String taskList, Function overrideOptions) { WorkerOptions.Builder builder = - new WorkerOptions.Builder() - .setInterceptorFactory(testEnvironmentOptions.getInterceptorFactory()) - .setMetricsScope(testEnvironmentOptions.getMetricsScope()) - .setEnableLoggingInReplay(testEnvironmentOptions.isLoggingEnabledInReplay()); + new WorkerOptions.Builder() + .setInterceptorFactory(testEnvironmentOptions.getInterceptorFactory()) + .setMetricsScope(testEnvironmentOptions.getMetricsScope()) + .setEnableLoggingInReplay(testEnvironmentOptions.isLoggingEnabledInReplay()); if (testEnvironmentOptions.getDataConverter() != null) { builder.setDataConverter(testEnvironmentOptions.getDataConverter()); } + builder = overrideOptions.apply(builder); Worker result = - new Worker(service, testEnvironmentOptions.getDomain(), taskList, builder.build()); + new Worker(service, testEnvironmentOptions.getDomain(), taskList, builder.build()); workers.add(result); return result; } diff --git a/src/main/java/com/uber/cadence/testing/TestWorkflowEnvironment.java b/src/main/java/com/uber/cadence/testing/TestWorkflowEnvironment.java index af1f4397b..fb2aa97da 100644 --- a/src/main/java/com/uber/cadence/testing/TestWorkflowEnvironment.java +++ b/src/main/java/com/uber/cadence/testing/TestWorkflowEnvironment.java @@ -23,7 +23,9 @@ import com.uber.cadence.internal.sync.TestWorkflowEnvironmentInternal; import com.uber.cadence.serviceclient.IWorkflowService; import com.uber.cadence.worker.Worker; +import com.uber.cadence.worker.WorkerOptions; import java.time.Duration; +import java.util.function.Function; /** * TestWorkflowEnvironment provides workflow unit testing capabilities. @@ -104,6 +106,15 @@ static TestWorkflowEnvironment newInstance(TestEnvironmentOptions options) { */ Worker newWorker(String taskList); + /** + * Creates a new Worker instance that is connected to the in-memory test Cadence service. {@link + * #close()} calls {@link Worker#shutdown(Duration)} for all workers created through this method. + * + * @param taskList task list to poll. + * @param overrideOptions is used to override the default worker options. + */ + Worker newWorker(String taskList, Function overrideOptions); + /** Creates a WorkflowClient that is connected to the in-memory test Cadence service. */ WorkflowClient newWorkflowClient(); diff --git a/src/test/java/com/uber/cadence/workflow/MetricsTest.java b/src/test/java/com/uber/cadence/workflow/MetricsTest.java index d58a52ec6..d8f96b478 100644 --- a/src/test/java/com/uber/cadence/workflow/MetricsTest.java +++ b/src/test/java/com/uber/cadence/workflow/MetricsTest.java @@ -20,17 +20,20 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import com.uber.cadence.client.WorkflowClient; import com.uber.cadence.client.WorkflowOptions; import com.uber.cadence.internal.metrics.MetricsTag; +import com.uber.cadence.internal.metrics.MetricsType; import com.uber.cadence.testing.TestEnvironmentOptions; import com.uber.cadence.testing.TestEnvironmentOptions.Builder; import com.uber.cadence.testing.TestWorkflowEnvironment; import com.uber.cadence.worker.Worker; +import com.uber.cadence.workflow.interceptors.CorruptedSignalWorkflowInterceptorFactory; +import com.uber.cadence.workflow.samples.ReceiveSignalObject_ChildWorkflowImpl; +import com.uber.cadence.workflow.samples.SendSignalObject_Workflow; +import com.uber.cadence.workflow.samples.SendSignalObject_WorkflowImpl; import com.uber.m3.tally.RootScopeBuilder; import com.uber.m3.tally.Scope; import com.uber.m3.tally.StatsReporter; @@ -109,7 +112,7 @@ public void setUp() { Scope scope = new RootScopeBuilder() .reporter(reporter) - .reportEvery(com.uber.m3.util.Duration.ofMillis(10)); + .reportEvery(com.uber.m3.util.Duration.ofMillis(300)); TestEnvironmentOptions testOptions = new Builder().setDomain(WorkflowTest.DOMAIN).setMetricsScope(scope).build(); @@ -158,4 +161,34 @@ public void testWorkflowMetrics() throws InterruptedException { sleepDuration.toString(), sleepDuration.compareTo(com.uber.m3.util.Duration.ofMillis(3100)) < 0); } + + @Test + public void testCorruptedSignalMetrics() throws InterruptedException { + Worker worker = testEnvironment.newWorker(taskList, builder -> + builder.setInterceptorFactory(new CorruptedSignalWorkflowInterceptorFactory())); + + worker.registerWorkflowImplementationTypes( + SendSignalObject_WorkflowImpl.class, ReceiveSignalObject_ChildWorkflowImpl.class); + worker.start(); + + WorkflowOptions options = + new WorkflowOptions.Builder() + .setExecutionStartToCloseTimeout(Duration.ofSeconds(1000)) + .setTaskList(taskList) + .build(); + + WorkflowClient workflowClient = testEnvironment.newWorkflowClient(); + SendSignalObject_Workflow workflow = workflowClient.newWorkflowStub(SendSignalObject_Workflow.class, options); + workflow.execute(); + + //Wait for reporter + Thread.sleep(500); + + Map tags = + new ImmutableMap.Builder(2) + .put(MetricsTag.DOMAIN, WorkflowTest.DOMAIN) + .put(MetricsTag.TASK_LIST, taskList) + .build(); + verify(reporter, times(1)).reportCounter(MetricsType.CORRUPTED_SIGNALS_COUNTER, tags, 2); + } } diff --git a/src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java b/src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java new file mode 100644 index 000000000..8b80770d0 --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.interceptors; + +import com.uber.cadence.workflow.WorkflowInterceptor; + +import java.util.function.Function; + +public class CorruptedSignalWorkflowInterceptorFactory + implements Function { + + @Override + public WorkflowInterceptor apply(WorkflowInterceptor next) { + return new SignalWorkflowInterceptor( args -> { + if(args != null && args.length > 0){ + return new Object [] {"Corrupted Signal"}; + } + return args; + }, sig->sig, next); + } +} diff --git a/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java b/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java new file mode 100644 index 000000000..ed36ebaff --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java @@ -0,0 +1,129 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.interceptors; + +import com.uber.cadence.WorkflowExecution; +import com.uber.cadence.activity.ActivityOptions; +import com.uber.cadence.workflow.*; +import java.time.Duration; +import java.util.Objects; +import java.util.Optional; +import java.util.Random; +import java.util.UUID; +import java.util.function.BiPredicate; +import java.util.function.Function; +import java.util.function.Supplier; + +public class SignalWorkflowInterceptor implements WorkflowInterceptor { + + private Function overrideArgs; + private Function overrideSignalName; + private final WorkflowInterceptor next; + + public SignalWorkflowInterceptor(Function overrideArgs, + Function overrideSignalName, + WorkflowInterceptor next) { + this.overrideArgs = overrideArgs; + this.overrideSignalName = overrideSignalName; + this.next = Objects.requireNonNull(next); + } + + @Override + public Promise executeActivity( + String activityName, Class returnType, Object[] args, ActivityOptions options) { + return next.executeActivity(activityName, returnType, args, options); + } + + @Override + public WorkflowResult executeChildWorkflow( + String workflowType, Class returnType, Object[] args, ChildWorkflowOptions options) { + return next.executeChildWorkflow(workflowType, returnType, args, options); + } + + @Override + public Random newRandom() { + return next.newRandom(); + } + + @Override + public Promise signalExternalWorkflow( + WorkflowExecution execution, String signalName, Object[] args) { + if(args != null && args.length > 0){ + args = new Object[] {"corrupted signal"}; + } + return next.signalExternalWorkflow(execution, overrideSignalName.apply(signalName), overrideArgs.apply(args)); + } + + @Override + public Promise cancelWorkflow(WorkflowExecution execution) { + return next.cancelWorkflow(execution); + } + + @Override + public void sleep(Duration duration) { + next.sleep(duration); + } + + @Override + public boolean await(Duration timeout, String reason, Supplier unblockCondition) { + return next.await(timeout, reason, unblockCondition); + } + + @Override + public void await(String reason, Supplier unblockCondition) { + next.await(reason, unblockCondition); + } + + @Override + public Promise newTimer(Duration duration) { + return next.newTimer(duration); + } + + @Override + public R sideEffect(Class resultType, Functions.Func func) { + return next.sideEffect(resultType, func); + } + + @Override + public R mutableSideEffect( + String id, Class returnType, BiPredicate updated, Functions.Func func) { + return next.mutableSideEffect(id, returnType, updated, func); + } + + @Override + public int getVersion(String changeID, int minSupported, int maxSupported) { + return next.getVersion(changeID, minSupported, maxSupported); + } + + @Override + public void continueAsNew( + Optional workflowType, Optional options, Object[] args) { + next.continueAsNew(workflowType, options, args); + } + + @Override + public void registerQuery( + String queryType, Class[] argTypes, Functions.Func1 callback) { + next.registerQuery(queryType, argTypes, callback); + } + + @Override + public UUID randomUUID() { + return next.randomUUID(); + } +} diff --git a/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java b/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java new file mode 100644 index 000000000..9a7399e5e --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.samples; + +import com.uber.cadence.workflow.SignalMethod; +import com.uber.cadence.workflow.WorkflowMethod; +import com.uber.cadence.workflow.samples.Signal; + +public interface ReceiveSignalObject_ChildWorkflow { + + @WorkflowMethod + String execute(); + + @SignalMethod(name = "testSignal") + void signal(Signal arg); + + @SignalMethod(name = "endWorkflow") + void close(); +} diff --git a/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java b/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java new file mode 100644 index 000000000..d0448b038 --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.samples; + +import com.uber.cadence.workflow.CompletablePromise; +import com.uber.cadence.workflow.Workflow; +import com.uber.cadence.workflow.WorkflowTest; + +public class ReceiveSignalObject_ChildWorkflowImpl implements ReceiveSignalObject_ChildWorkflow { + private String receivedSignal = "Initial State"; + // Keep workflow open so that we can send signal + CompletablePromise promise = Workflow.newPromise(); + @Override + public String execute() { + promise.get(); + return receivedSignal; + } + + @Override + public void signal(Signal arg) { + receivedSignal = arg.value; + } + + @Override + public void close() { + promise.complete(null); + } + } diff --git a/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java b/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java new file mode 100644 index 000000000..e87f01445 --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.samples; + +import com.uber.cadence.workflow.WorkflowMethod; + +public interface SendSignalObject_Workflow { + + @WorkflowMethod + String execute(); +} diff --git a/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java b/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java new file mode 100644 index 000000000..16e36ac33 --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.samples; + +import com.uber.cadence.workflow.Async; +import com.uber.cadence.workflow.Promise; +import com.uber.cadence.workflow.Workflow; +import com.uber.cadence.workflow.samples.ReceiveSignalObject_ChildWorkflow; +import com.uber.cadence.workflow.samples.SendSignalObject_Workflow; +import com.uber.cadence.workflow.samples.Signal; + +public class SendSignalObject_WorkflowImpl implements SendSignalObject_Workflow { + @Override + public String execute() { + ReceiveSignalObject_ChildWorkflow child = + Workflow.newChildWorkflowStub(ReceiveSignalObject_ChildWorkflow.class); + Promise greeting = Async.function(child::execute); + Signal sig = new Signal(); + sig.value = "Hello World"; + child.signal(sig); + child.close(); + return greeting.get(); + } +} diff --git a/src/test/java/com/uber/cadence/workflow/samples/Signal.java b/src/test/java/com/uber/cadence/workflow/samples/Signal.java new file mode 100644 index 000000000..608f3d7c2 --- /dev/null +++ b/src/test/java/com/uber/cadence/workflow/samples/Signal.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.samples; + +public class Signal { + + public String value; +} From 8ef8e5933927f0a604064ba6bd41ebd2a88b5c63 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Tue, 19 Jun 2018 13:36:34 -0700 Subject: [PATCH 3/8] fix errors --- .../SignalWorkflowInterceptor.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java b/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java index ed36ebaff..d3570aca0 100644 --- a/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java +++ b/src/test/java/com/uber/cadence/workflow/interceptors/SignalWorkflowInterceptor.java @@ -20,6 +20,8 @@ import com.uber.cadence.WorkflowExecution; import com.uber.cadence.activity.ActivityOptions; import com.uber.cadence.workflow.*; + +import java.lang.reflect.Type; import java.time.Duration; import java.util.Objects; import java.util.Optional; @@ -35,8 +37,8 @@ public class SignalWorkflowInterceptor implements WorkflowInterceptor { private Function overrideSignalName; private final WorkflowInterceptor next; - public SignalWorkflowInterceptor(Function overrideArgs, - Function overrideSignalName, + public SignalWorkflowInterceptor(Function overrideArgs, + Function overrideSignalName, WorkflowInterceptor next) { this.overrideArgs = overrideArgs; this.overrideSignalName = overrideSignalName; @@ -44,15 +46,13 @@ public SignalWorkflowInterceptor(Function overrideArgs, } @Override - public Promise executeActivity( - String activityName, Class returnType, Object[] args, ActivityOptions options) { - return next.executeActivity(activityName, returnType, args, options); + public Promise executeActivity(String activityName, Class resultClass, Type resultType, Object[] args, ActivityOptions options) { + return next.executeActivity(activityName, resultClass, resultType, args, options); } @Override - public WorkflowResult executeChildWorkflow( - String workflowType, Class returnType, Object[] args, ChildWorkflowOptions options) { - return next.executeChildWorkflow(workflowType, returnType, args, options); + public WorkflowResult executeChildWorkflow(String workflowType, Class resultClass, Type resultType, Object[] args, ChildWorkflowOptions options) { + return next.executeChildWorkflow(workflowType, resultClass, resultType, args, options); } @Override @@ -63,8 +63,8 @@ public Random newRandom() { @Override public Promise signalExternalWorkflow( WorkflowExecution execution, String signalName, Object[] args) { - if(args != null && args.length > 0){ - args = new Object[] {"corrupted signal"}; + if (args != null && args.length > 0) { + args = new Object[]{"corrupted signal"}; } return next.signalExternalWorkflow(execution, overrideSignalName.apply(signalName), overrideArgs.apply(args)); } @@ -95,14 +95,13 @@ public Promise newTimer(Duration duration) { } @Override - public R sideEffect(Class resultType, Functions.Func func) { - return next.sideEffect(resultType, func); + public R sideEffect(Class resultClass, Type resultType, Functions.Func func) { + return next.sideEffect(resultClass, resultType, func); } @Override - public R mutableSideEffect( - String id, Class returnType, BiPredicate updated, Functions.Func func) { - return next.mutableSideEffect(id, returnType, updated, func); + public R mutableSideEffect(String id, Class resultClass, Type resultType, BiPredicate updated, Functions.Func func) { + return null; } @Override @@ -117,8 +116,7 @@ public void continueAsNew( } @Override - public void registerQuery( - String queryType, Class[] argTypes, Functions.Func1 callback) { + public void registerQuery(String queryType, Type[] argTypes, Functions.Func1 callback) { next.registerQuery(queryType, argTypes, callback); } From 81035dd3dd786f9d6a46efa874b7bf7d0e5b1b67 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Tue, 19 Jun 2018 16:37:53 -0700 Subject: [PATCH 4/8] rename samples package --- .../uber/cadence/workflow/MetricsTest.java | 24 ++++++++++--- ...uptedSignalWorkflowInterceptorFactory.java | 36 ------------------- .../ReceiveSignalObject_ChildWorkflow.java | 3 +- ...ReceiveSignalObject_ChildWorkflowImpl.java | 3 +- .../SendSignalObject_Workflow.java | 2 +- .../SendSignalObject_WorkflowImpl.java | 5 +-- .../{samples => workflows}/Signal.java | 2 +- 7 files changed, 25 insertions(+), 50 deletions(-) delete mode 100644 src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java rename src/test/java/com/uber/cadence/workflow/{samples => workflows}/ReceiveSignalObject_ChildWorkflow.java (91%) rename src/test/java/com/uber/cadence/workflow/{samples => workflows}/ReceiveSignalObject_ChildWorkflowImpl.java (93%) rename src/test/java/com/uber/cadence/workflow/{samples => workflows}/SendSignalObject_Workflow.java (94%) rename src/test/java/com/uber/cadence/workflow/{samples => workflows}/SendSignalObject_WorkflowImpl.java (84%) rename src/test/java/com/uber/cadence/workflow/{samples => workflows}/Signal.java (94%) diff --git a/src/test/java/com/uber/cadence/workflow/MetricsTest.java b/src/test/java/com/uber/cadence/workflow/MetricsTest.java index d8f96b478..13dfc7f09 100644 --- a/src/test/java/com/uber/cadence/workflow/MetricsTest.java +++ b/src/test/java/com/uber/cadence/workflow/MetricsTest.java @@ -30,10 +30,10 @@ import com.uber.cadence.testing.TestEnvironmentOptions.Builder; import com.uber.cadence.testing.TestWorkflowEnvironment; import com.uber.cadence.worker.Worker; -import com.uber.cadence.workflow.interceptors.CorruptedSignalWorkflowInterceptorFactory; -import com.uber.cadence.workflow.samples.ReceiveSignalObject_ChildWorkflowImpl; -import com.uber.cadence.workflow.samples.SendSignalObject_Workflow; -import com.uber.cadence.workflow.samples.SendSignalObject_WorkflowImpl; +import com.uber.cadence.workflow.interceptors.SignalWorkflowInterceptor; +import com.uber.cadence.workflow.workflows.ReceiveSignalObject_ChildWorkflowImpl; +import com.uber.cadence.workflow.workflows.SendSignalObject_Workflow; +import com.uber.cadence.workflow.workflows.SendSignalObject_WorkflowImpl; import com.uber.m3.tally.RootScopeBuilder; import com.uber.m3.tally.Scope; import com.uber.m3.tally.StatsReporter; @@ -41,6 +41,8 @@ import com.uber.m3.util.ImmutableMap; import java.time.Duration; import java.util.Map; +import java.util.function.Function; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -191,4 +193,18 @@ public void testCorruptedSignalMetrics() throws InterruptedException { .build(); verify(reporter, times(1)).reportCounter(MetricsType.CORRUPTED_SIGNALS_COUNTER, tags, 2); } + + private static class CorruptedSignalWorkflowInterceptorFactory + implements Function { + + @Override + public WorkflowInterceptor apply(WorkflowInterceptor next) { + return new SignalWorkflowInterceptor(args -> { + if(args != null && args.length > 0){ + return new Object [] {"Corrupted Signal"}; + } + return args; + }, sig->sig, next); + } + } } diff --git a/src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java b/src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java deleted file mode 100644 index 8b80770d0..000000000 --- a/src/test/java/com/uber/cadence/workflow/interceptors/CorruptedSignalWorkflowInterceptorFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.interceptors; - -import com.uber.cadence.workflow.WorkflowInterceptor; - -import java.util.function.Function; - -public class CorruptedSignalWorkflowInterceptorFactory - implements Function { - - @Override - public WorkflowInterceptor apply(WorkflowInterceptor next) { - return new SignalWorkflowInterceptor( args -> { - if(args != null && args.length > 0){ - return new Object [] {"Corrupted Signal"}; - } - return args; - }, sig->sig, next); - } -} diff --git a/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java b/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java similarity index 91% rename from src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java rename to src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java index 9a7399e5e..9c5bdf3d3 100644 --- a/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflow.java +++ b/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java @@ -15,11 +15,10 @@ * permissions and limitations under the License. */ -package com.uber.cadence.workflow.samples; +package com.uber.cadence.workflow.workflows; import com.uber.cadence.workflow.SignalMethod; import com.uber.cadence.workflow.WorkflowMethod; -import com.uber.cadence.workflow.samples.Signal; public interface ReceiveSignalObject_ChildWorkflow { diff --git a/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java b/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java similarity index 93% rename from src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java rename to src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java index d0448b038..534f39716 100644 --- a/src/test/java/com/uber/cadence/workflow/samples/ReceiveSignalObject_ChildWorkflowImpl.java +++ b/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java @@ -15,11 +15,10 @@ * permissions and limitations under the License. */ -package com.uber.cadence.workflow.samples; +package com.uber.cadence.workflow.workflows; import com.uber.cadence.workflow.CompletablePromise; import com.uber.cadence.workflow.Workflow; -import com.uber.cadence.workflow.WorkflowTest; public class ReceiveSignalObject_ChildWorkflowImpl implements ReceiveSignalObject_ChildWorkflow { private String receivedSignal = "Initial State"; diff --git a/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java b/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java similarity index 94% rename from src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java rename to src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java index e87f01445..0251b9336 100644 --- a/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_Workflow.java +++ b/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java @@ -15,7 +15,7 @@ * permissions and limitations under the License. */ -package com.uber.cadence.workflow.samples; +package com.uber.cadence.workflow.workflows; import com.uber.cadence.workflow.WorkflowMethod; diff --git a/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java b/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java similarity index 84% rename from src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java rename to src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java index 16e36ac33..3902d7ab0 100644 --- a/src/test/java/com/uber/cadence/workflow/samples/SendSignalObject_WorkflowImpl.java +++ b/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java @@ -15,14 +15,11 @@ * permissions and limitations under the License. */ -package com.uber.cadence.workflow.samples; +package com.uber.cadence.workflow.workflows; import com.uber.cadence.workflow.Async; import com.uber.cadence.workflow.Promise; import com.uber.cadence.workflow.Workflow; -import com.uber.cadence.workflow.samples.ReceiveSignalObject_ChildWorkflow; -import com.uber.cadence.workflow.samples.SendSignalObject_Workflow; -import com.uber.cadence.workflow.samples.Signal; public class SendSignalObject_WorkflowImpl implements SendSignalObject_Workflow { @Override diff --git a/src/test/java/com/uber/cadence/workflow/samples/Signal.java b/src/test/java/com/uber/cadence/workflow/workflows/Signal.java similarity index 94% rename from src/test/java/com/uber/cadence/workflow/samples/Signal.java rename to src/test/java/com/uber/cadence/workflow/workflows/Signal.java index 608f3d7c2..a27a691b7 100644 --- a/src/test/java/com/uber/cadence/workflow/samples/Signal.java +++ b/src/test/java/com/uber/cadence/workflow/workflows/Signal.java @@ -15,7 +15,7 @@ * permissions and limitations under the License. */ -package com.uber.cadence.workflow.samples; +package com.uber.cadence.workflow.workflows; public class Signal { From 48f1b9b21126524724660af44971cb023df4a4d7 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Tue, 26 Jun 2018 11:48:22 -0700 Subject: [PATCH 5/8] parametrize test environment setup --- .../com/uber/cadence/workflow/MetricsTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/uber/cadence/workflow/MetricsTest.java b/src/test/java/com/uber/cadence/workflow/MetricsTest.java index 13dfc7f09..8e98d4995 100644 --- a/src/test/java/com/uber/cadence/workflow/MetricsTest.java +++ b/src/test/java/com/uber/cadence/workflow/MetricsTest.java @@ -108,21 +108,21 @@ public void executeChild() { } } - @Before - public void setUp() { + public void setUp(com.uber.m3.util.Duration reportingFrequecy){ reporter = mock(StatsReporter.class); Scope scope = - new RootScopeBuilder() - .reporter(reporter) - .reportEvery(com.uber.m3.util.Duration.ofMillis(300)); + new RootScopeBuilder() + .reporter(reporter) + .reportEvery(reportingFrequecy); TestEnvironmentOptions testOptions = - new Builder().setDomain(WorkflowTest.DOMAIN).setMetricsScope(scope).build(); + new Builder().setDomain(WorkflowTest.DOMAIN).setMetricsScope(scope).build(); testEnvironment = TestWorkflowEnvironment.newInstance(testOptions); } @Test public void testWorkflowMetrics() throws InterruptedException { + setUp(com.uber.m3.util.Duration.ofMillis(10)); Worker worker = testEnvironment.newWorker(taskList); worker.registerWorkflowImplementationTypes( @@ -166,6 +166,8 @@ public void testWorkflowMetrics() throws InterruptedException { @Test public void testCorruptedSignalMetrics() throws InterruptedException { + setUp(com.uber.m3.util.Duration.ofMillis(300)); + Worker worker = testEnvironment.newWorker(taskList, builder -> builder.setInterceptorFactory(new CorruptedSignalWorkflowInterceptorFactory())); From e2e26ffda729e2d2f70f8d49408b346895f3874b Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Wed, 27 Jun 2018 13:50:36 -0700 Subject: [PATCH 6/8] move classes into test class --- .../uber/cadence/workflow/MetricsTest.java | 62 +++++++++++++++++-- .../ReceiveSignalObject_ChildWorkflow.java | 33 ---------- ...ReceiveSignalObject_ChildWorkflowImpl.java | 42 ------------- .../workflows/SendSignalObject_Workflow.java | 26 -------- .../SendSignalObject_WorkflowImpl.java | 36 ----------- .../cadence/workflow/workflows/Signal.java | 23 ------- 6 files changed, 58 insertions(+), 164 deletions(-) delete mode 100644 src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java delete mode 100644 src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java delete mode 100644 src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java delete mode 100644 src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java delete mode 100644 src/test/java/com/uber/cadence/workflow/workflows/Signal.java diff --git a/src/test/java/com/uber/cadence/workflow/MetricsTest.java b/src/test/java/com/uber/cadence/workflow/MetricsTest.java index 8e98d4995..28cbf117b 100644 --- a/src/test/java/com/uber/cadence/workflow/MetricsTest.java +++ b/src/test/java/com/uber/cadence/workflow/MetricsTest.java @@ -31,9 +31,6 @@ import com.uber.cadence.testing.TestWorkflowEnvironment; import com.uber.cadence.worker.Worker; import com.uber.cadence.workflow.interceptors.SignalWorkflowInterceptor; -import com.uber.cadence.workflow.workflows.ReceiveSignalObject_ChildWorkflowImpl; -import com.uber.cadence.workflow.workflows.SendSignalObject_Workflow; -import com.uber.cadence.workflow.workflows.SendSignalObject_WorkflowImpl; import com.uber.m3.tally.RootScopeBuilder; import com.uber.m3.tally.Scope; import com.uber.m3.tally.StatsReporter; @@ -43,7 +40,6 @@ import java.util.Map; import java.util.function.Function; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestWatcher; @@ -108,6 +104,64 @@ public void executeChild() { } } + public interface ReceiveSignalObject_ChildWorkflow { + + @WorkflowMethod + String execute(); + + @SignalMethod(name = "testSignal") + void signal(Signal arg); + + @SignalMethod(name = "endWorkflow") + void close(); + } + + public static class ReceiveSignalObject_ChildWorkflowImpl implements ReceiveSignalObject_ChildWorkflow { + private String receivedSignal = "Initial State"; + // Keep workflow open so that we can send signal + CompletablePromise promise = Workflow.newPromise(); + @Override + public String execute() { + promise.get(); + return receivedSignal; + } + + @Override + public void signal(Signal arg) { + receivedSignal = arg.value; + } + + @Override + public void close() { + promise.complete(null); + } + } + + public interface SendSignalObject_Workflow { + + @WorkflowMethod + String execute(); + } + + public static class SendSignalObject_WorkflowImpl implements SendSignalObject_Workflow { + @Override + public String execute() { + ReceiveSignalObject_ChildWorkflow child = + Workflow.newChildWorkflowStub(ReceiveSignalObject_ChildWorkflow.class); + Promise greeting = Async.function(child::execute); + Signal sig = new Signal(); + sig.value = "Hello World"; + child.signal(sig); + child.close(); + return greeting.get(); + } + } + + public static class Signal { + + public String value; + } + public void setUp(com.uber.m3.util.Duration reportingFrequecy){ reporter = mock(StatsReporter.class); Scope scope = diff --git a/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java b/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java deleted file mode 100644 index 9c5bdf3d3..000000000 --- a/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflow.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.workflows; - -import com.uber.cadence.workflow.SignalMethod; -import com.uber.cadence.workflow.WorkflowMethod; - -public interface ReceiveSignalObject_ChildWorkflow { - - @WorkflowMethod - String execute(); - - @SignalMethod(name = "testSignal") - void signal(Signal arg); - - @SignalMethod(name = "endWorkflow") - void close(); -} diff --git a/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java b/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java deleted file mode 100644 index 534f39716..000000000 --- a/src/test/java/com/uber/cadence/workflow/workflows/ReceiveSignalObject_ChildWorkflowImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.workflows; - -import com.uber.cadence.workflow.CompletablePromise; -import com.uber.cadence.workflow.Workflow; - -public class ReceiveSignalObject_ChildWorkflowImpl implements ReceiveSignalObject_ChildWorkflow { - private String receivedSignal = "Initial State"; - // Keep workflow open so that we can send signal - CompletablePromise promise = Workflow.newPromise(); - @Override - public String execute() { - promise.get(); - return receivedSignal; - } - - @Override - public void signal(Signal arg) { - receivedSignal = arg.value; - } - - @Override - public void close() { - promise.complete(null); - } - } diff --git a/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java b/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java deleted file mode 100644 index 0251b9336..000000000 --- a/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_Workflow.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.workflows; - -import com.uber.cadence.workflow.WorkflowMethod; - -public interface SendSignalObject_Workflow { - - @WorkflowMethod - String execute(); -} diff --git a/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java b/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java deleted file mode 100644 index 3902d7ab0..000000000 --- a/src/test/java/com/uber/cadence/workflow/workflows/SendSignalObject_WorkflowImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.workflows; - -import com.uber.cadence.workflow.Async; -import com.uber.cadence.workflow.Promise; -import com.uber.cadence.workflow.Workflow; - -public class SendSignalObject_WorkflowImpl implements SendSignalObject_Workflow { - @Override - public String execute() { - ReceiveSignalObject_ChildWorkflow child = - Workflow.newChildWorkflowStub(ReceiveSignalObject_ChildWorkflow.class); - Promise greeting = Async.function(child::execute); - Signal sig = new Signal(); - sig.value = "Hello World"; - child.signal(sig); - child.close(); - return greeting.get(); - } -} diff --git a/src/test/java/com/uber/cadence/workflow/workflows/Signal.java b/src/test/java/com/uber/cadence/workflow/workflows/Signal.java deleted file mode 100644 index a27a691b7..000000000 --- a/src/test/java/com/uber/cadence/workflow/workflows/Signal.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file 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.uber.cadence.workflow.workflows; - -public class Signal { - - public String value; -} From 75ba76bd03d33561e007ed6bad6cad938b84bf38 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Wed, 27 Jun 2018 17:15:02 -0700 Subject: [PATCH 7/8] remvoe underscoreds --- .../com/uber/cadence/workflow/MetricsTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/uber/cadence/workflow/MetricsTest.java b/src/test/java/com/uber/cadence/workflow/MetricsTest.java index 28cbf117b..65c155b84 100644 --- a/src/test/java/com/uber/cadence/workflow/MetricsTest.java +++ b/src/test/java/com/uber/cadence/workflow/MetricsTest.java @@ -104,7 +104,7 @@ public void executeChild() { } } - public interface ReceiveSignalObject_ChildWorkflow { + public interface ReceiveSignalObjectChildWorkflow { @WorkflowMethod String execute(); @@ -116,7 +116,7 @@ public interface ReceiveSignalObject_ChildWorkflow { void close(); } - public static class ReceiveSignalObject_ChildWorkflowImpl implements ReceiveSignalObject_ChildWorkflow { + public static class ReceiveSignalObjectChildWorkflowImpl implements ReceiveSignalObjectChildWorkflow { private String receivedSignal = "Initial State"; // Keep workflow open so that we can send signal CompletablePromise promise = Workflow.newPromise(); @@ -137,17 +137,17 @@ public void close() { } } - public interface SendSignalObject_Workflow { + public interface SendSignalObjectWorkflow { @WorkflowMethod String execute(); } - public static class SendSignalObject_WorkflowImpl implements SendSignalObject_Workflow { + public static class SendSignalObjectWorkflowImpl implements SendSignalObjectWorkflow { @Override public String execute() { - ReceiveSignalObject_ChildWorkflow child = - Workflow.newChildWorkflowStub(ReceiveSignalObject_ChildWorkflow.class); + ReceiveSignalObjectChildWorkflow child = + Workflow.newChildWorkflowStub(ReceiveSignalObjectChildWorkflow.class); Promise greeting = Async.function(child::execute); Signal sig = new Signal(); sig.value = "Hello World"; @@ -226,7 +226,7 @@ public void testCorruptedSignalMetrics() throws InterruptedException { builder.setInterceptorFactory(new CorruptedSignalWorkflowInterceptorFactory())); worker.registerWorkflowImplementationTypes( - SendSignalObject_WorkflowImpl.class, ReceiveSignalObject_ChildWorkflowImpl.class); + SendSignalObjectWorkflowImpl.class, ReceiveSignalObjectChildWorkflowImpl.class); worker.start(); WorkflowOptions options = @@ -236,7 +236,7 @@ public void testCorruptedSignalMetrics() throws InterruptedException { .build(); WorkflowClient workflowClient = testEnvironment.newWorkflowClient(); - SendSignalObject_Workflow workflow = workflowClient.newWorkflowStub(SendSignalObject_Workflow.class, options); + SendSignalObjectWorkflow workflow = workflowClient.newWorkflowStub(SendSignalObjectWorkflow.class, options); workflow.execute(); //Wait for reporter From 03077235fde4bc7eb3adaaf1bc2c0d56d01d0d60 Mon Sep 17 00:00:00 2001 From: Hala Karaki Date: Thu, 28 Jun 2018 15:49:44 -0700 Subject: [PATCH 8/8] retrigger build --- src/test/java/com/uber/cadence/workflow/MetricsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/uber/cadence/workflow/MetricsTest.java b/src/test/java/com/uber/cadence/workflow/MetricsTest.java index 65c155b84..3dc3703b9 100644 --- a/src/test/java/com/uber/cadence/workflow/MetricsTest.java +++ b/src/test/java/com/uber/cadence/workflow/MetricsTest.java @@ -240,7 +240,7 @@ public void testCorruptedSignalMetrics() throws InterruptedException { workflow.execute(); //Wait for reporter - Thread.sleep(500); + Thread.sleep(600); Map tags = new ImmutableMap.Builder(2)