@@ -61,6 +61,45 @@ void shouldGiveTheMDCByDefault() {
61
61
.verifyComplete ();
62
62
}
63
63
64
+ @ Test
65
+ @ DisplayName ("should return the appropriate contexts count" )
66
+ void shouldReturnTheAppropriateContextsCount () {
67
+ MDC defaultMdc = new MDC ();
68
+ defaultMdc .put ("mdcKey" , "mdcValue" );
69
+
70
+ MDC anotherMdc = new MDC (ANOTHER_CONTEXT_KEY );
71
+ anotherMdc .put ("mdcKey" , "mdcValue" );
72
+
73
+ Mono <Integer > contextSize1 = Mono .deferContextual (ctx -> Mono .just (ctx .size ()))
74
+ .contextWrite (it -> MDCContext .put (it , defaultMdc ))
75
+ .contextWrite (it -> MDCContext .put (it , anotherMdc ));
76
+ StepVerifier .create (contextSize1 )
77
+ .expectNext (2 )
78
+ .verifyComplete ();
79
+
80
+
81
+ Mono <Integer > contextSize2 = Mono .deferContextual (ctx -> Mono .just (ctx .size ()))
82
+ .contextWrite (it -> MDCContext .put (it , defaultMdc , anotherMdc ));
83
+ StepVerifier .create (contextSize2 )
84
+ .expectNext (2 )
85
+ .verifyComplete ();
86
+
87
+
88
+ Mono <Integer > contextSize3 = Mono .deferContextual (ctx -> Mono .just (ctx .size ()))
89
+ .contextWrite (it -> MDCContext .put (it , defaultMdc , null ));
90
+ StepVerifier .create (contextSize3 )
91
+ .expectNext (1 )
92
+ .verifyComplete ();
93
+
94
+
95
+ Mono <Integer > contextSize4 = Mono .deferContextual (ctx -> Mono .just (ctx .size ()))
96
+ .contextWrite (it -> MDCContext .put (it , defaultMdc , null ))
97
+ .contextWrite (it -> it .put ("A" , "B" ));
98
+ StepVerifier .create (contextSize4 )
99
+ .expectNext (2 )
100
+ .verifyComplete ();
101
+ }
102
+
64
103
@ Test
65
104
@ DisplayName ("should give the MDC you are looking for (more MDC Context)" )
66
105
void shouldGiveTheMDCWithMoreMdcContext () {
@@ -74,7 +113,6 @@ void shouldGiveTheMDCWithMoreMdcContext() {
74
113
Mono <MDC > resultDefault = Mono .defer (MDCContext ::read )
75
114
.contextWrite (it -> MDCContext .put (it , defaultMdc ))
76
115
.contextWrite (it -> MDCContext .put (it , anotherMdc ));
77
-
78
116
StepVerifier .create (resultDefault )
79
117
.expectNext (defaultMdc )
80
118
.verifyComplete ();
@@ -83,57 +121,16 @@ void shouldGiveTheMDCWithMoreMdcContext() {
83
121
Mono <MDC > resultAnother = Mono .defer (() -> MDCContext .read (ANOTHER_CONTEXT_KEY ))
84
122
.contextWrite (it -> MDCContext .put (it , defaultMdc ))
85
123
.contextWrite (it -> MDCContext .put (it , anotherMdc ));
86
-
87
124
StepVerifier .create (resultAnother )
88
125
.expectNext (anotherMdc )
89
126
.verifyComplete ();
90
127
}
91
128
92
- @ Test
93
- @ DisplayName ("should need to be able to store a map" )
94
- void shouldNeedToBeAbleToStoreAMap () {
95
- Map <String , String > mdcMap = new HashMap <>();
96
- mdcMap .put ("mdcKey" , "mdcValue" );
97
-
98
-
99
- Mono <MDC > resultDefault = Mono .defer (MDCContext ::read )
100
- .contextWrite (it -> MDCContext .put (it , mdcMap ));
101
-
102
- StepVerifier .create (resultDefault )
103
- .expectNextMatches (mdc1 -> mdc1 .asMap ().equals (mdcMap ) && mdc1 .getContextKey ().equals (DEFAULT_REACTOR_CONTEXT_MDC_KEY ))
104
- .verifyComplete ();
105
-
106
-
107
- Mono <MDC > resultAnother = Mono .defer (() -> MDCContext .read (ANOTHER_CONTEXT_KEY ))
108
- .contextWrite (it -> MDCContext .put (it , ANOTHER_CONTEXT_KEY , mdcMap ));
109
-
110
- StepVerifier .create (resultAnother )
111
- .expectNextMatches (mdc1 -> mdc1 .asMap ().equals (mdcMap ) && mdc1 .getContextKey ().equals (ANOTHER_CONTEXT_KEY ))
112
- .verifyComplete ();
113
- }
114
-
115
- @ Test
116
- @ DisplayName ("should be MDC stored with the overridden context ID" )
117
- void shouldBeStoredWithTheOverriddenContextIDTest () {
118
- MDC mdc = new MDC ();
119
- mdc .put ("mdcKey" , "mdcValue" );
120
-
121
- Mono <MDC > result = Mono .defer (() -> MDCContext .read (ANOTHER_CONTEXT_KEY ))
122
- .contextWrite (it -> MDCContext .put (it , ANOTHER_CONTEXT_KEY , mdc ));
123
-
124
- StepVerifier .create (result )
125
- .expectNextMatches (mdc1 -> mdc1 .asMap ().equals (mdc .asMap ()) && mdc1 .getContextKey ().equals (ANOTHER_CONTEXT_KEY ))
126
- .verifyComplete ();
127
- }
128
-
129
129
@ Test
130
130
@ DisplayName ("should throw IllegalArgumentException if any parameter is NULL" )
131
131
void shouldThrowIllegalArgumentExceptionTest () {
132
- Map <String , String > emptyMap = new HashMap <>();
133
-
134
- assertThrows (IllegalArgumentException .class , () -> MDCContext .put (null , "" , emptyMap ));
135
- assertThrows (IllegalArgumentException .class , () -> MDCContext .put (Context .empty (), null , emptyMap ));
136
- assertThrows (IllegalArgumentException .class , () -> MDCContext .put (Context .empty (), "" , null ));
132
+ assertThrows (IllegalArgumentException .class , () -> MDCContext .put (null , new MDC ()));
133
+ assertThrows (IllegalArgumentException .class , () -> MDCContext .put (Context .empty (), null ));
137
134
138
135
StepVerifier .create (MDCContext .read ((String ) null ))
139
136
.expectError (IllegalArgumentException .class )
@@ -161,9 +158,6 @@ void shouldThrowInvalidContextDataException() {
161
158
.verify ();
162
159
163
160
164
-
165
-
166
-
167
161
Mono <MDC > result2 = Mono .defer (() -> MDCContext .read ("not-exist-context-id" ))
168
162
.contextWrite (it -> MDCContext .put (it , mdc ));
169
163
StepVerifier .create (result2 )
0 commit comments