Search in sources :

Example 26 with PrimitiveProxy

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);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 27 with PrimitiveProxy

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);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 28 with PrimitiveProxy

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);
    }
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 29 with PrimitiveProxy

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());
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with PrimitiveProxy

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);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

PrimitiveProxy (io.atomix.primitive.proxy.PrimitiveProxy)35 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 Test (org.junit.Test)4 Endpoint (io.atomix.messaging.Endpoint)2 BlockingAwarePrimitiveProxy (io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy)2 RecoveringPrimitiveProxy (io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy)2 RetryingPrimitiveProxy (io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy)2 Executor (java.util.concurrent.Executor)2 AtomicCounterProxy (io.atomix.core.counter.impl.AtomicCounterProxy)1 PrimitiveDescriptor (io.atomix.protocols.backup.protocol.PrimitiveDescriptor)1 PrimaryBackupProxy (io.atomix.protocols.backup.proxy.PrimaryBackupProxy)1 DefaultRaftProxy (io.atomix.protocols.raft.proxy.impl.DefaultRaftProxy)1 Scheduler (io.atomix.utils.concurrent.Scheduler)1 SingleThreadContext (io.atomix.utils.concurrent.SingleThreadContext)1 ThreadContext (io.atomix.utils.concurrent.ThreadContext)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1