Skip to content

Commit

Permalink
test: HA, fixed some tests with asynchronous replication. Now they wa…
Browse files Browse the repository at this point in the history
…it until the replication is finished before do the final checks
  • Loading branch information
lvca committed Oct 25, 2023
1 parent fff96e1 commit 999eca6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
10 changes: 10 additions & 0 deletions server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 13 additions & 4 deletions server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ReplicationServerWriteAgainstReplicaIT extends ReplicationServerIT
@Test
public void testReplication() {
testReplication(1);
waitAllForReplication(1);
}

@Override
Expand Down

0 comments on commit 999eca6

Please sign in to comment.