use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class TestEmptyFile method shouldHandleEmptyFile.
@Test(expected = TimeoutException.class)
public void shouldHandleEmptyFile() {
Assume.assumeFalse(OS.isWindows());
try (final ChronicleQueue queue = ChronicleQueue.singleBuilder(tmpDir).testBlockSize().timeoutMS(100).readOnly(true).build()) {
ExcerptTailer tailer = queue.createTailer();
assertFalse(tailer.readingDocument().isPresent());
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class TestTailAfterRoll method doTest.
public void doTest() {
File tmpDir = getTmpDir();
File[] files;
try (ChronicleQueue writeQ = ChronicleQueue.singleBuilder(tmpDir).build()) {
ExcerptAppender appender = writeQ.acquireAppender();
long wp;
Wire wire;
try (DocumentContext dc = appender.writingDocument()) {
wire = dc.wire();
wire.write().text("hello world");
Bytes<?> bytes = wire.bytes();
wp = bytes.writePosition();
}
File dir = new File(appender.queue().fileAbsolutePath());
files = dir.listFiles(pathname -> pathname.getAbsolutePath().endsWith(".cq4"));
wire.bytes().writeInt(wp, Wires.END_OF_DATA);
appender.writeText("hello world 2");
}
Assert.assertEquals(1, files.length);
File file = files[0];
file.delete();
try (ChronicleQueue q = ChronicleQueue.singleBuilder(tmpDir).build()) {
ExcerptTailer excerptTailer = q.createTailer().toEnd();
q.acquireAppender().writeText(EXPECTED);
Assert.assertEquals(EXPECTED, excerptTailer.readText());
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleMethodReaderTest method before.
@Before
public void before() {
dataDir = getTmpDir().toPath();
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).sourceId(1).testBlockSize().build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
final VanillaMethodWriterBuilder<All> methodWriterBuilder = excerptAppender.methodWriterBuilder(All.class);
final All events = methodWriterBuilder.useMethodIds(useMethodIds).build();
for (int i = 0; i < 24; ) {
Method1Type m1 = new Method1Type();
m1.text = "hello";
m1.value = i;
m1.number = i;
events.method1(m1);
i++;
Method2Type m2 = new Method2Type();
m2.text = "goodbye";
m2.value = i;
m2.number = i;
events.method2(m2);
i++;
}
}
ignoreException("Overriding sourceId from existing metadata, was 0, overriding to");
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleWriterTest method testBytesMarshallingWithInterface.
@Test(timeout = 5000)
public void testBytesMarshallingWithInterface() throws IOException {
ChronicleWriter chronicleWriter = chronicleWriter(MyInterface2.class.getTypeName(), cw3);
chronicleWriter.execute();
try (ChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build()) {
StringBuilder sb = new StringBuilder();
@NotNull MethodReader mr = queue.createTailer().methodReader(Mocker.intercepting(MyInterface2.class, "*", sb::append));
Assert.assertTrue(mr.readOne());
Assert.assertFalse(mr.readOne());
Assert.assertEquals("*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO2 {\n" + " age: 42,\n" + " name: Percy\n" + "}\n" + "]", sb.toString());
} finally {
IOTools.deleteDirWithFiles(dir);
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleWriterTest method testWireMarshallingWithInterface.
@Test(timeout = 5000)
public void testWireMarshallingWithInterface() throws IOException {
ChronicleWriter chronicleWriter = chronicleWriter(MyInterface.class.getTypeName(), cw2);
chronicleWriter.execute();
try (ChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build()) {
StringBuilder sb = new StringBuilder();
@NotNull MethodReader mr = queue.createTailer().methodReader(Mocker.intercepting(MyInterface.class, "*", sb::append));
Assert.assertTrue(mr.readOne());
Assert.assertFalse(mr.readOne());
Assert.assertEquals("*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO {\n" + " age: 42,\n" + " name: Percy\n" + "}\n" + "]", sb.toString());
} finally {
IOTools.deleteDirWithFiles(dir);
}
}
Aggregations