use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class RollCycleMultiThreadTest method testRead1.
@Test
public void testRead1() throws Exception {
File path = DirectoryUtils.tempDir(getClass().getSimpleName());
TestTimeProvider timeProvider = new TestTimeProvider();
try (ChronicleQueue queue0 = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
ParallelQueueObserver observer = new ParallelQueueObserver(queue0);
final ExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
ExcerptAppender appender = queue.acquireAppender();
Assert.assertEquals(0, (int) scheduledExecutorService.submit(observer::call).get());
// two days pass
timeProvider.add(TimeUnit.DAYS.toMillis(2));
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("Day 3 data");
}
Assert.assertEquals(1, (int) scheduledExecutorService.submit(observer::call).get());
assertEquals(1, observer.documentsRead);
}
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class RollCycleTest method newRollCycleIgnored.
@Test
public void newRollCycleIgnored() throws Exception {
File path = DirectoryUtils.tempDir("newRollCycleIgnored");
SetTimeProvider timeProvider = new SetTimeProvider();
ParallelQueueObserver observer = new ParallelQueueObserver(timeProvider, path.toPath());
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(RollCycles.DAILY).timeProvider(timeProvider).build()) {
ExcerptAppender appender = queue.acquireAppender();
Thread thread = new Thread(observer);
thread.start();
observer.await();
// two days pass
timeProvider.advanceMillis(TimeUnit.DAYS.toMillis(2));
appender.writeText("0");
// allow parallel tailer to finish iteration
for (int i = 0; i < 5_000 && observer.documentsRead != 1; i++) {
Thread.sleep(1);
}
thread.interrupt();
}
assertEquals(1, observer.documentsRead);
observer.queue.close();
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class RollCycleTest method newRollCycleIgnored2.
@Test
public void newRollCycleIgnored2() throws Exception {
File path = DirectoryUtils.tempDir("newRollCycleIgnored2");
SetTimeProvider timeProvider = new SetTimeProvider();
ParallelQueueObserver observer = new ParallelQueueObserver(timeProvider, path.toPath());
int cyclesToWrite = 100;
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(RollCycles.DAILY).timeProvider(timeProvider).build()) {
ExcerptAppender appender = queue.acquireAppender();
appender.writeText("0");
Thread thread = new Thread(observer);
thread.start();
observer.await();
for (int i = 1; i <= cyclesToWrite; i++) {
// two days pass
timeProvider.advanceMillis(TimeUnit.DAYS.toMillis(2));
appender.writeText(Integer.toString(i));
}
// allow parallel tailer to finish iteration
for (int i = 0; i < 5_000 && observer.documentsRead != 1 + cyclesToWrite; i++) {
Thread.sleep(1);
}
thread.interrupt();
}
assertEquals(1 + cyclesToWrite, observer.documentsRead);
observer.queue.close();
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueStoreTest method shouldPerformIndexingOnAppend.
@Test
public void shouldPerformIndexingOnAppend() throws Exception {
runTest(queue -> {
final ExcerptAppender appender = queue.acquireAppender();
appender.lazyIndexing(false);
final long[] indices = writeMessagesStoreIndices(appender, queue.createTailer());
assertExcerptsAreIndexed(queue, indices, i -> i % INDEX_SPACING == 0, ScanResult.FOUND);
});
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueStoreTest method shouldPerformIndexingOnRead.
@Test
public void shouldPerformIndexingOnRead() throws Exception {
runTest(queue -> {
final ExcerptAppender appender = queue.acquireAppender();
appender.lazyIndexing(true);
final long[] indices = writeMessagesStoreIndices(appender, queue.createTailer().indexing(true));
assertExcerptsAreIndexed(queue, indices, i -> i % INDEX_SPACING == 0, ScanResult.FOUND);
});
}
Aggregations