use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method readOnlyQueueTailerInFollowModeShouldObserveChangesAfterInitiallyObservedReadLimit.
@Test
@Ignore("TODO FIX")
public void readOnlyQueueTailerInFollowModeShouldObserveChangesAfterInitiallyObservedReadLimit() throws Exception {
DirectoryUtils.deleteDir(dataDir.toFile());
dataDir.toFile().mkdirs();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).testBlockSize().build()) {
final StringEvents events = queue.acquireAppender().methodWriterBuilder(StringEvents.class).build();
events.say("hello");
final long readerCapacity = getCurrentQueueFileLength(dataDir);
final AtomicReference<String> messageReceiver = new AtomicReference<>();
final ChronicleReader chronicleReader = basicReader().tail().withMessageSink(messageReceiver::set);
final ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<?> submit = executorService.submit(chronicleReader::execute);
final long expectedReadingDocumentCount = (readerCapacity / ONE_KILOBYTE.length) + 1;
int i;
for (i = 0; i < expectedReadingDocumentCount; i++) {
events.say(new String(ONE_KILOBYTE));
}
events.say(LAST_MESSAGE);
while (!(messageReceiver.get() != null && messageReceiver.get().contains(LAST_MESSAGE))) {
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000L));
}
executorService.shutdownNow();
executorService.awaitTermination(5L, TimeUnit.SECONDS);
submit.get();
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method shouldReadQueueWithDifferentRollCycleWhenCreatedAfterReader.
@Test(timeout = 10_000L)
public void shouldReadQueueWithDifferentRollCycleWhenCreatedAfterReader() throws IOException, InterruptedException {
Path path = DirectoryUtils.tempDir("shouldReadQueueWithDifferentRollCycleWhenCreatedAfterReader").toPath();
path.toFile().mkdirs();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicLong recordsProcessed = new AtomicLong(0);
final ChronicleReader reader = new ChronicleReader().withBasePath(path).withMessageSink(m -> {
latch.countDown();
recordsProcessed.incrementAndGet();
});
final AtomicReference<Throwable> readerException = new AtomicReference<>();
final CountDownLatch executeLatch = new CountDownLatch(1);
final Thread readerThread = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
reader.execute();
executeLatch.countDown();
} catch (Throwable t) {
readerException.set(t);
throw t;
}
}
});
readerThread.start();
assertTrue(executeLatch.await(5, TimeUnit.SECONDS));
assertTrue(capturedOutput.isEmpty());
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).rollCycle(RollCycles.MINUTELY).build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
final MethodWriterBuilder<StringEvents> methodWriterBuilder = excerptAppender.methodWriterBuilder(StringEvents.class);
methodWriterBuilder.recordHistory(true);
final StringEvents events = methodWriterBuilder.build();
for (int i = 0; i < 24; i++) {
events.say(i % 2 == 0 ? "hello" : "goodbye");
}
}
assertTrue(latch.await(5, TimeUnit.SECONDS));
while (recordsProcessed.get() < 10) {
LockSupport.parkNanos(1L);
}
readerThread.interrupt();
assertThat(readerException.get(), is(nullValue()));
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method createQueueAndWriteData.
private void createQueueAndWriteData(MutableTimeProvider timeProvider) {
final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).testBlockSize().rollCycle(RollCycles.TEST_DAILY).timeProvider(timeProvider).build();
ExcerptAppender excerptAppender = queue.acquireAppender();
try (DocumentContext dc = excerptAppender.writingDocument(false)) {
dc.wire().write(() -> "test").int64(0);
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class PublishDeltaGenerator method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: <program> [resource-name]");
}
Jvm.setExceptionHandlers((c, m, t) -> {
System.out.println(m);
}, (c, m, t) -> {
System.out.println(m);
t.printStackTrace();
}, (c, m, t) -> System.out.println(m));
final ConfigParser configParser = new ConfigParser(args[0]);
final List<StageConfig> allStageConfigs = configParser.getAllStageConfigs();
final StageConfig lastStageConfig = allStageConfigs.get(allStageConfigs.size() - 1);
try (final SingleChronicleQueue pubQueue = SingleChronicleQueueBuilder.binary(configParser.getPublisherConfig().outputDir()).build();
final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(lastStageConfig.getOutputPath()).build();
final Writer resultsWriter = new FileWriter("publish-deltas.txt", false);
final Writer s0Pub = new FileWriter("s0-deltas.txt", false);
final Writer s1Pub = new FileWriter("s1-deltas.txt", false);
final Writer s0s2Pub = new FileWriter("s0-s2-deltas.txt", false);
final Writer s1s2Pub = new FileWriter("s1-s2-deltas.txt", false)) {
final MethodReader reader = pubQueue.createTailer().methodReader(new CapturingReceiver(resultsWriter, m -> m.publishNanos));
while (reader.readOne()) {
// report
}
final MethodReader methodReader = queue.createTailer().methodReader(new DelegatingReceiver(new CapturingReceiver(s0Pub, m -> m.t0), new CapturingReceiver(s1Pub, m -> m.t1), new CapturingReceiver(s0s2Pub, m -> m.t2, 5), new CapturingReceiver(s1s2Pub, m -> m.t2, 6)));
while (methodReader.readOne()) {
// report
}
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class PublisherMain method createOutput.
private static MethodDefinition createOutput(final Path path) {
final SingleChronicleQueue queue = outputQueue(path);
final ExcerptAppender appender = queue.acquireAppender();
return new GarbageFreeMethodPublisher(() -> appender);
}
Aggregations