use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testManySessionsManyEvents.
/**
* Tests submitting a linearizable event that publishes to all sessions.
*/
private void testManySessionsManyEvents(int nodes) throws Throwable {
createServers(nodes);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
createSession(createClient()).addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
createSession(createClient()).addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, clientSerializer::encode, false).thenRun(this::resume);
await(10000, 4);
}
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testManyEvents.
/**
* Tests submitting a linearizable event that publishes to all sessions.
*/
private void testManyEvents(int nodes) throws Throwable {
createServers(nodes);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.addEventListener(message -> {
threadAssertNotNull(message);
resume();
});
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 testServerJoinLate.
/**
* Tests joining a server after many entries have been committed.
*/
private void testServerJoinLate(RaftMember.Type type, RaftServer.Role role) throws Throwable {
createServers(3);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
submit(session, 0, 100);
await(10000);
RaftServer joiner = createServer(nextNodeId());
joiner.addRoleChangeListener(s -> {
if (s == role)
resume();
});
if (type == RaftMember.Type.ACTIVE) {
joiner.join(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).thenRun(this::resume);
} else {
joiner.listen(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).thenRun(this::resume);
}
await(10000, 2);
submit(session, 0, 10);
await(10000);
Thread.sleep(5000);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testBlockOnEvent.
/**
* Tests blocking within an event thread.
*/
@Test
public void testBlockOnEvent() throws Throwable {
createServers(3);
AtomicLong index = new AtomicLong();
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.<Long>addEventListener(CHANGE_EVENT, clientSerializer::decode, event -> {
threadAssertEquals(index.get(), event);
try {
threadAssertTrue(index.get() <= session.<Long>invoke(READ, clientSerializer::decode).get(5, TimeUnit.SECONDS));
} catch (InterruptedException | TimeoutException | ExecutionException e) {
threadFail(e);
}
resume();
});
session.<Boolean, Long>invoke(EVENT, clientSerializer::encode, true, clientSerializer::decode).thenAccept(result -> {
threadAssertNotNull(result);
index.compareAndSet(0, result);
resume();
});
await(10000, 2);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testSessionClose.
/**
* Tests a session closing.
*/
private void testSessionClose(int nodes) throws Throwable {
createServers(nodes);
RaftClient client1 = createClient();
PrimitiveProxy session1 = createSession(client1);
RaftClient client2 = createClient();
session1.invoke(CLOSE).thenRun(this::resume);
await(Duration.ofSeconds(10).toMillis(), 1);
session1.addEventListener(CLOSE_EVENT, this::resume);
createSession(client2).close().thenRun(this::resume);
await(Duration.ofSeconds(10).toMillis(), 2);
}
Aggregations