From 999eca66aab969113fbe28ad02013890480d359c Mon Sep 17 00:00:00 2001 From: lvca Date: Wed, 25 Oct 2023 14:01:04 -0400 Subject: [PATCH] test: HA, fixed some tests with asynchronous replication. Now they wait until the replication is finished before do the final checks --- .../arcadedb/server/BaseGraphServerTest.java | 10 ++++++++++ .../com/arcadedb/server/ha/HASplitBrainIT.java | 17 +++++++++++++---- .../arcadedb/server/ha/ReplicationServerIT.java | 8 +------- .../ReplicationServerWriteAgainstReplicaIT.java | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java b/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java index 8ede42ece4..a8e6abd764 100644 --- a/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java +++ b/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java @@ -166,6 +166,16 @@ protected void populateDatabase() { root = v1.getIdentity(); } + protected void waitAllForReplication(final int serverNumber) { + while (getServer(serverNumber).getHA().getMessagesInQueue() > 0) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + @AfterEach public void endTest() { boolean anyServerRestarted = false; diff --git a/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java b/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java index 148ad5dde6..ce0d355041 100644 --- a/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java @@ -57,6 +57,11 @@ protected void onAfterTest() { Assertions.assertEquals("ArcadeDB_0", getLeaderServer().getServerName()); } + @Override + protected HAServer.SERVER_ROLE getServerRole(int serverIndex) { + return HAServer.SERVER_ROLE.ANY; + } + @Override protected void onBeforeStarting(final ArcadeDBServer server) { server.registerTestEventListener(new ReplicationCallback() { @@ -73,21 +78,25 @@ public void onEvent(final TYPE type, final Object object, final ArcadeDBServer s if (port == 2424 || port == 2425 || port == 2426) { if (!rejoining) { testLog("SIMULATING CONNECTION ERROR TO CONNECT TO THE LEADER FROM " + server); - throw new IOException("Simulating an IO Exception on reconnecting from server '" + server.getServerName() + "' to " + connectTo); + throw new IOException( + "Simulating an IO Exception on reconnecting from server '" + server.getServerName() + "' to " + connectTo); } else testLog("AFTER REJOINING -> ALLOWED CONNECTION TO THE ADDRESS " + connectTo + " FROM " + server); } else - LogManager.instance().log(this, Level.FINE, "ALLOWED CONNECTION FROM SERVER %s TO %s...", null, server.getServerName(), connectTo); + LogManager.instance() + .log(this, Level.FINE, "ALLOWED CONNECTION FROM SERVER %s TO %s...", null, server.getServerName(), connectTo); } else { // SERVERS 0-2 if (port == 2427 || port == 2428) { if (!rejoining) { testLog("SIMULATING CONNECTION ERROR TO SERVERS " + connectTo + " FROM " + server); - throw new IOException("Simulating an IO Exception on reconnecting from server '" + server.getServerName() + "' to " + connectTo); + throw new IOException( + "Simulating an IO Exception on reconnecting from server '" + server.getServerName() + "' to " + connectTo); } else testLog("AFTER REJOINING -> ALLOWED CONNECTION TO THE ADDRESS " + connectTo + " FROM " + server); } else - LogManager.instance().log(this, Level.FINE, "ALLOWED CONNECTION FROM SERVER %s TO %s...", null, server.getServerName(), connectTo); + LogManager.instance() + .log(this, Level.FINE, "ALLOWED CONNECTION FROM SERVER %s TO %s...", null, server.getServerName(), connectTo); } } } diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java index 0afcf50bd5..58a2012f15 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java @@ -112,13 +112,7 @@ public void testReplication(final int serverId) { testLog("Done"); - while (getServer(0).getHA().getMessagesInQueue() > 0) - try { - Thread.sleep(200); - } catch (final InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } + waitAllForReplication(0); Assertions.assertEquals(1 + (long) getTxs() * getVerticesPerTx(), db.countType(VERTEX1_TYPE_NAME, true), "Check for vertex count for server" + 0); diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerWriteAgainstReplicaIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerWriteAgainstReplicaIT.java index 315a9ed2a2..8be1fc64e4 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerWriteAgainstReplicaIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerWriteAgainstReplicaIT.java @@ -24,6 +24,7 @@ public class ReplicationServerWriteAgainstReplicaIT extends ReplicationServerIT @Test public void testReplication() { testReplication(1); + waitAllForReplication(1); } @Override