use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method shouldReadQueueWithNonDefaultRollCycle.
@Test
public void shouldReadQueueWithNonDefaultRollCycle() {
Path path = DirectoryUtils.tempDir("shouldReadQueueWithNonDefaultRollCycle").toPath();
path.toFile().mkdirs();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).rollCycle(RollCycles.MINUTELY).testBlockSize().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");
}
}
new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
assertFalse(capturedOutput.isEmpty());
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ServiceWrapperBuilder method outputReader.
@NotNull
public MethodReader outputReader(Object... impls) {
SingleChronicleQueue queue = outputQueue();
MethodReader reader = queue.createTailer().methodReader(impls);
reader.closeIn(true);
return reader;
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ContendedWriterTest method test.
private void test(String name, Config... configs) {
System.out.println(name);
File path = DirectoryUtils.tempDir(name);
SingleChronicleQueue[] queues = new SingleChronicleQueue[configs.length];
StartAndMonitor[] startAndMonitors = new StartAndMonitor[configs.length];
try {
for (int i = 0; i < configs.length; i++) {
queues[i] = SingleChronicleQueueBuilder.binary(path).testBlockSize().progressOnContention(configs[i].progressOnContention).build();
startAndMonitors[i] = new StartAndMonitor(queues[i], Integer.toString(i), configs[i].writePause, configs[i].pauseBetweenWrites);
}
// warmup
Jvm.pause(5_000);
running.set(false);
Jvm.pause(50);
running.set(true);
for (int i = 0; i < configs.length; i++) {
startAndMonitors[i] = new StartAndMonitor(queues[i], Integer.toString(i), configs[i].writePause, configs[i].pauseBetweenWrites);
}
Jvm.pause(Jvm.isDebug() ? 30_000 : 15_000);
running.set(false);
Jvm.pause(50);
for (int i = 0; i < configs.length; i++) {
System.out.println("thread" + i + " progress=" + configs[i].progressOnContention + " writePause=" + configs[i].writePause + " between=" + configs[i].pauseBetweenWrites + ": " + startAndMonitors[i].histo.toMicrosFormat());
}
} finally {
Closeable.closeQuietly(queues);
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class CreateAtIndexTest method testWrittenAndReadIndexesAreTheSameOfTheFirstExcerpt.
// TODO: 2 or more threads soak test
@Test
public void testWrittenAndReadIndexesAreTheSameOfTheFirstExcerpt() throws Exception {
String tmp = OS.TARGET + "/" + getClass().getSimpleName() + "-" + System.nanoTime();
long expected;
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().build()) {
ExcerptAppender appender = queue.acquireAppender();
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().write().text("some-data");
expected = dc.index();
Assert.assertTrue(expected > 0);
}
appender.lastIndexAppended();
ExcerptTailer tailer = queue.createTailer();
try (DocumentContext dc = tailer.readingDocument()) {
String text = dc.wire().read().text();
{
long actualIndex = dc.index();
Assert.assertTrue(actualIndex > 0);
Assert.assertEquals(expected, actualIndex);
}
{
long actualIndex = tailer.index();
Assert.assertTrue(actualIndex > 0);
Assert.assertEquals(expected, actualIndex);
}
}
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class CreateAtIndexTest method testWriteBytesWithIndex.
@Test
public void testWriteBytesWithIndex() throws Exception {
String tmp = OS.TARGET + "/" + getClass().getSimpleName() + "-" + System.nanoTime();
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().rollCycle(TEST_DAILY).build()) {
InternalAppender appender = (InternalAppender) queue.acquireAppender();
appender.writeBytes(0x421d00000000L, HELLO_WORLD);
appender.writeBytes(0x421d00000001L, HELLO_WORLD);
}
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().build()) {
InternalAppender appender = (InternalAppender) queue.acquireAppender();
String before = queue.dump();
appender.writeBytes(0x421d00000000L, HELLO_WORLD);
String after = queue.dump();
assertEquals(before, after);
}
boolean runIfAssertsOn = false;
// assert runIfAssertsOn = true;
if (runIfAssertsOn) {
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().build()) {
InternalAppender appender = (InternalAppender) queue.acquireAppender();
String before = queue.dump();
try {
appender.writeBytes(0x421d00000000L, Bytes.from("hellooooo world"));
fail();
} catch (IllegalStateException e) {
// expected
}
String after = queue.dump();
assertEquals(before, after);
}
}
// try too far
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().build()) {
InternalAppender appender = (InternalAppender) queue.acquireAppender();
try {
appender.writeBytes(0x421d00000003L, HELLO_WORLD);
fail();
} catch (IllegalStateException e) {
assertEquals("Unable to move to index 421d00000003 beyond the end of the queue", e.getMessage());
}
}
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(tmp).testBlockSize().build()) {
InternalAppender appender = (InternalAppender) queue.acquireAppender();
appender.writeBytes(0x421d00000002L, HELLO_WORLD);
appender.writeBytes(0x421d00000003L, HELLO_WORLD);
}
try {
IOTools.deleteDirWithFiles(tmp, 2);
} catch (IORuntimeException ignored) {
}
}
Aggregations