3939import java .time .Duration ;
4040import java .util .Map ;
4141import java .util .function .Function ;
42-
4342import org .junit .Rule ;
4443import org .junit .Test ;
4544import org .junit .rules .TestWatcher ;
@@ -116,10 +115,12 @@ public interface ReceiveSignalObjectChildWorkflow {
116115 void close ();
117116 }
118117
119- public static class ReceiveSignalObjectChildWorkflowImpl implements ReceiveSignalObjectChildWorkflow {
118+ public static class ReceiveSignalObjectChildWorkflowImpl
119+ implements ReceiveSignalObjectChildWorkflow {
120120 private String receivedSignal = "Initial State" ;
121121 // Keep workflow open so that we can send signal
122122 CompletablePromise <Void > promise = Workflow .newPromise ();
123+
123124 @ Override
124125 public String execute () {
125126 promise .get ();
@@ -147,7 +148,7 @@ public static class SendSignalObjectWorkflowImpl implements SendSignalObjectWork
147148 @ Override
148149 public String execute () {
149150 ReceiveSignalObjectChildWorkflow child =
150- Workflow .newChildWorkflowStub (ReceiveSignalObjectChildWorkflow .class );
151+ Workflow .newChildWorkflowStub (ReceiveSignalObjectChildWorkflow .class );
151152 Promise <String > greeting = Async .function (child ::execute );
152153 Signal sig = new Signal ();
153154 sig .value = "Hello World" ;
@@ -162,15 +163,12 @@ public static class Signal {
162163 public String value ;
163164 }
164165
165- public void setUp (com .uber .m3 .util .Duration reportingFrequecy ){
166+ public void setUp (com .uber .m3 .util .Duration reportingFrequecy ) {
166167 reporter = mock (StatsReporter .class );
167- Scope scope =
168- new RootScopeBuilder ()
169- .reporter (reporter )
170- .reportEvery (reportingFrequecy );
168+ Scope scope = new RootScopeBuilder ().reporter (reporter ).reportEvery (reportingFrequecy );
171169
172170 TestEnvironmentOptions testOptions =
173- new Builder ().setDomain (WorkflowTest .DOMAIN ).setMetricsScope (scope ).build ();
171+ new Builder ().setDomain (WorkflowTest .DOMAIN ).setMetricsScope (scope ).build ();
174172 testEnvironment = TestWorkflowEnvironment .newInstance (testOptions );
175173 }
176174
@@ -222,45 +220,52 @@ public void testWorkflowMetrics() throws InterruptedException {
222220 public void testCorruptedSignalMetrics () throws InterruptedException {
223221 setUp (com .uber .m3 .util .Duration .ofMillis (300 ));
224222
225- Worker worker = testEnvironment .newWorker (taskList , builder ->
226- builder .setInterceptorFactory (new CorruptedSignalWorkflowInterceptorFactory ()));
223+ Worker worker =
224+ testEnvironment .newWorker (
225+ taskList ,
226+ builder ->
227+ builder .setInterceptorFactory (new CorruptedSignalWorkflowInterceptorFactory ()));
227228
228229 worker .registerWorkflowImplementationTypes (
229- SendSignalObjectWorkflowImpl .class , ReceiveSignalObjectChildWorkflowImpl .class );
230+ SendSignalObjectWorkflowImpl .class , ReceiveSignalObjectChildWorkflowImpl .class );
230231 worker .start ();
231232
232233 WorkflowOptions options =
233- new WorkflowOptions .Builder ()
234- .setExecutionStartToCloseTimeout (Duration .ofSeconds (1000 ))
235- .setTaskList (taskList )
236- .build ();
234+ new WorkflowOptions .Builder ()
235+ .setExecutionStartToCloseTimeout (Duration .ofSeconds (1000 ))
236+ .setTaskList (taskList )
237+ .build ();
237238
238239 WorkflowClient workflowClient = testEnvironment .newWorkflowClient ();
239- SendSignalObjectWorkflow workflow = workflowClient .newWorkflowStub (SendSignalObjectWorkflow .class , options );
240+ SendSignalObjectWorkflow workflow =
241+ workflowClient .newWorkflowStub (SendSignalObjectWorkflow .class , options );
240242 workflow .execute ();
241243
242- //Wait for reporter
244+ // Wait for reporter
243245 Thread .sleep (600 );
244246
245247 Map <String , String > tags =
246- new ImmutableMap .Builder <String , String >(2 )
247- .put (MetricsTag .DOMAIN , WorkflowTest .DOMAIN )
248- .put (MetricsTag .TASK_LIST , taskList )
249- .build ();
248+ new ImmutableMap .Builder <String , String >(2 )
249+ .put (MetricsTag .DOMAIN , WorkflowTest .DOMAIN )
250+ .put (MetricsTag .TASK_LIST , taskList )
251+ .build ();
250252 verify (reporter , times (1 )).reportCounter (MetricsType .CORRUPTED_SIGNALS_COUNTER , tags , 2 );
251253 }
252254
253255 private static class CorruptedSignalWorkflowInterceptorFactory
254- implements Function <WorkflowInterceptor , WorkflowInterceptor > {
255-
256- @ Override
257- public WorkflowInterceptor apply (WorkflowInterceptor next ) {
258- return new SignalWorkflowInterceptor (args -> {
259- if (args != null && args .length > 0 ){
260- return new Object [] {"Corrupted Signal" };
261- }
262- return args ;
263- }, sig ->sig , next );
264- }
256+ implements Function <WorkflowInterceptor , WorkflowInterceptor > {
257+
258+ @ Override
259+ public WorkflowInterceptor apply (WorkflowInterceptor next ) {
260+ return new SignalWorkflowInterceptor (
261+ args -> {
262+ if (args != null && args .length > 0 ) {
263+ return new Object [] {"Corrupted Signal" };
264+ }
265+ return args ;
266+ },
267+ sig -> sig ,
268+ next );
269+ }
265270 }
266271}
0 commit comments