use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class ToEndTest method toEndBeforeWriteTest.
@Test
public void toEndBeforeWriteTest() {
File baseDir = DirectoryUtils.tempDir("toEndBeforeWriteTest");
IOTools.shallowDeleteDirWithFiles(baseDir);
try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(baseDir).testBlockSize().build()) {
checkOneFile(baseDir);
// if this appender isn't created, the tailer toEnd doesn't cause a roll.
ExcerptAppender appender = queue.acquireAppender();
checkOneFile(baseDir);
ExcerptTailer tailer = queue.createTailer();
checkOneFile(baseDir);
ExcerptTailer tailer2 = queue.createTailer();
checkOneFile(baseDir);
tailer.toEnd();
checkOneFile(baseDir);
tailer2.toEnd();
checkOneFile(baseDir);
}
System.gc();
/*for (int i = 0; i < 10; i++) {
final int j = i;
appender.writeDocument(wire -> wire.write(() -> "msg").int32(j));
}*/
IOTools.shallowDeleteDirWithFiles(baseDir);
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class Queue30Test method testMT.
@Ignore("Stress test - doesn't finish")
@Test
public void testMT() throws IOException, InterruptedException {
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.text(getTmpDir()).blockSize(640_000).build()) {
ExecutorService exec = Executors.newCachedThreadPool(new NamedThreadFactory("stress"));
Throwable[] tref = { null };
Runnable r = () -> {
try {
final String name = Thread.currentThread().getName();
final ExcerptAppender appender = queue.acquireAppender();
for (int count = 0; !Thread.currentThread().isInterrupted(); count++) {
final int c = count;
appender.writeDocument(w -> w.write(() -> "thread").text(name).write(() -> "count").int32(c));
if (count % 10_000 == 0) {
LOGGER.info(name + "> " + count);
}
}
} catch (Throwable t) {
tref[0] = t;
exec.shutdown();
}
};
for (int i = 0; i < 100; i++) exec.submit(r);
exec.awaitTermination(10, TimeUnit.MINUTES);
exec.shutdownNow();
if (tref[0] != null)
throw new AssertionError(tref[0]);
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class Queue30Test method testST.
@SuppressWarnings("InfiniteLoopStatement")
@Ignore("Stress test - doesn't finish")
@Test
public void testST() throws IOException {
try (final ChronicleQueue queue = new SingleChronicleQueueBuilder(getTmpDir()).wireType(WireType.TEXT).blockSize(640_000).build()) {
final String name = Thread.currentThread().getName();
final ExcerptAppender appender = queue.acquireAppender();
for (int count = 0; ; count++) {
final int c = count;
appender.writeDocument(w -> w.write(() -> "thread").text(name).write(() -> "count").int32(c));
if (count % 50_000 == 0) {
LOGGER.info(name + "> " + count);
}
}
}
}
use of net.openhft.chronicle.queue.ExcerptAppender 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.ExcerptAppender 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);
}
}
Aggregations