From: Kai Moritz Date: Sun, 18 Feb 2024 19:12:19 +0000 (+0100) Subject: fix: Without `@DirtiesContext` the app is not teared down correctly X-Git-Tag: rebase--2024-02-20--15-07~17 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=28aa31ca5492c75eeebda71f5ceefc3ab97e034c;p=demos%2Fkafka%2Fchat fix: Without `@DirtiesContext` the app is not teared down correctly * `StorageStrategy` depends on Spring to call the method `ChatBackendApplication#onExit()`, that is annotated with `@PreDestroy`. * If this method is not called, the strategy is not applied, which leads to errors in the integration-tests. * This happens, if all tests are run through Maven, because Spring recycles the application-context and only tears down the context after all tests have run. * The addition of `@DirtiesContext` on those tests forces Spring to tear down the application completely after each so annotated test. * Hence, the method is called as expected, which fixes the described errors. --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java index 41618e56..21605bc1 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.MediaType; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.web.reactive.server.WebTestClient; import org.testcontainers.shaded.org.awaitility.Awaitility; @@ -22,6 +23,7 @@ import static org.hamcrest.Matchers.endsWith; @Slf4j +@DirtiesContext public abstract class AbstractConfigurationIT { final static String EXISTING_CHATROOM = "5c73531c-6fc4-426c-adcb-afc5c140a0f7";