use of com.hedera.mirror.grpc.domain.Entity in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method missingMessagesFromListenerTest.
private void missingMessagesFromListenerTest(TopicMessageFilter filter, Flux<TopicMessage> missingMessages) {
TopicListener topicListener = Mockito.mock(TopicListener.class);
EntityRepository entityRepository = Mockito.mock(EntityRepository.class);
TopicMessageRetriever topicMessageRetriever = Mockito.mock(TopicMessageRetriever.class);
topicMessageService = new TopicMessageServiceImpl(new GrpcProperties(), topicListener, entityRepository, topicMessageRetriever, new SimpleMeterRegistry());
// historic messages
TopicMessage retrieved1 = topicMessage(1);
TopicMessage retrieved2 = topicMessage(2);
// incoming messages before gap
TopicMessage beforeMissing1 = topicMessage(3);
TopicMessage beforeMissing2 = topicMessage(4);
// incoming messages after gap
TopicMessage afterMissing1 = topicMessage(8);
TopicMessage afterMissing2 = topicMessage(9);
TopicMessage afterMissing3 = topicMessage(10);
// mock entity type check
Mockito.when(entityRepository.findById(filter.getTopicId().getId())).thenReturn(Optional.of(Entity.builder().type(EntityType.TOPIC).build()));
Mockito.when(topicMessageRetriever.retrieve(ArgumentMatchers.eq(filter), ArgumentMatchers.eq(true))).thenReturn(Flux.just(retrieved1, retrieved2));
TopicMessageFilter listenerFilter = TopicMessageFilter.builder().startTime(beforeMissing1.getConsensusTimestampInstant()).build();
Mockito.when(topicListener.listen(ArgumentMatchers.argThat(l -> l.getStartTime().equals(listenerFilter.getStartTime())))).thenReturn(Flux.just(beforeMissing1, beforeMissing2, afterMissing1, afterMissing2, afterMissing3));
Mockito.when(topicMessageRetriever.retrieve(ArgumentMatchers.argThat(t -> t.getLimit() == 3 && t.getStartTime().equals(beforeMissing2.getConsensusTimestampInstant().plusNanos(1)) && t.getEndTime().equals(afterMissing1.getConsensusTimestampInstant())), ArgumentMatchers.eq(false))).thenReturn(missingMessages);
}
Aggregations