Search in sources :

Example 31 with PrimitiveProxy

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

Example 32 with PrimitiveProxy

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

Example 33 with PrimitiveProxy

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

Example 34 with PrimitiveProxy

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

Example 35 with PrimitiveProxy

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);
}
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