Search in sources :

Example 6 with PrimitiveProxy

use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.

the class RaftTest method testEvents.

/**
 * Tests submitting sequential events to all sessions.
 */
private void testEvents(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();
    });
    session.invoke(EVENT, clientSerializer::encode, false).thenRun(this::resume);
    await(30000, 4);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 7 with PrimitiveProxy

use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.

the class RaftTest method testEventsAfterLeaderKill.

/**
 * Tests submitting a linearizable event that publishes to all sessions.
 */
private void testEventsAfterLeaderKill(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 leader = servers.stream().filter(s -> s.getRole() == RaftServer.Role.LEADER).findFirst().get();
    leader.shutdown().get(10, TimeUnit.SECONDS);
    await(30000);
    for (int i = 0; i < 10; i++) {
        session.invoke(EVENT, clientSerializer::encode, true).thenRun(this::resume);
        await(30000, 2);
    }
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 8 with PrimitiveProxy

use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.

the class RaftTest method testSessionExpire.

/**
 * Tests a session expiring.
 */
private void testSessionExpire(int nodes) throws Throwable {
    createServers(nodes);
    RaftClient client1 = createClient();
    PrimitiveProxy session1 = createSession(client1);
    RaftClient client2 = createClient();
    createSession(client2);
    session1.addEventListener(EXPIRE_EVENT, this::resume);
    session1.invoke(EXPIRE).thenRun(this::resume);
    client2.close().thenRun(this::resume);
    await(Duration.ofSeconds(10).toMillis(), 3);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 9 with PrimitiveProxy

use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.

the class RaftTest method testSubmitCommand.

/**
 * Tests submitting a command with a configured consistency level.
 */
private void testSubmitCommand(int nodes) throws Throwable {
    createServers(nodes);
    RaftClient client = createClient();
    PrimitiveProxy session = createSession(client);
    session.invoke(WRITE).thenRun(this::resume);
    await(30000);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 10 with PrimitiveProxy

use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.

the class RaftTest method testClientKeepAlive.

/**
 * Tests keeping a client session alive.
 */
@Test
public void testClientKeepAlive() throws Throwable {
    createServers(3);
    RaftClient client = createClient();
    PrimitiveProxy session = createSession(client);
    Thread.sleep(Duration.ofSeconds(10).toMillis());
    threadAssertTrue(session.getState() == PrimitiveProxy.State.CONNECTED);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) Test(org.junit.Test)

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