Skip to content

Commit 75d2491

Browse files
committed
Polishing.
Remove BDD comments. Minor formatting. Original pull request #5083 See #5082
1 parent bcbf2ff commit 75d2491

File tree

1 file changed

+1
-31
lines changed

1 file changed

+1
-31
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/observability/MongoObservationCommandListenerTests.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void setup() {
7575

7676
@AfterEach
7777
void tearDown() {
78+
7879
Observation currentObservation = observationRegistry.getCurrentObservation();
7980
if (currentObservation != null) {
8081
currentObservation.stop();
@@ -85,40 +86,32 @@ void tearDown() {
8586
@Test
8687
void commandStartedShouldNotInstrumentWhenAdminDatabase() {
8788

88-
// when
8989
listener.commandStarted(new CommandStartedEvent(null, 0, 0, null, "admin", "", null));
9090

91-
// then
9291
assertThat(meterRegistry).hasNoMetrics();
9392
}
9493

9594
@Test
9695
void commandStartedShouldNotInstrumentWhenNoRequestContext() {
9796

98-
// when
9997
listener.commandStarted(new CommandStartedEvent(null, 0, 0, null, "some name", "", null));
10098

101-
// then
10299
assertThat(meterRegistry).hasNoMetrics();
103100
}
104101

105102
@Test
106103
void commandStartedShouldNotInstrumentWhenNoParentSampleInRequestContext() {
107104

108-
// when
109105
listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "", null));
110106

111-
// then
112107
assertThat(meterRegistry).hasMeterWithName("spring.data.mongodb.command.active");
113108
}
114109

115110
@Test // GH-4994
116111
void commandStartedShouldAlwaysIncludeCollection() {
117112

118-
// when
119113
listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "hello", null));
120114

121-
// then
122115
// although command 'hello' is collection-less, metric must have tag "db.mongodb.collection"
123116
assertThat(meterRegistry).hasMeterWithNameAndTags(
124117
"spring.data.mongodb.command.active",
@@ -140,18 +133,15 @@ void reactiveContextCompletesNormally() {
140133
new BsonDocument("collection", new BsonString("user"))));
141134
listener.commandSucceeded(new CommandSucceededEvent(context, 0, 0, null, "insert", null, null, 0));
142135

143-
// then
144136
assertThatTimerRegisteredWithTags();
145137
}
146138

147139
@Test
148140
void successfullyCompletedCommandShouldCreateTimerWhenParentSampleInRequestContext() {
149141

150-
// given
151142
Observation parent = Observation.start("name", observationRegistry);
152143
RequestContext traceRequestContext = getContext();
153144

154-
// when
155145
listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, //
156146
new ConnectionDescription( //
157147
new ServerId( //
@@ -160,18 +150,15 @@ void successfullyCompletedCommandShouldCreateTimerWhenParentSampleInRequestConte
160150
new BsonDocument("collection", new BsonString("user"))));
161151
listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "insert", null, null, 0));
162152

163-
// then
164153
assertThatTimerRegisteredWithTags();
165154
}
166155

167156
@Test
168157
void successfullyCompletedCommandWithCollectionHavingCommandNameShouldCreateTimerWhenParentSampleInRequestContext() {
169158

170-
// given
171159
Observation parent = Observation.start("name", observationRegistry);
172160
RequestContext traceRequestContext = getContext();
173161

174-
// when
175162
listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, //
176163
new ConnectionDescription( //
177164
new ServerId( //
@@ -181,18 +168,15 @@ void successfullyCompletedCommandWithCollectionHavingCommandNameShouldCreateTime
181168
new BsonDocument("aggregate", new BsonString("user"))));
182169
listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "aggregate", null, null, 0));
183170

184-
// then
185171
assertThatTimerRegisteredWithTags();
186172
}
187173

