use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class PeekDocumentTest method test2.
@Test
public void test2() {
File tempDir = getTmpDir();
try {
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tempDir).build()) {
ExcerptAppender appender = queue.acquireAppender();
appender.writeText("hello1");
appender.writeText("hello2");
ExcerptTailer tailer = queue.createTailer();
long address1a = Jvm.getValue(tailer, "address");
assertTrue(tailer.moveToIndex(tailer.index() + 1));
long address1b = Jvm.getValue(tailer, "address");
assertNotEquals(address1a, address1b);
assertFalse(tailer.moveToIndex(tailer.index() + 1));
long address1c = Jvm.getValue(tailer, "address");
assertEquals(address1c, NoBytesStore.NO_PAGE);
}
} finally {
tempDir.deleteOnExit();
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class PeekDocumentTest method testReadWrite.
@Test
public void testReadWrite() {
File tempDir = getTmpDir();
try {
Bytes<byte[]> bytes = from(EXPECTED_MESSAGE);
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tempDir).build()) {
ExcerptAppender appender = queue.acquireAppender();
appender.writeText("hello");
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.peekDocument());
}
} finally {
tempDir.deleteOnExit();
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class PeekDocumentTest method testWhenNoDocument.
@Test
public void testWhenNoDocument() {
File tempDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir).build()) {
ExcerptTailer tailer = queue.createTailer();
ExcerptAppender appender = queue.acquireAppender();
// peekDocumentBeforeWrite should be false.but returns true
boolean peekDocumentBeforeWrite = tailer.peekDocument();
assertFalse(peekDocumentBeforeWrite);
try (DocumentContext dc = appender.writingDocument()) {
dc.wire().writeText("testString");
}
boolean peekDocumentAfterWrite = tailer.peekDocument();
assertTrue(peekDocumentAfterWrite);
String text = null;
try (DocumentContext dc = tailer.readingDocument()) {
text = dc.wire().readText();
}
assertEquals("testString", text);
boolean peekDocumentAfterRead = tailer.peekDocument();
assertFalse(peekDocumentAfterRead);
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class IgnoreMethodBasedOnFirstArgTest method testIgnoreMethodBasedOnFirstArg.
@Test
public void testIgnoreMethodBasedOnFirstArg() {
try (SingleChronicleQueue build = SingleChronicleQueueBuilder.binary(DirectoryUtils.tempDir("q")).build()) {
Printer printer = build.acquireAppender().methodWriter(Printer.class);
printer.print(EXPECTED_ENVELOPE, MSG);
MethodReader mr = build.createTailer().methodReaderBuilder().build(new Printer() {
@Override
public boolean ignoreMethodBasedOnFirstArg(final String methodName, final Object firstArg) {
assertEquals(EXPECTED_ENVELOPE, firstArg);
return false;
}
@Override
public void print(String envelope, final String msg) {
assertEquals(EXPECTED_ENVELOPE, envelope);
assertEquals(MSG, msg);
}
});
mr.readOne();
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class StridingAQueueTest method testStriding.
@Test
public void testStriding() {
SetTimeProvider timeProvider = new SetTimeProvider();
timeProvider.currentTimeMillis(1_567_498_753_000L);
File tmpDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir).testBlockSize().timeProvider(timeProvider).rollCycle(RollCycles.TEST4_SECONDLY).build()) {
SAQMessage writer = queue.acquireAppender().methodWriter(SAQMessage.class);
for (int j = 1; j <= 4; j++) {
for (int i = 0; i < 6 + j; i++) writer.hi(j, i);
timeProvider.advanceMillis(j * 500);
// System.out.println(timeProvider.currentTimeMillis());
}
}
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir).testBlockSize().timeProvider(timeProvider).rollCycle(RollCycles.TEST4_SECONDLY).build()) {
assertEquals(getExpected(), queue.dump().replaceAll("(?m)^#.+$\\n", ""));
StringWriter sw = new StringWriter();
ExcerptTailer tailer = queue.createTailer().direction(TailerDirection.BACKWARD).toEnd().striding(true);
MethodReader reader = tailer.methodReader(Mocker.logging(SAQMessage.class, "", sw));
while (reader.readOne()) ;
assertEquals("hi[4, 9]\n" + "hi[4, 8]\n" + "hi[4, 4]\n" + "hi[4, 0]\n" + "hi[3, 8]\n" + "hi[3, 4]\n" + "hi[3, 0]\n" + "hi[2, 7]\n" + "hi[2, 5]\n" + "hi[2, 1]\n" + "hi[1, 4]\n" + "hi[1, 0]\n", sw.toString().replace("\r", ""));
}
}
Aggregations