This is an automated email from the ASF dual-hosted git repository.

mpochatkin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 010111eaa2 IGNITE-22018 Fix flaky ItConnectionHeartbeatTest (#3582)
010111eaa2 is described below

commit 010111eaa29163f40a498a7fcd43b3826d490f65
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Wed Apr 10 11:50:21 2024 +0300

    IGNITE-22018 Fix flaky ItConnectionHeartbeatTest (#3582)
---
 .../cli/commands/ItConnectionHeartbeatTest.java    | 109 ++++-----------------
 1 file changed, 18 insertions(+), 91 deletions(-)

diff --git 
a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItConnectionHeartbeatTest.java
 
b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItConnectionHeartbeatTest.java
index bd642ed339..459091f27e 100644
--- 
a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItConnectionHeartbeatTest.java
+++ 
b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/ItConnectionHeartbeatTest.java
@@ -20,124 +20,51 @@ package org.apache.ignite.internal.cli.commands;
 import static org.apache.ignite.internal.cli.event.EventType.CONNECTION_LOST;
 import static 
org.apache.ignite.internal.cli.event.EventType.CONNECTION_RESTORED;
 import static org.awaitility.Awaitility.await;
-import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.hamcrest.Matchers.is;
 
 import io.micronaut.context.annotation.Property;
-import io.micronaut.context.annotation.Value;
 import jakarta.inject.Inject;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ignite.internal.cli.CliIntegrationTest;
-import org.apache.ignite.internal.cli.core.repl.Session;
 import org.apache.ignite.internal.cli.event.EventSubscriptionManager;
+import org.apache.ignite.internal.cli.event.EventType;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 
 @Property(name = "cli.check.connection.period.second", value = "1")
 class ItConnectionHeartbeatTest extends CliIntegrationTest {
-
-    @Inject
-    Session session;
-
     @Inject
-    EventSubscriptionManager eventSubscriptionManager;
+    private EventSubscriptionManager eventSubscriptionManager;
 
-    @Value("${cli.check.connection.period.second}")
-    private long cliCheckConnectionPeriodSecond;
-
-    private final AtomicInteger connectionLostCount = new AtomicInteger(0);
-    private final AtomicInteger connectionRestoredCount = new AtomicInteger(0);
+    private final AtomicReference<EventType> lastEvent = new 
AtomicReference<>();
 
     @BeforeEach
     void resetConnectionCounts() {
-        connectionLostCount.set(0);
-        connectionRestoredCount.set(0);
+        lastEvent.set(null);
 
         // Register listeners
-        eventSubscriptionManager.subscribe(CONNECTION_LOST, event -> 
connectionLostCount.incrementAndGet());
-        eventSubscriptionManager.subscribe(CONNECTION_RESTORED, event -> 
connectionRestoredCount.incrementAndGet());
-    }
-
-    @Override
-    protected Class<?> getCommandClass() {
-        return TopLevelCliReplCommand.class;
-    }
-
-    @Test
-    @DisplayName("Should send event CONNECTION_RESTORED on connection start")
-    void connectionEstablished() {
-        // Given null session info before connect
-        assertNull(session.info());
-
-        // When connect without parameters
-        execute("connect");
-
-        // Then
-        assertAll(
-                this::assertErrOutputIsEmpty,
-                () -> assertOutputContains("Connected to 
http://localhost:10300";)
-        );
-
-        // Listener was invoked
-        await().timeout(cliCheckConnectionPeriodSecond * 2, 
TimeUnit.SECONDS).until(() -> connectionRestoredCount.get() == 1);
-        assertEquals(0, connectionLostCount.get());
-    }
-
-    @Test
-    @DisplayName("Should send event CONNECTION_LOST on cluster stop")
-    void onConnectionLost() {
-        // Given connected cli
-        execute("connect");
-
-        // Then
-        assertAll(
-                this::assertErrOutputIsEmpty,
-                () -> assertOutputContains("Connected to 
http://localhost:10300";)
-        );
-
-        // When stop node
-        int nodeIndex = CLUSTER.nodeIndex(session.info().nodeName());
-        CLUSTER.stopNode(nodeIndex);
-
-        // Listener was invoked
-        await().timeout(cliCheckConnectionPeriodSecond * 2, 
TimeUnit.SECONDS).until(
-                () -> connectionRestoredCount.get() == 1 && 
connectionLostCount.get() == 1
-        );
-
-        // Tear down. Restore initial state of node to exclude any impact on 
next test.
-        CLUSTER.startNode(nodeIndex);
+        eventSubscriptionManager.subscribe(CONNECTION_LOST, event -> 
lastEvent.set(event.eventType()));
+        eventSubscriptionManager.subscribe(CONNECTION_RESTORED, event -> 
lastEvent.set(event.eventType()));
     }
 
     @Test
-    @DisplayName("Should send event CONNECTION_LOST on cluster stop")
-    void restoreConnectionAfterConnectionLost() {
-        // Given connected cli
-        execute("connect");
+    void checkEvents() {
+        // When CLI is connected
+        connect(NODE_URL);
 
-        // Then
-        assertAll(
-                this::assertErrOutputIsEmpty,
-                () -> assertOutputContains("Connected to 
http://localhost:10300";)
-        );
+        // Then listener was invoked with connection restored event
+        await().until(lastEvent::get, is(CONNECTION_RESTORED));
 
         // When stop node
-        int nodeIndex = CLUSTER.nodeIndex(session.info().nodeName());
-        CLUSTER.stopNode(nodeIndex);
+        CLUSTER.stopNode(0);
 
         // Then connection lost event obtained
-        await().timeout(cliCheckConnectionPeriodSecond * 2, 
TimeUnit.SECONDS).until(
-                () -> connectionRestoredCount.get() == 1 && 
connectionLostCount.get() == 1
-        );
+        await().until(lastEvent::get, is(CONNECTION_LOST));
 
-        // When
-        CLUSTER.startNode(nodeIndex);
+        // When start node again
+        CLUSTER.startNode(0);
 
         // Then one more connection restore event obtained
-        await().timeout(cliCheckConnectionPeriodSecond * 2, 
TimeUnit.SECONDS).until(
-                () -> connectionRestoredCount.get() == 2 && 
connectionLostCount.get() == 1
-        );
+        await().until(lastEvent::get, is(CONNECTION_RESTORED));
     }
 }

Reply via email to