188174
@Test
189175
void successfullyCompletedCommandWithoutClusterInformationShouldCreateTimerWhenParentSampleInRequestContext() {
190176

191-
// given
192177
Observation parent = Observation.start("name", observationRegistry);
193178
RequestContext traceRequestContext = getContext();
194179

195-
// when
196180
listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, null, "database", "insert",
197181
new BsonDocument("collection", new BsonString("user"))));
198182
listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "insert", null, null, 0));
@@ -207,11 +191,9 @@ void successfullyCompletedCommandWithoutClusterInformationShouldCreateTimerWhenP
207191
@Test
208192
void commandWithErrorShouldCreateTimerWhenParentSampleInRequestContext() {
209193

210-
// given
211194
Observation parent = Observation.start("name", observationRegistry);
212195
RequestContext traceRequestContext = getContext();
213196

214-
// when
215197
listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, //
216198
new ConnectionDescription( //
217199
new ServerId( //
@@ -222,20 +204,17 @@ void commandWithErrorShouldCreateTimerWhenParentSampleInRequestContext() {
222204
listener.commandFailed( //
223205
new CommandFailedEvent(traceRequestContext, 0, 0, null, "db", "insert", 0, new IllegalAccessException()));
224206

225-
// then
226207
assertThatTimerRegisteredWithTags();
227208
}
228209

229210
@Test // GH-4481
230211
void completionShouldIgnoreIncompatibleObservationContext() {
231212

232-
// given
233213
RequestContext traceRequestContext = getContext();
234214

235215
Observation observation = mock(Observation.class);
236216
traceRequestContext.put(ObservationThreadLocalAccessor.KEY, observation);
237217

238-
// when
239218
listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "insert", null, null, 0));
240219

241220
verify(observation).getContext();
@@ -245,13 +224,11 @@ void completionShouldIgnoreIncompatibleObservationContext() {
245224
@Test // GH-4481
246225
void failureShouldIgnoreIncompatibleObservationContext() {
247226

248-
// given
249227
RequestContext traceRequestContext = getContext();
250228

251229
Observation observation = mock(Observation.class);
252230
traceRequestContext.put(ObservationThreadLocalAccessor.KEY, observation);
253231

254-
// when
255232
listener.commandFailed(new CommandFailedEvent(traceRequestContext, 0, 0, null, "db", "insert", 0, null));
256233

257234
verify(observation).getContext();
@@ -261,7 +238,6 @@ void failureShouldIgnoreIncompatibleObservationContext() {
261238
@Test // GH-4321
262239
void shouldUseObservationConvention() {
263240

264-
// given
265241
MongoHandlerObservationConvention customObservationConvention = new MongoHandlerObservationConvention() {
266242
@Override
267243
public boolean supportsContext(Observation.Context context) {
@@ -276,22 +252,18 @@ public String getName() {
276252
this.listener = new MongoObservationCommandListener(observationRegistry, mock(ConnectionString.class),
277253
customObservationConvention);
278254

279-
// when
280255
listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "", null));
281256

282-
// then
283257
assertThat(meterRegistry).hasMeterWithName("custom.name.active");
284258
}
285259

286260
@Test // GH-5064
287261
void completionRestoresParentObservation() {
288262

289-
// given
290263
Observation parent = Observation.start("name", observationRegistry);
291264
observationRegistry.setCurrentObservationScope(parent.openScope());
292265
RequestContext traceRequestContext = getContext();
293266

294-
// when
295267
listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, null, "database", "insert",
296268
new BsonDocument("collection", new BsonString("user"))));
297269

@@ -306,12 +278,10 @@ void completionRestoresParentObservation() {
306278
@Test // GH-5064
307279
void failureRestoresParentObservation() {
308280

309-
// given
310281
Observation parent = Observation.start("name", observationRegistry);
311282
observationRegistry.setCurrentObservationScope(parent.openScope());
312283
RequestContext traceRequestContext = getContext();
313284

314-
// when
315285
listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, null, "database", "insert",
316286
new BsonDocument("collection", new BsonString("user"))));
317287

0 commit comments

Comments
 (0)