Search in sources :

Example 1 with Event

use of io.atomix.primitive.event.Event 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();
    TestPrimitive primitive = createPrimitive(client);
    primitive.onEvent(event -> {
        threadAssertEquals(count.incrementAndGet(), 2L);
        threadAssertEquals(index.get(), event);
        resume();
    }).join();
    primitive.sendEvent(true).thenAccept(result -> {
        threadAssertNotNull(result);
        threadAssertEquals(count.incrementAndGet(), 1L);
        index.set(result);
        resume();
    });
    await(30000, 2);
}
Also used : RaftClusterEvent(io.atomix.protocols.raft.cluster.RaftClusterEvent) RaftMember(io.atomix.protocols.raft.cluster.RaftMember) TimeoutException(java.util.concurrent.TimeoutException) AsyncPrimitive(io.atomix.primitive.AsyncPrimitive) SessionId(io.atomix.primitive.session.SessionId) ClusterMembershipService(io.atomix.cluster.ClusterMembershipService) PrimitiveInfo(io.atomix.primitive.PrimitiveInfo) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) DefaultOperationId(io.atomix.primitive.operation.impl.DefaultOperationId) SessionMetadata(io.atomix.primitive.session.SessionMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PrimitiveConfig(io.atomix.primitive.config.PrimitiveConfig) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) Session(io.atomix.primitive.session.Session) Path(java.nio.file.Path) ConcurrentTestCase(net.jodah.concurrentunit.ConcurrentTestCase) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ProxyClient(io.atomix.primitive.proxy.ProxyClient) InitializeEntry(io.atomix.protocols.raft.storage.log.entry.InitializeEntry) PrimitiveBuilder(io.atomix.primitive.PrimitiveBuilder) PrimitiveState(io.atomix.primitive.PrimitiveState) Event(io.atomix.primitive.event.Event) Set(java.util.Set) RaftStorage(io.atomix.protocols.raft.storage.RaftStorage) Instant(java.time.Instant) CommandEntry(io.atomix.protocols.raft.storage.log.entry.CommandEntry) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SingleThreadContext(io.atomix.utils.concurrent.SingleThreadContext) ThreadContext(io.atomix.utils.concurrent.ThreadContext) PrimitiveRegistry(io.atomix.primitive.PrimitiveRegistry) Matchers.any(org.mockito.Matchers.any) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) PrimitiveService(io.atomix.primitive.service.PrimitiveService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) KeepAliveEntry(io.atomix.protocols.raft.storage.log.entry.KeepAliveEntry) MetadataEntry(io.atomix.protocols.raft.storage.log.entry.MetadataEntry) BackupOutput(io.atomix.primitive.service.BackupOutput) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) PrimitiveException(io.atomix.primitive.PrimitiveException) Serializer(io.atomix.utils.serializer.Serializer) QueryEntry(io.atomix.protocols.raft.storage.log.entry.QueryEntry) Mockito.mock(org.mockito.Mockito.mock) BackupInput(io.atomix.primitive.service.BackupInput) IntStream(java.util.stream.IntStream) SyncPrimitive(io.atomix.primitive.SyncPrimitive) OperationType(io.atomix.primitive.operation.OperationType) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) PartitionId(io.atomix.primitive.partition.PartitionId) ArrayList(java.util.ArrayList) StorageLevel(io.atomix.storage.StorageLevel) HashSet(java.util.HashSet) PrimitiveOperation(io.atomix.primitive.operation.PrimitiveOperation) Lists(com.google.common.collect.Lists) ConfigurationEntry(io.atomix.protocols.raft.storage.log.entry.ConfigurationEntry) DefaultRaftMember(io.atomix.protocols.raft.cluster.impl.DefaultRaftMember) OpenSessionEntry(io.atomix.protocols.raft.storage.log.entry.OpenSessionEntry) MemberId(io.atomix.cluster.MemberId) TestRaftProtocolFactory(io.atomix.protocols.raft.protocol.TestRaftProtocolFactory) Futures(io.atomix.utils.concurrent.Futures) Before(org.junit.Before) AbstractAsyncPrimitive(io.atomix.primitive.AbstractAsyncPrimitive) CloseSessionEntry(io.atomix.protocols.raft.storage.log.entry.CloseSessionEntry) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Command(io.atomix.primitive.operation.Command) File(java.io.File) Query(io.atomix.primitive.operation.Query) Configuration(io.atomix.protocols.raft.storage.system.Configuration) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractPrimitiveService(io.atomix.primitive.service.AbstractPrimitiveService) Namespace(io.atomix.utils.serializer.Namespace) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) PrimitiveType(io.atomix.primitive.PrimitiveType) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) SessionClient(io.atomix.primitive.session.SessionClient) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 ClusterMembershipService (io.atomix.cluster.ClusterMembershipService)1 MemberId (io.atomix.cluster.MemberId)1 AbstractAsyncPrimitive (io.atomix.primitive.AbstractAsyncPrimitive)1 AsyncPrimitive (io.atomix.primitive.AsyncPrimitive)1 PrimitiveBuilder (io.atomix.primitive.PrimitiveBuilder)1 PrimitiveException (io.atomix.primitive.PrimitiveException)1 PrimitiveInfo (io.atomix.primitive.PrimitiveInfo)1 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)1 PrimitiveRegistry (io.atomix.primitive.PrimitiveRegistry)1 PrimitiveState (io.atomix.primitive.PrimitiveState)1 PrimitiveType (io.atomix.primitive.PrimitiveType)1 SyncPrimitive (io.atomix.primitive.SyncPrimitive)1 PrimitiveConfig (io.atomix.primitive.config.PrimitiveConfig)1 Event (io.atomix.primitive.event.Event)1 Command (io.atomix.primitive.operation.Command)1 OperationType (io.atomix.primitive.operation.OperationType)1 PrimitiveOperation (io.atomix.primitive.operation.PrimitiveOperation)1 Query (io.atomix.primitive.operation.Query)1