Search in sources :

Example 1 with LogSession

use of io.atomix.primitive.log.LogSession in project atomix by atomix.

the class DistributedLogTest method testConsumeIndex.

@Test
public void testConsumeIndex() throws Throwable {
    createServers(3);
    DistributedLogSessionClient client1 = createClient();
    LogSession session1 = createSession(client1);
    DistributedLogSessionClient client2 = createClient();
    LogSession session2 = createSession(client2);
    for (int i = 1; i <= 10; i++) {
        session2.producer().append(String.valueOf(i).getBytes()).join();
    }
    session1.consumer().consume(10, record -> {
        threadAssertTrue(record.index() == 10);
        threadAssertTrue(Arrays.equals("10".getBytes(), record.value()));
        resume();
    });
    await(5000);
}
Also used : LogSession(io.atomix.primitive.log.LogSession) Test(org.junit.Test)

Example 2 with LogSession

use of io.atomix.primitive.log.LogSession in project atomix by atomix.

the class DistributedLogTest method testConsumeAfterSizeCompact.

@Test
public void testConsumeAfterSizeCompact() throws Throwable {
    List<DistributedLogServer> servers = createServers(3);
    DistributedLogSessionClient client1 = createClient();
    LogSession session1 = createSession(client1);
    DistributedLogSessionClient client2 = createClient();
    LogSession session2 = createSession(client2);
    Predicate<List<DistributedLogServer>> predicate = s -> s.stream().map(sr -> sr.context.journal().segments().size() > 2).reduce(Boolean::logicalOr).orElse(false);
    while (!predicate.test(servers)) {
        session1.producer().append(UUID.randomUUID().toString().getBytes());
    }
    servers.forEach(server -> server.context.compact());
    session2.consumer().consume(1, record -> {
        threadAssertTrue(record.index() > 1);
        resume();
    });
    await(5000);
}
Also used : ServiceExecutor(io.atomix.primitive.service.ServiceExecutor) Arrays(java.util.Arrays) TimeoutException(java.util.concurrent.TimeoutException) MemberGroupStrategy(io.atomix.primitive.partition.MemberGroupStrategy) SessionId(io.atomix.primitive.session.SessionId) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) Duration(java.time.Duration) PrimitiveConfig(io.atomix.primitive.config.PrimitiveConfig) After(org.junit.After) Session(io.atomix.primitive.session.Session) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ConcurrentTestCase(net.jodah.concurrentunit.ConcurrentTestCase) PrimitiveBuilder(io.atomix.primitive.PrimitiveBuilder) Predicate(java.util.function.Predicate) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) PrimitiveService(io.atomix.primitive.service.PrimitiveService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimaryElection(io.atomix.primitive.partition.PrimaryElection) BackupOutput(io.atomix.primitive.service.BackupOutput) Serializer(io.atomix.utils.serializer.Serializer) BackupInput(io.atomix.primitive.service.BackupInput) DefaultSerializers(io.atomix.utils.serializer.serializers.DefaultSerializers) CompletableFuture(java.util.concurrent.CompletableFuture) EventType(io.atomix.primitive.event.EventType) ArrayList(java.util.ArrayList) PartitionId(io.atomix.primitive.partition.PartitionId) OperationId(io.atomix.primitive.operation.OperationId) LogSession(io.atomix.primitive.log.LogSession) TestClusterMembershipService(io.atomix.cluster.TestClusterMembershipService) MemberId(io.atomix.cluster.MemberId) Futures(io.atomix.utils.concurrent.Futures) Before(org.junit.Before) TestLogProtocolFactory(io.atomix.protocols.log.protocol.TestLogProtocolFactory) Files(java.nio.file.Files) Commit(io.atomix.primitive.service.Commit) TestPrimaryElection(io.atomix.primitive.partition.TestPrimaryElection) IOException(java.io.IOException) Test(org.junit.Test) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AbstractPrimitiveService(io.atomix.primitive.service.AbstractPrimitiveService) Paths(java.nio.file.Paths) PrimitiveType(io.atomix.primitive.PrimitiveType) Assert.assertEquals(org.junit.Assert.assertEquals) LogSession(io.atomix.primitive.log.LogSession) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with LogSession

use of io.atomix.primitive.log.LogSession in project atomix by atomix.

the class DistributedLogTest method testProducerConsumer.

@Test
public void testProducerConsumer() throws Throwable {
    createServers(3);
    DistributedLogSessionClient client1 = createClient();
    LogSession session1 = createSession(client1);
    DistributedLogSessionClient client2 = createClient();
    LogSession session2 = createSession(client2);
    session1.consumer().consume(1, record -> {
        threadAssertTrue(Arrays.equals("Hello world!".getBytes(), record.value()));
        resume();
    });
    session2.producer().append("Hello world!".getBytes());
    await(5000);
}
Also used : LogSession(io.atomix.primitive.log.LogSession) Test(org.junit.Test)

Example 4 with LogSession

use of io.atomix.primitive.log.LogSession in project atomix by atomix.

the class DistributedLogTest method testConsumeAfterAgeCompact.

@Test
public void testConsumeAfterAgeCompact() throws Throwable {
    List<DistributedLogServer> servers = createServers(3);
    DistributedLogSessionClient client1 = createClient();
    LogSession session1 = createSession(client1);
    DistributedLogSessionClient client2 = createClient();
    LogSession session2 = createSession(client2);
    Predicate<List<DistributedLogServer>> predicate = s -> s.stream().map(sr -> sr.context.journal().segments().size() > 1).reduce(Boolean::logicalOr).orElse(false);
    while (!predicate.test(servers)) {
        session1.producer().append(UUID.randomUUID().toString().getBytes());
    }
    Thread.sleep(1000);
    servers.forEach(server -> server.context.compact());
    session2.consumer().consume(1, record -> {
        threadAssertTrue(record.index() > 1);
        resume();
    });
    await(5000);
}
Also used : ServiceExecutor(io.atomix.primitive.service.ServiceExecutor) Arrays(java.util.Arrays) TimeoutException(java.util.concurrent.TimeoutException) MemberGroupStrategy(io.atomix.primitive.partition.MemberGroupStrategy) SessionId(io.atomix.primitive.session.SessionId) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) Duration(java.time.Duration) PrimitiveConfig(io.atomix.primitive.config.PrimitiveConfig) After(org.junit.After) Session(io.atomix.primitive.session.Session) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ConcurrentTestCase(net.jodah.concurrentunit.ConcurrentTestCase) PrimitiveBuilder(io.atomix.primitive.PrimitiveBuilder) Predicate(java.util.function.Predicate) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) PrimitiveService(io.atomix.primitive.service.PrimitiveService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimaryElection(io.atomix.primitive.partition.PrimaryElection) BackupOutput(io.atomix.primitive.service.BackupOutput) Serializer(io.atomix.utils.serializer.Serializer) BackupInput(io.atomix.primitive.service.BackupInput) DefaultSerializers(io.atomix.utils.serializer.serializers.DefaultSerializers) CompletableFuture(java.util.concurrent.CompletableFuture) EventType(io.atomix.primitive.event.EventType) ArrayList(java.util.ArrayList) PartitionId(io.atomix.primitive.partition.PartitionId) OperationId(io.atomix.primitive.operation.OperationId) LogSession(io.atomix.primitive.log.LogSession) TestClusterMembershipService(io.atomix.cluster.TestClusterMembershipService) MemberId(io.atomix.cluster.MemberId) Futures(io.atomix.utils.concurrent.Futures) Before(org.junit.Before) TestLogProtocolFactory(io.atomix.protocols.log.protocol.TestLogProtocolFactory) Files(java.nio.file.Files) Commit(io.atomix.primitive.service.Commit) TestPrimaryElection(io.atomix.primitive.partition.TestPrimaryElection) IOException(java.io.IOException) Test(org.junit.Test) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AbstractPrimitiveService(io.atomix.primitive.service.AbstractPrimitiveService) Paths(java.nio.file.Paths) PrimitiveType(io.atomix.primitive.PrimitiveType) Assert.assertEquals(org.junit.Assert.assertEquals) LogSession(io.atomix.primitive.log.LogSession) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

LogSession (io.atomix.primitive.log.LogSession)4 Test (org.junit.Test)4 MemberId (io.atomix.cluster.MemberId)2 TestClusterMembershipService (io.atomix.cluster.TestClusterMembershipService)2 PrimitiveBuilder (io.atomix.primitive.PrimitiveBuilder)2 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)2 PrimitiveType (io.atomix.primitive.PrimitiveType)2 PrimitiveConfig (io.atomix.primitive.config.PrimitiveConfig)2 EventType (io.atomix.primitive.event.EventType)2 OperationId (io.atomix.primitive.operation.OperationId)2 MemberGroupStrategy (io.atomix.primitive.partition.MemberGroupStrategy)2 PartitionId (io.atomix.primitive.partition.PartitionId)2 PrimaryElection (io.atomix.primitive.partition.PrimaryElection)2 TestPrimaryElection (io.atomix.primitive.partition.TestPrimaryElection)2 AbstractPrimitiveService (io.atomix.primitive.service.AbstractPrimitiveService)2 BackupInput (io.atomix.primitive.service.BackupInput)2 BackupOutput (io.atomix.primitive.service.BackupOutput)2 Commit (io.atomix.primitive.service.Commit)2 PrimitiveService (io.atomix.primitive.service.PrimitiveService)2 ServiceConfig (io.atomix.primitive.service.ServiceConfig)2