From d83754ecf9584d85df1c9bb06f537a61e9ef8a7e Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Wed, 29 Oct 2025 15:19:19 +0100 Subject: [PATCH] Polishing. Remove BDD comments. Minor formatting. Original pull request #5083 See #5082 --- .../MongoObservationCommandListenerTests.java | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/observability/MongoObservationCommandListenerTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/observability/MongoObservationCommandListenerTests.java index 33b0c6a8d..2f0e607fd 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/observability/MongoObservationCommandListenerTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/observability/MongoObservationCommandListenerTests.java @@ -75,6 +75,7 @@ class MongoObservationCommandListenerTests { @AfterEach void tearDown() { + Observation currentObservation = observationRegistry.getCurrentObservation(); if (currentObservation != null) { currentObservation.stop(); @@ -85,40 +86,32 @@ class MongoObservationCommandListenerTests { @Test void commandStartedShouldNotInstrumentWhenAdminDatabase() { - // when listener.commandStarted(new CommandStartedEvent(null, 0, 0, null, "admin", "", null)); - // then assertThat(meterRegistry).hasNoMetrics(); } @Test void commandStartedShouldNotInstrumentWhenNoRequestContext() { - // when listener.commandStarted(new CommandStartedEvent(null, 0, 0, null, "some name", "", null)); - // then assertThat(meterRegistry).hasNoMetrics(); } @Test void commandStartedShouldNotInstrumentWhenNoParentSampleInRequestContext() { - // when listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "", null)); - // then assertThat(meterRegistry).hasMeterWithName("spring.data.mongodb.command.active"); } @Test // GH-4994 void commandStartedShouldAlwaysIncludeCollection() { - // when listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "hello", null)); - // then // although command 'hello' is collection-less, metric must have tag "db.mongodb.collection" assertThat(meterRegistry).hasMeterWithNameAndTags( "spring.data.mongodb.command.active", @@ -140,18 +133,15 @@ class MongoObservationCommandListenerTests { new BsonDocument("collection", new BsonString("user")))); listener.commandSucceeded(new CommandSucceededEvent(context, 0, 0, null, "insert", null, null, 0)); - // then assertThatTimerRegisteredWithTags(); } @Test void successfullyCompletedCommandShouldCreateTimerWhenParentSampleInRequestContext() { - // given Observation parent = Observation.start("name", observationRegistry); RequestContext traceRequestContext = getContext(); - // when listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, // new ConnectionDescription( // new ServerId( // @@ -160,18 +150,15 @@ class MongoObservationCommandListenerTests { new BsonDocument("collection", new BsonString("user")))); listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "insert", null, null, 0)); - // then assertThatTimerRegisteredWithTags(); } @Test void successfullyCompletedCommandWithCollectionHavingCommandNameShouldCreateTimerWhenParentSampleInRequestContext() { - // given Observation parent = Observation.start("name", observationRegistry); RequestContext traceRequestContext = getContext(); - // when listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, // new ConnectionDescription( // new ServerId( // @@ -181,18 +168,15 @@ class MongoObservationCommandListenerTests { new BsonDocument("aggregate", new BsonString("user")))); listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "aggregate", null, null, 0)); - // then assertThatTimerRegisteredWithTags(); } @Test void successfullyCompletedCommandWithoutClusterInformationShouldCreateTimerWhenParentSampleInRequestContext() { - // given Observation parent = Observation.start("name", observationRegistry); RequestContext traceRequestContext = getContext(); - // when listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, null, "database", "insert", new BsonDocument("collection", new BsonString("user")))); listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "insert", null, null, 0)); @@ -207,11 +191,9 @@ class MongoObservationCommandListenerTests { @Test void commandWithErrorShouldCreateTimerWhenParentSampleInRequestContext() { - // given Observation parent = Observation.start("name", observationRegistry); RequestContext traceRequestContext = getContext(); - // when listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, // new ConnectionDescription( // new ServerId( // @@ -222,20 +204,17 @@ class MongoObservationCommandListenerTests { listener.commandFailed( // new CommandFailedEvent(traceRequestContext, 0, 0, null, "db", "insert", 0, new IllegalAccessException())); - // then assertThatTimerRegisteredWithTags(); } @Test // GH-4481 void completionShouldIgnoreIncompatibleObservationContext() { - // given RequestContext traceRequestContext = getContext(); Observation observation = mock(Observation.class); traceRequestContext.put(ObservationThreadLocalAccessor.KEY, observation); - // when listener.commandSucceeded(new CommandSucceededEvent(traceRequestContext, 0, 0, null, "insert", null, null, 0)); verify(observation).getContext(); @@ -245,13 +224,11 @@ class MongoObservationCommandListenerTests { @Test // GH-4481 void failureShouldIgnoreIncompatibleObservationContext() { - // given RequestContext traceRequestContext = getContext(); Observation observation = mock(Observation.class); traceRequestContext.put(ObservationThreadLocalAccessor.KEY, observation); - // when listener.commandFailed(new CommandFailedEvent(traceRequestContext, 0, 0, null, "db", "insert", 0, null)); verify(observation).getContext(); @@ -261,7 +238,6 @@ class MongoObservationCommandListenerTests { @Test // GH-4321 void shouldUseObservationConvention() { - // given MongoHandlerObservationConvention customObservationConvention = new MongoHandlerObservationConvention() { @Override public boolean supportsContext(Observation.Context context) { @@ -276,22 +252,18 @@ class MongoObservationCommandListenerTests { this.listener = new MongoObservationCommandListener(observationRegistry, mock(ConnectionString.class), customObservationConvention); - // when listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "", null)); - // then assertThat(meterRegistry).hasMeterWithName("custom.name.active"); } @Test // GH-5064 void completionRestoresParentObservation() { - // given Observation parent = Observation.start("name", observationRegistry); observationRegistry.setCurrentObservationScope(parent.openScope()); RequestContext traceRequestContext = getContext(); - // when listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, null, "database", "insert", new BsonDocument("collection", new BsonString("user")))); @@ -306,12 +278,10 @@ class MongoObservationCommandListenerTests { @Test // GH-5064 void failureRestoresParentObservation() { - // given Observation parent = Observation.start("name", observationRegistry); observationRegistry.setCurrentObservationScope(parent.openScope()); RequestContext traceRequestContext = getContext(); - // when listener.commandStarted(new CommandStartedEvent(traceRequestContext, 0, 0, null, "database", "insert", new BsonDocument("collection", new BsonString("user"))));