use of net.openhft.chronicle.wire.DocumentContext in project kie-wb-common by kiegroup.
the class ClientIPCImpl method readThisDocument.
private DefaultKieCompilationResponseOffProcess readThisDocument(ExcerptTailer tailer) {
if (logger.isDebugEnabled()) {
logger.debug("current index on readThisDocument:{}", tailer.index());
}
DefaultKieCompilationResponseOffProcess res = null;
try (DocumentContext dc = tailer.readingDocument()) {
if (dc.isPresent()) {
if (logger.isDebugEnabled()) {
logger.debug("Document Context index:{}", dc.index());
}
Wire wire = dc.wire();
Bytes bytes = wire.bytes();
if (!bytes.isEmpty()) {
try {
Object obj = deserialize(bytes.toByteArray());
res = (DefaultKieCompilationResponseOffProcess) obj;
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}
if (res == null) {
res = new DefaultKieCompilationResponseOffProcess(false, "");
}
return res;
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class StuckQueueTest method test.
@Test
public void test() throws IOException {
// todo remove see https://github.com/OpenHFT/Chronicle-Queue/issues/837
assumeFalse(Jvm.isMacArm());
// java.nio.file.InvalidPathException: Illegal char <:> at index 2: /D:/BuildAgent/work/1e5875c1db7235db/target/test-classes/stuck.queue.test/20180508-1249.cq4
assumeFalse(OS.isWindows());
Path tmpDir = getTmpDir().toPath();
expectException("Failback to readonly tablestore");
expectException("reading control code as text");
// expectException("Unable to copy TimedStoreRecovery safely will try anyway");
// expectException("Unable to copy SCQStore safely will try anyway");
// expectException("Unable to copy SCQSRoll safely");
// expectException("Unable to copy SCQSIndexing safely");
tmpDir.toFile().mkdirs();
Path templatePath = Paths.get(StuckQueueTest.class.getResource("/stuck.queue.test/20180508-1249.cq4").getFile());
Path to = tmpDir.resolve(templatePath.getFileName());
Files.copy(templatePath, to, StandardCopyOption.REPLACE_EXISTING);
try (RollingChronicleQueue q = ChronicleQueue.singleBuilder(tmpDir).rollCycle(RollCycles.MINUTELY).readOnly(true).build();
ExcerptTailer tailer = q.createTailer()) {
// System.out.println(q.dump());
int cycle = q.rollCycle().toCycle(0x18406e100000000L);
try (SingleChronicleQueueStore wireStore = q.storeForCycle(cycle, q.epoch(), false, null)) {
String absolutePath = wireStore.file().getAbsolutePath();
// System.out.println(absolutePath);
Assert.assertTrue(absolutePath.endsWith("20180508-1249.cq4"));
}
try (DocumentContext dc = tailer.readingDocument()) {
// Assert.assertTrue(!dc.isPresent());
// System.out.println(Long.toHexString(dc.index()));
}
// Assert.assertTrue(tailer.moveToIndex(0x183efe300000000L));
try (final SingleChronicleQueue q2 = ChronicleQueue.singleBuilder(tmpDir).rollCycle(RollCycles.MINUTELY).build()) {
try (DocumentContext dc = q2.acquireAppender().writingDocument()) {
dc.wire().write("hello").text("world");
}
}
ExcerptTailer tailer2 = q.createTailer();
try (DocumentContext dc = tailer2.readingDocument()) {
Assert.assertTrue(dc.isPresent());
String actual = dc.wire().read("hello").text();
Assert.assertEquals("world", actual);
// System.out.println(Long.toHexString(dc.index()));
}
}
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class TailerIndexingQueueTest method tailerShouldBeAbleToMoveBackwardFromEndOfCycle.
@Test
public void tailerShouldBeAbleToMoveBackwardFromEndOfCycle() throws IOException {
assumeFalse(OS.isWindows());
try (final ChronicleQueue queue = createQueue(path, clock::get)) {
final ExcerptAppender appender = queue.acquireAppender();
// generate some cycle files
range(0, 5).forEach(i -> {
try (final DocumentContext ctx = appender.writingDocument()) {
ctx.wire().write().int32(i);
clock.addAndGet(TimeUnit.SECONDS.toMillis(10L));
}
});
}
// remove all but the first file
try (Stream<Path> list = Files.list(this.path.toPath());
Stream<Path> list2 = Files.list(this.path.toPath())) {
final Path firstFile = list.sorted(Comparator.comparing(Path::toString)).findFirst().orElseThrow(AssertionError::new);
list2.filter(p -> !p.equals(firstFile)).forEach(TailerIndexingQueueTest::deleteFile);
try (final ChronicleQueue queue = createQueue(path, SystemTimeProvider.INSTANCE)) {
final ExcerptTailer tailer = queue.createTailer().toEnd();
// move to END_OF_CYCLE
try (final DocumentContext readCtx = tailer.readingDocument()) {
assertFalse(readCtx.isPresent());
}
assertEquals(TailerState.END_OF_CYCLE, tailer.state());
tailer.direction(TailerDirection.BACKWARD);
tailer.toEnd();
assertTrue(tailer.readingDocument().isPresent());
}
}
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class ToEndTest method missingCyclesToEndTest.
@Test
public void missingCyclesToEndTest() {
String path = OS.getTarget() + "/missingCyclesToEndTest-" + Time.uniqueId();
IOTools.shallowDeleteDirWithFiles(path);
final SetTimeProvider timeProvider = new SetTimeProvider();
long now = 1470757797000L;
long timeIncMs = 1001;
timeProvider.currentTimeMillis(now);
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).testBlockSize().rollCycle(RollCycles.TEST4_SECONDLY).timeProvider(timeProvider).build()) {
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(wire -> wire.write("msg").int32(1));
// roll
timeProvider.currentTimeMillis(now += timeIncMs);
appender.writeDocument(wire -> wire.write("msg").int32(2));
appender.writeDocument(wire -> wire.write("msg").int32(3));
final ExcerptTailer tailer = queue.createTailer().toEnd();
try (DocumentContext dc = tailer.readingDocument()) {
if (dc.isPresent()) {
fail("Should be at the end of the queue but dc.isPresent and we read: " + dc.wire().read("msg").int32());
}
}
// append same cycle.
appender.writeDocument(wire -> wire.write("msg").int32(4));
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue("Should be able to read entry in this cycle. Got NoDocumentContext.", dc.isPresent());
int i = dc.wire().read("msg").int32();
assertEquals("Should've read 4, instead we read: " + i, 4, i);
}
// read from the beginning
tailer.toStart();
for (int j = 1; j <= 4; j++) {
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue(dc.isPresent());
int i = dc.wire().read("msg").int32();
assertEquals(j, i);
}
}
try (DocumentContext dc = tailer.readingDocument()) {
if (dc.isPresent()) {
fail("Should be at the end of the queue but dc.isPresent and we read: " + String.valueOf(dc.wire().read("msg").int32()));
}
}
// write another
appender.writeDocument(wire -> wire.write("msg").int32(5));
// roll 5 cycles
timeProvider.currentTimeMillis(now += timeIncMs * 5);
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue(dc.isPresent());
assertEquals(5, dc.wire().read("msg").int32());
}
try (DocumentContext dc = tailer.readingDocument()) {
assertFalse(dc.isPresent());
}
}
}
use of net.openhft.chronicle.wire.DocumentContext in project Chronicle-Queue by OpenHFT.
the class StoreAppenderDoubleBufferTest method testDoubleBuffering.
// @Test(timeout = 10000L)
public void testDoubleBuffering() throws InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
try (SingleChronicleQueue q = binary(tempDir("q")).doubleBuffer(true).rollCycle(MINUTELY).timeProvider(() -> 0).build()) {
BlockedWriterScenario blockedWriterScenario = scenarioClass.getConstructor(ChronicleQueue.class, Integer.class).newInstance(q, iterations);
blockedWriterScenario.run();
ExcerptTailer tailer = q.createTailer();
for (int i = 0; i < iterations; i++) {
try (DocumentContext dc = tailer.readingDocument()) {
assertEquals("blocker-before", dc.wire().read().text());
assertEquals("blocker-after", dc.wire().read().text());
}
blockedWriterScenario.readBlockeeRecordForIteration(i, tailer);
}
// Test we're at the end
try (DocumentContext dc = tailer.readingDocument()) {
assertFalse(dc.isPresent());
}
}
}
Aggregations