Search in sources :

Example 1 with PrimitiveProxy

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

Example 2 with PrimitiveProxy

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

Example 3 with PrimitiveProxy

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

Example 4 with PrimitiveProxy

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

Example 5 with PrimitiveProxy

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

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