@@ -75,40 +75,32 @@ void setup() {
7575 @ Test
7676 void commandStartedShouldNotInstrumentWhenAdminDatabase () {
7777
78- // when
7978 listener .commandStarted (new CommandStartedEvent (null , 0 , 0 , null , "admin" , "" , null ));
8079
81- // then
8280 assertThat (meterRegistry ).hasNoMetrics ();
8381 }
8482
8583 @ Test
8684 void commandStartedShouldNotInstrumentWhenNoRequestContext () {
8785
88- // when
8986 listener .commandStarted (new CommandStartedEvent (null , 0 , 0 , null , "some name" , "" , null ));
9087
91- // then
9288 assertThat (meterRegistry ).hasNoMetrics ();
9389 }
9490
9591 @ Test
9692 void commandStartedShouldNotInstrumentWhenNoParentSampleInRequestContext () {
9793
98- // when
9994 listener .commandStarted (new CommandStartedEvent (new MapRequestContext (), 0 , 0 , null , "some name" , "" , null ));
10095
101- // then
10296 assertThat (meterRegistry ).hasMeterWithName ("spring.data.mongodb.command.active" );
10397 }
10498
10599 @ Test // GH-4994
106100 void commandStartedShouldAlwaysIncludeCollection () {
107101
108- // when
109102 listener .commandStarted (new CommandStartedEvent (new MapRequestContext (), 0 , 0 , null , "some name" , "hello" , null ));
110103
111- // then
112104 // although command 'hello' is collection-less, metric must have tag "db.mongodb.collection"
113105 assertThat (meterRegistry ).hasMeterWithNameAndTags (
114106 "spring.data.mongodb.command.active" ,
@@ -130,18 +122,15 @@ void reactiveContextCompletesNormally() {
130122 new BsonDocument ("collection" , new BsonString ("user" ))));
131123 listener .commandSucceeded (new CommandSucceededEvent (context , 0 , 0 , null , "insert" , null , null , 0 ));
132124
133- // then
134125 assertThatTimerRegisteredWithTags ();
135126 }
136127
137128 @ Test
138129 void successfullyCompletedCommandShouldCreateTimerWhenParentSampleInRequestContext () {
139130
140- // given
141131 Observation parent = Observation .start ("name" , observationRegistry );
142132 RequestContext traceRequestContext = getContext ();
143133
144- // when
145134 listener .commandStarted (new CommandStartedEvent (traceRequestContext , 0 , 0 , //
146135 new ConnectionDescription ( //
147136 new ServerId ( //
@@ -150,18 +139,15 @@ void successfullyCompletedCommandShouldCreateTimerWhenParentSampleInRequestConte
150139 new BsonDocument ("collection" , new BsonString ("user" ))));
151140 listener .commandSucceeded (new CommandSucceededEvent (traceRequestContext , 0 , 0 , null , "insert" , null , null , 0 ));
152141
153- // then
154142 assertThatTimerRegisteredWithTags ();
155143 }
156144
157145 @ Test
158146 void successfullyCompletedCommandWithCollectionHavingCommandNameShouldCreateTimerWhenParentSampleInRequestContext () {
159147
160- // given
161148 Observation parent = Observation .start ("name" , observationRegistry );
162149 RequestContext traceRequestContext = getContext ();
163150
164- // when
165151 listener .commandStarted (new CommandStartedEvent (traceRequestContext , 0 , 0 , //
166152 new ConnectionDescription ( //
167153 new ServerId ( //
@@ -171,18 +157,15 @@ void successfullyCompletedCommandWithCollectionHavingCommandNameShouldCreateTime
171157 new BsonDocument ("aggregate" , new BsonString ("user" ))));
172158 listener .commandSucceeded (new CommandSucceededEvent (traceRequestContext , 0 , 0 , null , "aggregate" , null , null , 0 ));
173159
174- // then
175160 assertThatTimerRegisteredWithTags ();
176161 }
177162
178163 @ Test
179164 void successfullyCompletedCommandWithoutClusterInformationShouldCreateTimerWhenParentSampleInRequestContext () {
180165
181- // given
182166 Observation parent = Observation .start ("name" , observationRegistry );
183167 RequestContext traceRequestContext = getContext ();
184168
185- // when
186169 listener .commandStarted (new CommandStartedEvent (traceRequestContext , 0 , 0 , null , "database" , "insert" ,
187170 new BsonDocument ("collection" , new BsonString ("user" ))));
188171 listener .commandSucceeded (new CommandSucceededEvent (traceRequestContext , 0 , 0 , null , "insert" , null , null , 0 ));
@@ -197,11 +180,9 @@ void successfullyCompletedCommandWithoutClusterInformationShouldCreateTimerWhenP
197180 @ Test
198181 void commandWithErrorShouldCreateTimerWhenParentSampleInRequestContext () {
199182
200- // given
201183 Observation parent = Observation .start ("name" , observationRegistry );
202184 RequestContext traceRequestContext = getContext ();
203185
204- // when
205186 listener .commandStarted (new CommandStartedEvent (traceRequestContext , 0 , 0 , //
206187 new ConnectionDescription ( //
207188 new ServerId ( //
@@ -212,20 +193,17 @@ void commandWithErrorShouldCreateTimerWhenParentSampleInRequestContext() {
212193 listener .commandFailed ( //
213194 new CommandFailedEvent (traceRequestContext , 0 , 0 , null , "db" , "insert" , 0 , new IllegalAccessException ()));
214195
215- // then
216196 assertThatTimerRegisteredWithTags ();
217197 }
218198
219199 @ Test // GH-4481
220200 void completionShouldIgnoreIncompatibleObservationContext () {
221201
222- // given
223202 RequestContext traceRequestContext = getContext ();
224203
225204 Observation observation = mock (Observation .class );
226205 traceRequestContext .put (ObservationThreadLocalAccessor .KEY , observation );
227206
228- // when
229207 listener .commandSucceeded (new CommandSucceededEvent (traceRequestContext , 0 , 0 , null , "insert" , null , null , 0 ));
230208
231209 verify (observation ).getContext ();
@@ -235,13 +213,11 @@ void completionShouldIgnoreIncompatibleObservationContext() {
235213 @ Test // GH-4481
236214 void failureShouldIgnoreIncompatibleObservationContext () {
237215
238- // given
239216 RequestContext traceRequestContext = getContext ();
240217
241218 Observation observation = mock (Observation .class );
242219 traceRequestContext .put (ObservationThreadLocalAccessor .KEY , observation );
243220
244- // when
245221 listener .commandFailed (new CommandFailedEvent (traceRequestContext , 0 , 0 , null , "db" , "insert" , 0 , null ));
246222
247223 verify (observation ).getContext ();
@@ -251,7 +227,6 @@ void failureShouldIgnoreIncompatibleObservationContext() {
251227 @ Test // GH-4321
252228 void shouldUseObservationConvention () {
253229
254- // given
255230 MongoHandlerObservationConvention customObservationConvention = new MongoHandlerObservationConvention () {
256231 @ Override
257232 public boolean supportsContext (Observation .Context context ) {
@@ -266,22 +241,18 @@ public String getName() {
266241 this .listener = new MongoObservationCommandListener (observationRegistry , mock (ConnectionString .class ),
267242 customObservationConvention );
268243
269- // when
270244 listener .commandStarted (new CommandStartedEvent (new MapRequestContext (), 0 , 0 , null , "some name" , "" , null ));
271245
272- // then
273246 assertThat (meterRegistry ).hasMeterWithName ("custom.name.active" );
274247 }
275248
276249 @ Test // GH-5064
277250 void completionRestoresParentObservation () {
278251
279- // given
280252 Observation parent = Observation .start ("name" , observationRegistry );
281253 observationRegistry .setCurrentObservationScope (parent .openScope ());
282254 RequestContext traceRequestContext = getContext ();
283255
284- // when
285256 listener .commandStarted (new CommandStartedEvent (traceRequestContext , 0 , 0 , null , "database" , "insert" ,
286257 new BsonDocument ("collection" , new BsonString ("user" ))));
287258
@@ -296,12 +267,10 @@ void completionRestoresParentObservation() {
296267 @ Test // GH-5064
297268 void failureRestoresParentObservation () {
298269
299- // given
300270 Observation parent = Observation .start ("name" , observationRegistry );
301271 observationRegistry .setCurrentObservationScope (parent .openScope ());
302272 RequestContext traceRequestContext = getContext ();
303273
304- // when
305274 listener .commandStarted (new CommandStartedEvent (traceRequestContext , 0 , 0 , null , "database" , "insert" ,
306275 new BsonDocument ("collection" , new BsonString ("user" ))));
307276
0 commit comments