use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class ChronicleWriterTest method testWireMarshallingMapAndDTO.
@Test(timeout = 5000)
public void testWireMarshallingMapAndDTO() throws IOException {
ChronicleWriter chronicleWriter = chronicleWriter(null, cw1, 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.assertTrue(mr.readOne());
Assert.assertFalse(mr.readOne());
Assert.assertEquals("*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO {\n" + " age: 19,\n" + " name: Henry\n" + "}\n" + "]*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO {\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 QueueWriteJitterMain method run.
protected void run() {
MappedFile.warmup();
String path = "test-q-" + Time.uniqueId();
System.out.println("Writing to " + path);
Thread pretoucher = new Thread(() -> {
try (ChronicleQueue q = createQueue(path)) {
ExcerptAppender appender = q.acquireAppender();
while (true) {
Thread.sleep(50);
appender.pretouch();
}
} catch (InterruptedException ie) {
if (running)
ie.printStackTrace();
}
});
pretoucher.setDaemon(true);
pretoucher.start();
Thread writer = new Thread(() -> {
try (ChronicleQueue q = createQueue(path)) {
ExcerptAppender appender = q.acquireAppender();
while (running) {
writeStarted = System.nanoTime();
Jvm.safepoint();
try (DocumentContext dc = appender.writingDocument(false)) {
Jvm.safepoint();
Bytes<?> bytes = dc.wire().bytes();
for (int i = 0; i < size; i += 8) bytes.writeLong(i);
Jvm.safepoint();
}
Jvm.safepoint();
writeStarted = Long.MAX_VALUE;
waitForNext(Math.min(100, sampleTime));
}
}
});
writer.setDaemon(true);
writer.start();
// give it time to start
Jvm.pause(100);
try (ChronicleQueue q = createQueue(path)) {
ExcerptTailer tailer = q.createTailer();
long start0 = System.currentTimeMillis();
do {
if (writeStarted < Long.MAX_VALUE) {
// overflow exists loop
while (writeStarted + sampleTime * 1000 > System.nanoTime()) Thread.yield();
if (writeStarted < Long.MAX_VALUE) {
StackTraceElement[] stes = writer.getStackTrace();
if (!stes[1].getMethodName().equals("waitForNext")) {
StringBuilder sb = new StringBuilder();
sb.append(PROFILE_OF_THE_THREAD);
Jvm.trimStackTrace(sb, stes);
System.out.println(sb);
}
}
}
try (DocumentContext dc = tailer.readingDocument()) {
if (!dc.isPresent())
waitForNext(Math.min(100, sampleTime));
}
Thread.yield();
} while (System.currentTimeMillis() < start0 + runTime * 1_000);
}
running = false;
pretoucher.interrupt();
IOTools.deleteDirWithFiles(path, 2);
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testLastWrittenIndexPerAppenderNoData.
@Test(expected = IllegalStateException.class)
public void testLastWrittenIndexPerAppenderNoData() {
final File file = createTempFile("testLastWrittenIndexPerAppenderNoData");
try {
final ChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
appender.lastWrittenIndex();
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueueTest method testLastWrittenIndexPerAppender.
@Test
public void testLastWrittenIndexPerAppender() {
final File file = createTempFile("testLastWrittenIndexPerAppender");
try {
final ChronicleQueue chronicle = createQueue(file);
final ExcerptAppender appender = chronicle.acquireAppender();
appender.writeDocument(wire -> wire.write("key").text("test"));
Assert.assertEquals(0, appender.lastWrittenIndex());
} finally {
file.delete();
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.
the class StagedPerformanceMain method runBenchmark.
private static void runBenchmark(int count, int interval, boolean warmup) {
String run = Long.toString(System.nanoTime(), 36);
WARMUP = warmup;
DIR = PATH + "/run-" + run;
new File(DIR).mkdirs();
// every 60 seconds.
REPORT_INTERVAL = (int) (60e9 / interval);
try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(DIR + "/data").build()) {
q0 = queue;
List<Runnable> runnables = new ArrayList<>();
runnables.add(() -> producer(count, interval));
runnables.add(() -> firstStage());
for (int s = 2; s <= STAGES; s++) {
int finalS = s;
runnables.add(() -> runStage(finalS));
}
runnables.stream().parallel().forEach(Runnable::run);
Histogram latencies = new Histogram();
reportLatenciesForStage(STAGES, latencies);
}
IOTools.deleteDirWithFiles(DIR, 3);
}
Aggregations