use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.
the class AbstractEventJournalBasicTest method allowReadingWithFutureSeq.
@Test
public void allowReadingWithFutureSeq() throws Exception {
final EventJournalTestContext<String, Integer, EJ_TYPE> context = createContext();
final EventJournalInitialSubscriberState state = subscribeToEventJournal(context.dataAdapter, partitionId);
assertEquals(0, state.getOldestSequence());
assertEquals(-1, state.getNewestSequence());
assertEventJournalSize(context.dataAdapter, 0);
final Integer value = RANDOM.nextInt();
final CountDownLatch latch = new CountDownLatch(1);
final int startSequence = 1;
final BiConsumer<ReadResultSet<EJ_TYPE>, Throwable> callback = (response, t) -> {
if (t == null) {
latch.countDown();
assertEquals(1, response.size());
final EventJournalEventAdapter<String, Integer, EJ_TYPE> journalAdapter = context.eventJournalAdapter;
final EJ_TYPE e = response.get(0);
assertEquals(ADDED, journalAdapter.getType(e));
assertEquals(value, journalAdapter.getNewValue(e));
} else {
rethrow(t);
}
};
CompletionStage<ReadResultSet<EJ_TYPE>> callbackStage = readFromEventJournal(context.dataAdapter, startSequence, 1, partitionId, TRUE_PREDICATE, IDENTITY_FUNCTION).whenCompleteAsync(callback);
assertTrueEventually(() -> {
context.dataAdapter.put(randomPartitionKey(), value);
assertTrue(latch.await(200, TimeUnit.MILLISECONDS));
}, 30);
// ensure no exception thrown from callback
callbackStage.toCompletableFuture().join();
}
use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.
the class ClientCacheProxy method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
eventJournalReadResponseDecoder = message -> {
final CacheEventJournalReadCodec.ResponseParameters params = CacheEventJournalReadCodec.decodeResponse(message);
final ReadResultSetImpl resultSet = new ReadResultSetImpl<>(params.readCount, params.items, params.itemSeqs, params.nextSeq);
resultSet.setSerializationService(getSerializationService());
return resultSet;
};
eventJournalSubscribeResponseDecoder = message -> {
final ResponseParameters resp = CacheEventJournalSubscribeCodec.decodeResponse(message);
return new EventJournalInitialSubscriberState(resp.oldestSequence, resp.newestSequence);
};
}
use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.
the class AbstractEventJournalBasicTest method nextSequenceProceedsWhenReadFromEventJournalWhileMinSizeIsZero.
@Test
public void nextSequenceProceedsWhenReadFromEventJournalWhileMinSizeIsZero() throws Exception {
final EventJournalTestContext<String, Integer, EJ_TYPE> context = createContext();
final int count = 1000;
assertEventJournalSize(context.dataAdapter, 0);
for (int i = 0; i < count; i++) {
context.dataAdapter.put(randomPartitionKey(), i);
}
final EventJournalInitialSubscriberState state = subscribeToEventJournal(context.dataAdapter, partitionId);
assertEquals(500, state.getOldestSequence());
assertEquals(999, state.getNewestSequence());
assertEventJournalSize(context.dataAdapter, 500);
final int startSequence = 0;
final ReadResultSet<EJ_TYPE> resultSet = readFromEventJournal(context.dataAdapter, startSequence, 1, 0, partitionId, TRUE_PREDICATE, IDENTITY_FUNCTION).toCompletableFuture().get();
assertEquals(1, resultSet.size());
assertEquals(1, resultSet.readCount());
assertNotEquals(startSequence + resultSet.readCount(), resultSet.getNextSequenceToReadFrom());
assertEquals(501, resultSet.getNextSequenceToReadFrom());
final long lostCount = resultSet.getNextSequenceToReadFrom() - resultSet.readCount() - startSequence;
assertEquals(500, lostCount);
}
Aggregations