use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class PrimaryBackupTest method testSubmitCommand.
/**
* Tests submitting a command to a partial cluster.
*/
private void testSubmitCommand(int nodes, int backups, Replication replication) throws Throwable {
createServers(nodes);
PrimaryBackupClient client = createClient();
PrimitiveProxy session = createProxy(client, backups, replication);
session.invoke(WRITE).thenRun(this::resume);
await(5000);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class PrimaryBackupTest method testSessionClose.
/**
* Tests a session closing.
*/
private void testSessionClose(Replication replication) throws Throwable {
createServers(3);
PrimaryBackupClient client1 = createClient();
PrimitiveProxy session1 = createProxy(client1, 2, replication);
PrimaryBackupClient client2 = createClient();
session1.invoke(CLOSE).thenRun(this::resume);
await(Duration.ofSeconds(10).toMillis(), 1);
session1.addEventListener(CLOSE_EVENT, this::resume);
PrimitiveProxy session2 = createProxy(client2, 2, replication);
session2.invoke(READ).thenRun(this::resume);
await(5000);
session2.close().thenRun(this::resume);
await(Duration.ofSeconds(10).toMillis(), 2);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class PrimaryBackupTest method testManySessionsManyEvents.
/**
* Tests submitting a linearizable event that publishes to all sessions.
*/
private void testManySessionsManyEvents(Replication replication) throws Throwable {
createServers(3);
PrimaryBackupClient client = createClient();
PrimitiveProxy session = createProxy(client, 2, replication);
session.addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
PrimitiveProxy session1 = createProxy(createClient(), 2, replication);
session1.invoke(READ).thenRun(this::resume);
session1.addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
PrimitiveProxy session2 = createProxy(createClient(), 2, replication);
session2.invoke(READ).thenRun(this::resume);
session2.addEventListener(event -> {
threadAssertNotNull(event);
resume();
});
await(5000, 2);
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, SERIALIZER::encode, false).thenRun(this::resume);
await(10000, 4);
}
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testTransferLeadership.
/**
* Tests transferring leadership.
*/
@Test
@Ignore
public void testTransferLeadership() throws Throwable {
List<RaftServer> servers = createServers(3);
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
submit(session, 0, 1000);
RaftServer follower = servers.stream().filter(RaftServer::isFollower).findFirst().get();
follower.promote().thenRun(this::resume);
await(10000, 2);
assertTrue(follower.isLeader());
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftTest method testSequentialEvent.
/**
* Tests submitting a sequential event.
*/
private void testSequentialEvent(int nodes) throws Throwable {
createServers(nodes);
AtomicLong count = new AtomicLong();
AtomicLong index = new AtomicLong();
RaftClient client = createClient();
PrimitiveProxy session = createSession(client);
session.<Long>addEventListener(CHANGE_EVENT, clientSerializer::decode, event -> {
threadAssertEquals(count.incrementAndGet(), 2L);
threadAssertEquals(index.get(), event);
resume();
});
session.<Boolean, Long>invoke(EVENT, clientSerializer::encode, true, clientSerializer::decode).thenAccept(result -> {
threadAssertNotNull(result);
threadAssertEquals(count.incrementAndGet(), 1L);
index.set(result);
resume();
});
await(30000, 2);
}
Aggregations