use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class ChronicleQueueMethodsWithoutParameters method test.
@Test
public void test() throws IOException, InterruptedException {
File file = getTmpDir();
try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(file).testBlockSize().rollCycle(TEST_DAILY).build()) {
SomeListener someListener = queue.acquireAppender().methodWriter(SomeListener.class);
SomeManager someManager = new SomeManager();
MethodReader reader = queue.createTailer().methodReader(someManager);
LOG.debug("Writing to queue");
someListener.methodWithOneParam(1);
someListener.methodWithoutParams();
LOG.debug("Reading from queue");
assertTrue(reader.readOne());
assertTrue(reader.readOne());
assertFalse(reader.readOne());
// one param method was invoked
assertTrue(someManager.methodWithOneParamInvoked);
// no params method was NOT invoked
assertTrue(someManager.methodWithoutParamsInvoked);
LOG.warn(queue.dump());
}
}
use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class JDBCServiceTest method doCreateTable.
public void doCreateTable(int repeats, int noUpdates) throws SQLException {
for (int t = 0; t < repeats; t++) {
long start = System.nanoTime(), written;
File path1 = DirectoryUtils.tempDir("createTable1");
File path2 = DirectoryUtils.tempDir("createTable2");
File file = new File(OS.TARGET, "hsqldb-" + System.nanoTime());
file.deleteOnExit();
try (ChronicleQueue in = SingleChronicleQueueBuilder.binary(path1).testBlockSize().build();
ChronicleQueue out = SingleChronicleQueueBuilder.binary(path2).testBlockSize().build()) {
JDBCService service = new JDBCService(in, out, () -> DriverManager.getConnection("jdbc:hsqldb:file:" + file.getAbsolutePath(), "SA", ""));
JDBCStatement writer = service.createWriter();
writer.executeUpdate("CREATE TABLE tableName (\n" + "name VARCHAR(64) NOT NULL,\n" + "num INT\n" + ")\n");
for (int i = 1; i < (long) noUpdates; i++) writer.executeUpdate("INSERT INTO tableName (name, num)\n" + "VALUES (?, ?)", "name", i);
written = System.nanoTime() - start;
AtomicLong queries = new AtomicLong();
AtomicLong updates = new AtomicLong();
CountingJDBCResult countingJDBCResult = new CountingJDBCResult(queries, updates);
MethodReader methodReader = service.createReader(countingJDBCResult);
int counter = 0;
while (updates.get() < noUpdates) {
if (methodReader.readOne())
counter++;
else
Thread.yield();
}
Closeable.closeQuietly(service);
// System.out.println(in.dump());
// System.out.println(out.dump());
long time = System.nanoTime() - start;
System.out.printf("Average time to write each update %.1f us, average time to perform each update %.1f us%n", written / noUpdates / 1e3, time / noUpdates / 1e3);
} finally {
try {
IOTools.deleteDirWithFiles(path1, 2);
IOTools.deleteDirWithFiles(path2, 2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class MessageHistoryTest method shouldAccessMessageHistory.
@Test
public void shouldAccessMessageHistory() throws Exception {
try (final SingleChronicleQueue inputQueue = createQueue(inputQueueDir, 1);
final SingleChronicleQueue outputQueue = createQueue(outputQueueDir, 2)) {
generateTestData(inputQueue, outputQueue);
final ExcerptTailer tailer = outputQueue.createTailer();
final ValidatingSecond validatingSecond = new ValidatingSecond();
final MethodReader validator = tailer.methodReader(validatingSecond);
assertThat(validator.readOne(), is(true));
assertThat(validatingSecond.messageHistoryPresent(), is(true));
}
}
use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class MessageHistoryTest method generateTestData.
private void generateTestData(final SingleChronicleQueue inputQueue, final SingleChronicleQueue outputQueue) {
final First first = inputQueue.acquireAppender().methodWriterBuilder(First.class).recordHistory(true).build();
first.say("one");
first.say("two");
first.say("three");
final LoggingFirst loggingFirst = new LoggingFirst(outputQueue.acquireAppender().methodWriterBuilder(Second.class).build());
final MethodReader reader = inputQueue.createTailer().methodReaderBuilder().build(loggingFirst);
assertThat(reader.readOne(), is(true));
assertThat(reader.readOne(), is(true));
// roll queue file
clock.addAndGet(TimeUnit.DAYS.toMillis(2));
assertThat(reader.readOne(), is(true));
assertThat(reader.readOne(), is(false));
}
use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class StageMain method main.
public static void main(String[] args) throws IOException {
// MlockAll.doMlockall();
if (args.length != 2) {
throw new IllegalArgumentException("Usage: <program> [resource-name] [stage-index]");
}
final ConfigParser configParser = new ConfigParser(args[0]);
final StageConfig stageConfig = configParser.getStageConfig(Integer.parseInt(args[1]));
final ExecutorService service = Executors.newFixedThreadPool(stageConfig.getStageIndices().size() + 1);
service.submit(new PretoucherTask(outputQueue(stageConfig.getOutputPath(), UNSET_SOURCE), configParser.getPretouchIntervalMillis()));
for (Integer index : stageConfig.getStageIndices()) {
service.submit(() -> {
final Stage stage = new Stage(createOutput(stageConfig.getOutputPath(), index + 1), index);
final MethodReader reader = createReader(stageConfig.getInputPath(), stage);
Thread.currentThread().setName("load.stage-consumer-" + index);
boolean warnOnce = false;
while (!Thread.currentThread().isInterrupted()) {
try {
reader.readOne();
} catch (Exception e) {
if (!warnOnce) {
e.printStackTrace();
warnOnce = true;
}
}
}
});
}
}
Aggregations