17
17
18
18
package com .uber .cadence .internal .testing ;
19
19
20
- import static org .junit .Assert .assertEquals ;
21
- import static org .junit .Assert .assertTrue ;
22
- import static org .junit .Assert .fail ;
20
+ import static org .junit .Assert .*;
23
21
import static org .mockito .Matchers .anyString ;
24
22
import static org .mockito .Mockito .mock ;
25
23
import static org .mockito .Mockito .when ;
45
43
import com .uber .cadence .testing .TestEnvironmentOptions ;
46
44
import com .uber .cadence .testing .TestWorkflowEnvironment ;
47
45
import com .uber .cadence .worker .Worker ;
48
- import com .uber .cadence .workflow .ActivityTimeoutException ;
49
- import com .uber .cadence .workflow .Async ;
50
- import com .uber .cadence .workflow .ChildWorkflowOptions ;
51
- import com .uber .cadence .workflow .ChildWorkflowTimedOutException ;
52
- import com .uber .cadence .workflow .Promise ;
53
- import com .uber .cadence .workflow .SignalMethod ;
54
- import com .uber .cadence .workflow .Workflow ;
55
- import com .uber .cadence .workflow .WorkflowMethod ;
46
+ import com .uber .cadence .workflow .*;
56
47
import java .nio .charset .StandardCharsets ;
57
48
import java .time .Duration ;
58
- import java .util .Collections ;
59
- import java .util .List ;
60
- import java .util .Map ;
61
- import java .util .Optional ;
62
- import java .util .UUID ;
49
+ import java .util .*;
63
50
import java .util .concurrent .CancellationException ;
64
51
import java .util .concurrent .CompletableFuture ;
65
52
import java .util .concurrent .ExecutionException ;
@@ -742,6 +729,37 @@ public void testMockedChildSimulatedTimeout() {
742
729
743
730
public static class TestContextPropagator implements ContextPropagator {
744
731
732
+ // public static class TestContext {
733
+ // private final String testKey;
734
+ // private final Integer level;
735
+ //
736
+ // public TestContext(String testKey, Integer level) {
737
+ // this.testKey = testKey;
738
+ // this.level = level;
739
+ // }
740
+ //
741
+ // public String getTestKey() {
742
+ // return testKey;
743
+ // }
744
+ // public Integer getLevel() {
745
+ // return level;
746
+ // }
747
+ //
748
+ // public Map<String, byte[]> ToMap() {
749
+ // return "TestContext{testKey=" + testKey + ", level=" + level + "}";
750
+ // }
751
+ // }
752
+
753
+ private int level ;
754
+
755
+ TestContextPropagator () {
756
+ level = 0 ;
757
+ }
758
+
759
+ public int getLevel () {
760
+ return level ;
761
+ }
762
+
745
763
@ Override
746
764
public String getName () {
747
765
return this .getClass ().getName ();
@@ -774,6 +792,13 @@ public Object getCurrentContext() {
774
792
@ Override
775
793
public void setCurrentContext (Object context ) {
776
794
MDC .put ("test" , String .valueOf (context ));
795
+ level ++;
796
+ }
797
+
798
+ @ Override
799
+ public void unsetCurrentContext () {
800
+ MDC .remove ("test" );
801
+ level --;
777
802
}
778
803
}
779
804
@@ -793,13 +818,15 @@ public void testWorkflowContextPropagation() {
793
818
testEnvironment .start ();
794
819
MDC .put ("test" , "testing123" );
795
820
WorkflowClient client = testEnvironment .newWorkflowClient ();
821
+ TestContextPropagator propagator = new TestContextPropagator ();
796
822
WorkflowOptions options =
797
823
new WorkflowOptions .Builder ()
798
- .setContextPropagators (Collections .singletonList (new TestContextPropagator () ))
824
+ .setContextPropagators (Collections .singletonList (propagator ))
799
825
.build ();
800
826
TestWorkflow workflow = client .newWorkflowStub (TestWorkflow .class , options );
801
827
String result = workflow .workflow1 ("input1" );
802
828
assertEquals ("testing123" , result );
829
+ assertEquals (0 , propagator .getLevel ());
803
830
}
804
831
805
832
public static class ContextPropagationParentWorkflowImpl implements ParentWorkflow {
0 commit comments