From a3fb97758847ef84c4f7be316a3fb6e0abc49687 Mon Sep 17 00:00:00 2001 From: Marcin Date: Thu, 21 Nov 2024 14:18:31 +0100 Subject: [PATCH] [Java] AeronCluster client does not close itself after whole cluster shutdown --- .../cluster/ClusterClientRecoveryTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 aeron-system-tests/src/test/java/io/aeron/cluster/ClusterClientRecoveryTest.java diff --git a/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterClientRecoveryTest.java b/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterClientRecoveryTest.java new file mode 100644 index 00000000000..fce3fa715ff --- /dev/null +++ b/aeron-system-tests/src/test/java/io/aeron/cluster/ClusterClientRecoveryTest.java @@ -0,0 +1,68 @@ +package io.aeron.cluster; + +import io.aeron.cluster.client.AeronCluster; +import io.aeron.test.EventLogExtension; +import io.aeron.test.InterruptAfter; +import io.aeron.test.InterruptingTestCallback; +import io.aeron.test.SlowTest; +import io.aeron.test.SystemTestWatcher; +import io.aeron.test.Tests; +import io.aeron.test.cluster.TestCluster; +import io.aeron.test.cluster.TestNode; +import org.agrona.concurrent.IdleStrategy; +import org.agrona.concurrent.SleepingIdleStrategy; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static io.aeron.test.cluster.TestCluster.aCluster; +import static io.aeron.test.cluster.TestCluster.awaitElectionClosed; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@SlowTest +@ExtendWith({EventLogExtension.class, InterruptingTestCallback.class }) +class ClusterClientRecoveryTest +{ + @RegisterExtension + final SystemTestWatcher systemTestWatcher = new SystemTestWatcher(); + + @Test + @InterruptAfter(30) + void shouldCloseClusterClientAfterClusterShutdown() + { + final TestCluster cluster = aCluster().withStaticNodes(3).start(); + systemTestWatcher.cluster(cluster); + + final TestNode follower = cluster.followers().get(0); + awaitElectionClosed(follower); + + final AeronCluster client = cluster.connectClient(); + + assertEquals(false, client.isClosed()); + assertEquals(false, client.ingressPublication().isClosed()); + assertEquals(true, client.sendKeepAlive()); + + cluster.node(0).close(); + cluster.node(1).close(); + cluster.node(2).close(); + + final IdleStrategy idleStrategy = new SleepingIdleStrategy(); + idleStrategy.reset(); + + while (true) + { + client.sendKeepAlive(); + client.pollEgress(); + + boolean clientClosed = client.isClosed(); + boolean ingressPublicationClosed = client.ingressPublication().isClosed(); + + if (clientClosed && ingressPublicationClosed) + { + break; + } + + Tests.idle(idleStrategy, "AeronCluster#isClosed = %s, AeronCluster#ingressPublication#isClosed = %s", clientClosed, ingressPublicationClosed); + } + } +}