use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testSequenceOperations.
/**
* Tests submitting a linearizable event that publishes to all sessions.
*/
private void testSequenceOperations(int nodes, ReadConsistency consistency) throws Throwable {
createServers(nodes);
AtomicInteger counter = new AtomicInteger();
AtomicLong index = new AtomicLong();
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.<Long>addEventListener(CHANGE_EVENT, clientSerializer::decode, event -> {
threadAssertEquals(counter.incrementAndGet(), 3);
threadAssertTrue(event >= index.get());
index.set(event);
resume();
});
session.<Long>invoke(WRITE, clientSerializer::decode).thenAccept(result -> {
threadAssertNotNull(result);
threadAssertEquals(counter.incrementAndGet(), 1);
threadAssertTrue(index.compareAndSet(0, result));
resume();
});
session.<Boolean, Long>invoke(EVENT, clientSerializer::encode, true, clientSerializer::decode).thenAccept(result -> {
threadAssertNotNull(result);
threadAssertEquals(counter.incrementAndGet(), 2);
threadAssertTrue(result > index.get());
index.set(result);
resume();
});
session.<Long>invoke(READ, clientSerializer::decode).thenAccept(result -> {
threadAssertNotNull(result);
threadAssertEquals(counter.incrementAndGet(), 4);
long i = index.get();
threadAssertTrue(result >= i);
resume();
});
await(30000, 4);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testEventsAfterFollowerKill.
/**
* Tests submitting a sequential event that publishes to all sessions.
*/
private void testEventsAfterFollowerKill(int nodes) throws Throwable {
List<RaftServer> servers = createServers(nodes);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, clientSerializer::encode, true).thenRun(this::resume);
await(30000, 2);
}
session.invoke(EVENT, clientSerializer::encode, true).thenRun(this::resume);
RaftServer follower = servers.stream().filter(s -> s.getRole() == RaftServer.Role.FOLLOWER).findFirst().get();
follower.shutdown().get(10, TimeUnit.SECONDS);
await(30000, 2);
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, clientSerializer::encode, true).thenRun(this::resume);
await(30000, 2);
}
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testCrashRecover.
/**
* Tests joining a server to an existing cluster.
*/
@Test
public void testCrashRecover() throws Throwable {
List<RaftServer> servers = createServers(3);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
submit(session, 0, 100);
await(30000);
Thread.sleep(15000);
servers.get(0).shutdown().get(10, TimeUnit.SECONDS);
RaftServer server = createServer(members.get(0).nodeId());
server.join(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).thenRun(this::resume);
await(30000);
submit(session, 0, 100);
await(30000);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testManyEventsAfterLeaderShutdown.
/**
* Tests submitting a linearizable event that publishes to all sessions.
*/
private void testManyEventsAfterLeaderShutdown(int nodes) throws Throwable {
List<RaftServer> servers = createServers(nodes);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, clientSerializer::encode, true).thenRun(this::resume);
await(30000, 2);
}
RaftServer leader = servers.stream().filter(s -> s.getRole() == RaftServer.Role.LEADER).findFirst().get();
leader.shutdown().get(10, TimeUnit.SECONDS);
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, clientSerializer::encode, true).thenRun(this::resume);
await(30000, 2);
}
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testSubmitQuery.
/**
* Tests submitting a query with a configured consistency level.
*/
private void testSubmitQuery(int nodes, ReadConsistency consistency) throws Throwable {
createServers(nodes);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client, consistency);
session.invoke(READ).thenRun(this::resume);
await(30000);
}
Aggregations