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