use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueCloseTest method testTailAfterClose.
@Test
public void testTailAfterClose() {
final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(getTmpDir(), WireType.BINARY).build();
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(w -> w.write(TestKey.test).int32(1));
queue.close();
try {
appender.writeDocument(w -> w.write(TestKey.test).int32(2));
Assert.fail();
} catch (IllegalStateException e) {
// ok
}
}
use of net.openhft.chronicle.queue.ChronicleQueue 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.ChronicleQueue 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.ChronicleQueue 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.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class Queue36Test method testTail.
@Test
public void testTail() throws IOException {
File basePath = getTmpDir();
try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(basePath).testBlockSize().build()) {
checkNoFiles(basePath);
ExcerptTailer tailer = queue.createTailer();
checkNoFiles(basePath);
tailer.toStart();
checkNoFiles(basePath);
assertFalse(tailer.readDocument(d -> {
}));
checkNoFiles(basePath);
}
}
Aggregations