diff --git a/hermes-common/src/main/java/pl/allegro/tech/hermes/infrastructure/zookeeper/cache/HierarchicalCache.java b/hermes-common/src/main/java/pl/allegro/tech/hermes/infrastructure/zookeeper/cache/HierarchicalCache.java index 4f79d10549..babb1a0150 100644 --- a/hermes-common/src/main/java/pl/allegro/tech/hermes/infrastructure/zookeeper/cache/HierarchicalCache.java +++ b/hermes-common/src/main/java/pl/allegro/tech/hermes/infrastructure/zookeeper/cache/HierarchicalCache.java @@ -65,7 +65,7 @@ public void registerCallback(int depth, Consumer callbac } private HierarchicalCacheLevel createLevelCache(int depth, String path) { - BiFunction function = + BiFunction nextLevelFactory = depth + 1 < maxDepth ? this::createLevelCache : null; HierarchicalCacheLevel levelCache = new HierarchicalCacheLevel( @@ -74,7 +74,7 @@ private HierarchicalCacheLevel createLevelCache(int depth, String path) { path(depth, path), depth, levelCallbacks.get(depth), - Optional.ofNullable(function), + Optional.ofNullable(nextLevelFactory), removeNodesWithNoData); try { logger.debug("Starting hierarchical cache level for path {} and depth {}", path, depth); diff --git a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/zookeeper/ZookeeperClient.java b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/zookeeper/ZookeeperClient.java index 5e740a737d..9faad1c8f6 100644 --- a/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/zookeeper/ZookeeperClient.java +++ b/hermes-management/src/main/java/pl/allegro/tech/hermes/management/infrastructure/zookeeper/ZookeeperClient.java @@ -1,15 +1,11 @@ package pl.allegro.tech.hermes.management.infrastructure.zookeeper; -import static org.slf4j.LoggerFactory.getLogger; - import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.CreateMode; -import org.slf4j.Logger; import pl.allegro.tech.hermes.common.exception.InternalProcessingException; public class ZookeeperClient { - private static final Logger logger = getLogger(ZookeeperClient.class); private final CuratorFramework curatorFramework; private final String datacenterName; @@ -36,7 +32,7 @@ public void ensureEphemeralNodeExists(String path) { .forPath(path); } } catch (Exception e) { - throw new InternalProcessingException("Could not ensure existence of path: " + path); + throw new InternalProcessingException("Could not ensure existence of path: " + path, e); } } } diff --git a/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesExtension.java b/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesExtension.java index 6f008480bd..2e0b6309cb 100644 --- a/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesExtension.java +++ b/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesExtension.java @@ -4,11 +4,13 @@ import static pl.allegro.tech.hermes.integrationtests.setup.HermesManagementTestApp.AUDIT_EVENT_PATH; import static pl.allegro.tech.hermes.test.helper.endpoint.TimeoutAdjuster.adjust; +import java.io.IOException; import java.time.Duration; import java.util.List; import java.util.stream.Stream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; @@ -34,7 +36,10 @@ import pl.allegro.tech.hermes.test.helper.environment.HermesTestApp; public class HermesExtension - implements BeforeAllCallback, AfterAllCallback, ExtensionContext.Store.CloseableResource { + implements AfterEachCallback, + BeforeAllCallback, + AfterAllCallback, + ExtensionContext.Store.CloseableResource { private static final Logger logger = LoggerFactory.getLogger(HermesExtension.class); @@ -62,7 +67,8 @@ public class HermesExtension public static BrokerOperations brokerOperations; @Override - public void beforeAll(ExtensionContext context) { + public void beforeAll(ExtensionContext context) throws IOException, InterruptedException { + if (!started) { Stream.of(hermesZookeeper, kafka).parallel().forEach(Startable::start); schemaRegistry.start(); @@ -179,4 +185,13 @@ public HermesExtension withFrontendProfile(String profile) { public void afterAll(ExtensionContext context) { Stream.of(management, consumers, frontend).forEach(HermesTestApp::restoreDefaultSettings); } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + try { + clearManagementData(); + } catch (Exception e) { + logger.error("Error during cleaning up management data", e); + } + } } diff --git a/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesManagementTestApp.java b/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesManagementTestApp.java index 4031abb32e..cad0168fd3 100644 --- a/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesManagementTestApp.java +++ b/integration-tests/src/common/java/pl/allegro/tech/hermes/integrationtests/setup/HermesManagementTestApp.java @@ -11,11 +11,14 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; import pl.allegro.tech.hermes.integrationtests.prometheus.PrometheusExtension; import pl.allegro.tech.hermes.management.HermesManagement; @@ -78,6 +81,7 @@ private void waitUntilReady() { HttpRequest request = HttpRequest.newBuilder() .uri(new URI("http://localhost:" + getPort() + "/mode")) + .timeout(Duration.ofSeconds(1)) .GET() .build(); HttpClient httpClient = HttpClient.newHttpClient(); @@ -109,7 +113,7 @@ public int getPort() { @Override public void stop() { if (app != null) { - app.context().close(); + Optional.ofNullable(app.context()).ifPresent(ConfigurableApplicationContext::close); app = null; } } diff --git a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/ConsumerProfilingTest.java b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/ConsumerProfilingTest.java index 5294afba5a..ae02917be6 100644 --- a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/ConsumerProfilingTest.java +++ b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/ConsumerProfilingTest.java @@ -10,7 +10,6 @@ import ch.qos.logback.core.read.ListAppender; import java.time.Duration; import java.util.List; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -48,12 +47,6 @@ void createLogAppender() { @AfterEach void teardown() { ((Logger) LoggerFactory.getLogger(DefaultConsumerProfiler.class)).detachAndStopAllAppenders(); - hermes.clearManagementData(); - } - - @AfterAll - static void teardownClass() { - hermes.clearManagementData(); } @Test diff --git a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListSubscriptionForOwnerTest.java b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListSubscriptionForOwnerTest.java index a37b2aee86..a8ec5ec674 100644 --- a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListSubscriptionForOwnerTest.java +++ b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListSubscriptionForOwnerTest.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import pl.allegro.tech.hermes.api.OwnerId; @@ -20,10 +20,10 @@ public class ListSubscriptionForOwnerTest { @RegisterExtension public static final HermesExtension hermes = new HermesExtension(); - private static Topic topic; + private Topic topic; - @BeforeAll - public static void createTopic() { + @BeforeEach + public void createTopic() { topic = hermes.initHelper().createTopic(topicWithRandomName().build()); } diff --git a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListUnhealthySubscriptionsForOwnerTest.java b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListUnhealthySubscriptionsForOwnerTest.java index 924ca0f593..054af6b9dd 100644 --- a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListUnhealthySubscriptionsForOwnerTest.java +++ b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/ListUnhealthySubscriptionsForOwnerTest.java @@ -10,8 +10,6 @@ import java.time.Duration; import java.util.Set; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -34,16 +32,6 @@ public class ListUnhealthySubscriptionsForOwnerTest { @RegisterExtension public static final HermesExtension hermes = new HermesExtension().withPrometheus(prometheus); - @BeforeAll - static void setup() { - hermes.clearManagementData(); - } - - @AfterEach - void cleanup() { - hermes.clearManagementData(); - } - @Test public void shouldNotListHealthySubscriptions() { // given diff --git a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/OfflineRetransmissionManagementTest.java b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/OfflineRetransmissionManagementTest.java index 3953a0dfe0..701d253a92 100644 --- a/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/OfflineRetransmissionManagementTest.java +++ b/integration-tests/src/integrationTest/java/pl/allegro/tech/hermes/integrationtests/management/OfflineRetransmissionManagementTest.java @@ -7,7 +7,7 @@ import java.util.List; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.test.web.reactive.server.WebTestClient; @@ -26,8 +26,8 @@ public class OfflineRetransmissionManagementTest { private static final String GROUP = "pl.allegro.retransmission"; - @BeforeAll - public static void setupGroup() { + @BeforeEach + public void setupGroup() { hermes.initHelper().createGroup(Group.from(GROUP)); } diff --git a/integration-tests/src/integrationTest/resources/logback.xml b/integration-tests/src/integrationTest/resources/logback.xml index 25978ddfbd..6c059da44d 100644 --- a/integration-tests/src/integrationTest/resources/logback.xml +++ b/integration-tests/src/integrationTest/resources/logback.xml @@ -3,7 +3,7 @@ - %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + [%thread] - %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n diff --git a/integration-tests/src/slowIntegrationTest/java/pl/allegro/tech/hermes/integrationtests/KafkaReadinessCheckTest.java b/integration-tests/src/slowIntegrationTest/java/pl/allegro/tech/hermes/integrationtests/KafkaReadinessCheckTest.java index d2cff160b2..d489a60f78 100644 --- a/integration-tests/src/slowIntegrationTest/java/pl/allegro/tech/hermes/integrationtests/KafkaReadinessCheckTest.java +++ b/integration-tests/src/slowIntegrationTest/java/pl/allegro/tech/hermes/integrationtests/KafkaReadinessCheckTest.java @@ -12,6 +12,7 @@ import java.util.stream.Stream; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.test.web.reactive.server.WebTestClient; import org.testcontainers.lifecycle.Startable; @@ -33,23 +34,31 @@ public class KafkaReadinessCheckTest { private static final KafkaContainerCluster kafka = new KafkaContainerCluster(3); private static final ConfluentSchemaRegistryContainer schemaRegistry = new ConfluentSchemaRegistryContainer().withKafkaCluster(kafka); + private static HermesFrontendTestApp frontendApp = + new HermesFrontendTestApp(hermesZookeeper, kafka, schemaRegistry); private static Topic topic; + private static HermesInitHelper hermesInitHelper; + private static HermesTestApp management; @BeforeAll public static void setup() { Stream.of(hermesZookeeper, kafka).parallel().forEach(Startable::start); schemaRegistry.start(); - HermesTestApp management = - new HermesManagementTestApp(hermesZookeeper, kafka, schemaRegistry).start(); + management = new HermesManagementTestApp(hermesZookeeper, kafka, schemaRegistry).start(); + frontendApp.start(); + hermesInitHelper = new HermesInitHelper(management.getPort()); + } - HermesInitHelper hermesInitHelper = new HermesInitHelper(management.getPort()); + @BeforeEach + public void beforeEach() { topic = hermesInitHelper.createTopic(topicWithRandomName().withAck(ALL).build()); - management.stop(); } @AfterAll public static void clean() { Stream.of(hermesZookeeper, kafka, schemaRegistry).parallel().forEach(Startable::stop); + frontendApp.stop(); + management.stop(); } @Test diff --git a/integration-tests/src/slowIntegrationTest/resources/logback.xml b/integration-tests/src/slowIntegrationTest/resources/logback.xml index 25978ddfbd..6c059da44d 100644 --- a/integration-tests/src/slowIntegrationTest/resources/logback.xml +++ b/integration-tests/src/slowIntegrationTest/resources/logback.xml @@ -3,7 +3,7 @@ - %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + [%thread] - %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n