use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldCatchUpTwoFreshNodesAfterRestart.
@Test
@InterruptAfter(30)
public void shouldCatchUpTwoFreshNodesAfterRestart() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final int messageCount = 50_000;
cluster.connectClient();
cluster.msgBuffer().putStringWithoutLengthAscii(0, NO_OP_MSG);
for (int i = 0; i < messageCount; i++) {
cluster.pollUntilMessageSent(NO_OP_MSG.length());
}
cluster.awaitResponseMessageCount(messageCount);
cluster.terminationsExpected(true);
cluster.abortCluster(leader);
cluster.awaitNodeTerminations();
cluster.stopAllNodes();
final TestNode oldLeader = cluster.startStaticNode(leader.index(), false);
final TestNode oldFollower1 = cluster.startStaticNode(followers.get(0).index(), true);
final TestNode oldFollower2 = cluster.startStaticNode(followers.get(1).index(), true);
cluster.awaitLeader();
cluster.awaitServicesMessageCount(messageCount);
assertEquals(0L, oldLeader.errors());
assertEquals(0L, oldFollower1.errors());
assertEquals(0L, oldFollower2.errors());
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot.
@SuppressWarnings("MethodLength")
@Test
@InterruptAfter(30)
public void shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot() {
final int originalTermLength = 256 * 1024;
final int originalMtu = 1408;
final int newTermLength = 2 * 1024 * 1024;
final int newMtu = 8992;
final CRC32 crc32 = new CRC32();
cluster = aCluster().withStaticNodes(3).withLogChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withIngressChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withEgressChannel("aeron:udp?endpoint=localhost:0|term-length=" + originalTermLength + "|mtu=" + originalMtu).withServiceSupplier((i) -> new TestNode.TestService[] { new TestNode.TestService(), new TestNode.ChecksumService() }).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
for (int i = 0; i < 3; i++) {
assertEquals(2, cluster.node(i).services().length);
}
cluster.connectClient();
final int firstBatch = 9;
int messageLength = computeMaxMessageLength(originalTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
int payloadLength = messageLength - SIZE_OF_INT;
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'x');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
int msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
long checksum = 0;
for (int i = 0; i < firstBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
checksum = Hashing.hash(checksum ^ msgChecksum);
}
cluster.awaitResponseMessageCount(firstBatch);
cluster.takeSnapshot(leader);
cluster.awaitSnapshotCount(1);
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'y');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
final int secondBatch = 11;
for (int i = 0; i < secondBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
}
cluster.awaitResponseMessageCount(firstBatch + secondBatch);
cluster.stopAllNodes();
// seed all recording logs from the latest snapshot
for (int i = 0; i < 3; i++) {
ClusterTool.seedRecordingLogFromSnapshot(cluster.node(i).consensusModule().context().clusterDir());
}
cluster.logChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.ingressChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.egressChannel("aeron:udp?endpoint=localhost:0|term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.restartAllNodes(false);
cluster.awaitLeader();
assertEquals(2, cluster.followers().size());
for (int i = 0; i < 3; i++) {
assertEquals(2, cluster.node(i).services().length);
}
cluster.awaitSnapshotsLoaded();
cluster.reconnectClient();
messageLength = computeMaxMessageLength(newTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
payloadLength = messageLength - SIZE_OF_INT;
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'z');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
final int thirdBatch = 5;
for (int i = 0; i < thirdBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
checksum = Hashing.hash(checksum ^ msgChecksum);
}
cluster.awaitResponseMessageCount(firstBatch + secondBatch + thirdBatch);
final int finalMessageCount = firstBatch + thirdBatch;
final long finalChecksum = checksum;
final Predicate<TestNode> finalServiceState = node -> {
final TestNode.TestService[] services = node.services();
return finalMessageCount == services[0].messageCount() && finalChecksum == ((TestNode.ChecksumService) services[1]).checksum();
};
for (int i = 0; i < 3; i++) {
final TestNode node = cluster.node(i);
cluster.awaitServiceState(node, finalServiceState);
}
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldRecoverWhenLeaderHasAppendedMoreThanFollower.
@Test
@InterruptAfter(40)
public void shouldRecoverWhenLeaderHasAppendedMoreThanFollower() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final TestNode followerOne = followers.get(0);
final TestNode followerTwo = followers.get(1);
final int messageCount = 10;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.stopNode(followerOne);
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount * 2);
cluster.stopNode(followerTwo);
cluster.stopNode(leader);
cluster.startStaticNode(leader.index(), false);
cluster.startStaticNode(followerOne.index(), false);
cluster.awaitLeader();
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldStopLeaderAndRestartAsFollower.
@Test
@InterruptAfter(40)
public void shouldStopLeaderAndRestartAsFollower() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode originalLeader = cluster.awaitLeader();
cluster.stopNode(originalLeader);
cluster.awaitLeader(originalLeader.index());
final TestNode follower = cluster.startStaticNode(originalLeader.index(), false);
awaitElectionClosed(follower);
assertEquals(FOLLOWER, follower.role());
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldStopFollowerAndRestartFollower.
@Test
@InterruptAfter(30)
public void shouldStopFollowerAndRestartFollower() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
TestNode follower = cluster.followers().get(0);
awaitElectionClosed(follower);
cluster.stopNode(follower);
follower = cluster.startStaticNode(follower.index(), false);
awaitElectionClosed(follower);
assertEquals(FOLLOWER, follower.role());
}
Aggregations