@Test public void testJournalReplay() throws Exception { JournalWriter<Quote> w = factory.writer(Quote.class); TestUtils.generateQuoteData(w, 1000); ReplayIterator<Quote> replay = new ReplayIterator<>(w, 0.00000001f); TestUtils.assertEquals(w.bufferedIterator(), replay); }
@Test public void testIncrementalInteraction() throws Exception { JournalWriter<Quote> origin = factory.writer(Quote.class, "origin"); TestUtils.generateQuoteData(origin, 200); server.start(); JournalWriter<Quote> quoteClientWriter = factory.writer(Quote.class, "client"); JournalDeltaConsumer quoteDeltaConsumer = new JournalDeltaConsumer(quoteClientWriter); // send quote journal key commandProducer.write(channel, Command.SET_KEY_CMD); setKeyRequestProducer.write(channel, new IndexedJournalKey(0, quoteWriter.getKey())); agent.process(channel); charSequenceResponseConsumer.read(channel); TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); hugeBufferConsumer.read(channel); // send quote state commandProducer.write(channel, Command.DELTA_REQUEST_CMD); journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter)); agent.process(channel); charSequenceResponseConsumer.read(channel); TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); quoteWriter.append(origin.query().all().asResultSet().subset(0, 100)); quoteWriter.commit(); commandProducer.write(channel, Command.CLIENT_READY_CMD); agent.process(channel); commandConsumer.read(channel); Assert.assertEquals(Command.JOURNAL_DELTA_CMD, commandConsumer.getValue()); Assert.assertEquals(0, intResponseConsumer.getValue(channel)); quoteDeltaConsumer.read(channel); Assert.assertEquals(100, quoteClientWriter.size()); commandConsumer.read(channel); Assert.assertEquals(Command.SERVER_READY_CMD, commandConsumer.getValue()); quoteWriter.append(origin.query().all().asResultSet().subset(100, 200)); quoteWriter.commit(); // send quote state commandProducer.write(channel, Command.DELTA_REQUEST_CMD); journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter)); agent.process(channel); charSequenceResponseConsumer.read(channel); TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue()); commandProducer.write(channel, Command.CLIENT_READY_CMD); agent.process(channel); commandConsumer.read(channel); Assert.assertEquals(Command.JOURNAL_DELTA_CMD, commandConsumer.getValue()); Assert.assertEquals(0, intResponseConsumer.getValue(channel)); quoteDeltaConsumer.read(channel); Assert.assertEquals(200, quoteClientWriter.size()); commandConsumer.read(channel); Assert.assertEquals(Command.SERVER_READY_CMD, commandConsumer.getValue()); server.halt(); }