use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ResultGenerator method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: <program> [resource-name]");
}
final ConfigParser configParser = new ConfigParser(args[0]);
final List<StageConfig> allStageConfigs = configParser.getAllStageConfigs();
final StageConfig lastStageConfig = allStageConfigs.get(allStageConfigs.size() - 1);
Jvm.setExceptionHandlers((c, m, t) -> {
// System.out.println(m);
}, (c, m, t) -> {
// System.out.println(m);
if (t != null) {
t.printStackTrace();
}
}, (c, m, t) -> System.out.println(m));
try (final SingleChronicleQueue queue = ChronicleQueue.singleBuilder(lastStageConfig.getOutputPath()).build();
final Writer resultsWriter = new FileWriter("results.txt", false)) {
final MethodReader methodReader = queue.createTailer().methodReader(new CapturingReceiver(resultsWriter));
while (methodReader.readOne()) {
// report
}
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class LatinCharTest method shouldCorrectlyEncodeDecode.
@Test
public void shouldCorrectlyEncodeDecode() {
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(DirectoryUtils.tempDir("temp")).rollCycle(RollCycles.MINUTELY).build();
ExcerptAppender appender = queue.acquireAppender();
ExcerptTailer tailer = queue.createTailer("test-tailer")) {
// the é character in the line below is causing it to fail under java 11
Message expected = new Message("awésome-message-1", 1L);
appender.writeDocument(expected);
Message actual = new Message();
tailer.readDocument(actual);
assertEquals(expected, actual);
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class InternalAppenderWriteBytesTest method appendToPreviousCycle.
@Test
public void appendToPreviousCycle() {
@NotNull Bytes<byte[]> test = Bytes.from("hello world");
@NotNull Bytes<byte[]> test1 = Bytes.from("hello world again cycle1");
@NotNull Bytes<byte[]> test2 = Bytes.from("hello world cycle2");
Bytes result = Bytes.elasticHeapByteBuffer();
SetTimeProvider timeProvider = new SetTimeProvider();
try (SingleChronicleQueue q = SingleChronicleQueueBuilder.binary(getTmpDir()).timeProvider(timeProvider).rollCycle(TEST_HOURLY).build()) {
ExcerptAppender appender = q.acquireAppender();
appender.writeBytes(test);
long nextIndexInFirstCycle = appender.lastIndexAppended() + 1;
int firstCycle = q.rollCycle().toCycle(nextIndexInFirstCycle);
timeProvider.advanceMillis(TimeUnit.SECONDS.toMillis(65 * 60));
appender.writeBytes(test2);
// System.out.println(q.dump());
Assert.assertTrue(hasEOF(q, firstCycle));
// here we try and write to previous cycle file. We will overwrite the EOF in doing so
ignoreException("Incomplete header found at pos: 33048: c0000000, overwriting");
((InternalAppender) appender).writeBytes(nextIndexInFirstCycle, test1);
Assert.assertFalse(hasEOF(q, firstCycle));
// we have to manually fix. This is done by CQE at the end of backfilling
appender.normaliseEOFs();
ExcerptTailer tailer = q.createTailer();
tailer.readBytes(result);
assertEquals(test, result);
result.clear();
tailer.readBytes(result);
assertEquals(test1, result);
result.clear();
tailer.readBytes(result);
assertEquals(test2, result);
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class InternalAppenderWriteBytesTest method dontOverwriteExistingDifferentQueueInstance.
@Test
public void dontOverwriteExistingDifferentQueueInstance() {
expectException("Trying to overwrite index 0 which is before the end of the queue");
expectException("Trying to overwrite index 1 which is before the end of the queue");
@NotNull Bytes<byte[]> test = Bytes.from("hello world");
@NotNull Bytes<byte[]> test2 = Bytes.from("hello world2");
Bytes result = Bytes.elasticHeapByteBuffer();
long index;
final File tmpDir = getTmpDir();
final String expected = "" + "--- !!meta-data #binary\n" + "header: !STStore {\n" + " wireType: !WireType BINARY_LIGHT,\n" + " metadata: !SCQMeta {\n" + " roll: !SCQSRoll { length: !int 86400000, format: yyyyMMdd'T4', epoch: 0 },\n" + " deltaCheckpointInterval: 64,\n" + " sourceId: 0\n" + " }\n" + "}\n" + "# position: 176, header: 0\n" + "--- !!data #binary\n" + "listing.highestCycle: 0\n" + "# position: 216, header: 1\n" + "--- !!data #binary\n" + "listing.lowestCycle: 0\n" + "# position: 256, header: 2\n" + "--- !!data #binary\n" + "listing.modCount: 1\n" + "# position: 288, header: 3\n" + "--- !!data #binary\n" + "chronicle.write.lock: -9223372036854775808\n" + "# position: 328, header: 4\n" + "--- !!data #binary\n" + "chronicle.append.lock: -9223372036854775808\n" + "# position: 368, header: 5\n" + "--- !!data #binary\n" + "chronicle.lastIndexReplicated: -1\n" + "# position: 416, header: 6\n" + "--- !!data #binary\n" + "chronicle.lastAcknowledgedIndexReplicated: -1\n" + "...\n" + "# 130596 bytes remaining\n" + "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + " writePosition: [\n" + " 792,\n" + " 3401614098433\n" + " ],\n" + " indexing: !SCQSIndexing {\n" + " indexCount: 32,\n" + " indexSpacing: 4,\n" + " index2Index: 196,\n" + " lastIndex: 4\n" + " },\n" + " dataFormat: 1\n" + "}\n" + "# position: 196, header: -1\n" + "--- !!meta-data #binary\n" + "index2index: [\n" + " # length: 32, used: 1\n" + " 488,\n" + " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 488, header: -1\n" + "--- !!meta-data #binary\n" + "index: [\n" + " # length: 32, used: 1\n" + " 776,\n" + " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 776, header: 0\n" + "--- !!data\n" + "hello world\n" + "# position: 792, header: 1\n" + "--- !!data\n" + "hello world2\n" + "...\n" + "# 130260 bytes remaining\n";
try (SingleChronicleQueue q = createQueue(tmpDir)) {
ExcerptAppender appender = q.acquireAppender();
appender.writeBytes(test);
appender.writeBytes(test2);
index = appender.lastIndexAppended();
// assertEquals(expected, q.dump());
}
assertEquals(1, index);
// has to be the same tmpDir
try (SingleChronicleQueue q = createQueue(tmpDir)) {
InternalAppender appender = (InternalAppender) q.acquireAppender();
appender.writeBytes(0, Bytes.from("HELLO WORLD"));
// assertEquals(expected, q.dump());
appender.writeBytes(1, Bytes.from("HELLO WORLD"));
// assertEquals(expected, q.dump());
ExcerptTailer tailer = q.createTailer();
tailer.readBytes(result);
assertEquals(test, result);
assertEquals(1, tailer.index());
}
}
use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.
the class InternalAppenderWriteBytesTest method cantAppendPastTheEnd.
@Test(expected = java.lang.IllegalStateException.class)
public void cantAppendPastTheEnd() {
@NotNull Bytes<byte[]> test = Bytes.from("hello world");
try (SingleChronicleQueue q = SingleChronicleQueueBuilder.binary(getTmpDir()).timeProvider(() -> 0).build()) {
ExcerptAppender appender = q.acquireAppender();
appender.writeBytes(test);
// this will throw because it is not in sequence
((InternalAppender) appender).writeBytes(2, test);
}
}
Aggregations