use of com.hedera.mirror.grpc.listener.TopicListener in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method duplicateMessages.
@Test
void duplicateMessages() {
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());
TopicMessageFilter retrieverFilter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
Mockito.when(entityRepository.findById(retrieverFilter.getTopicId().getId())).thenReturn(Optional.of(Entity.builder().type(EntityType.TOPIC).build()));
Mockito.when(topicMessageRetriever.retrieve(ArgumentMatchers.isA(TopicMessageFilter.class), ArgumentMatchers.eq(true))).thenReturn(Flux.just(topicMessage(1, Instant.EPOCH), topicMessage(1, Instant.EPOCH.plus(1, ChronoUnit.NANOS)), topicMessage(2, Instant.EPOCH.plus(2, ChronoUnit.NANOS)), topicMessage(1, Instant.EPOCH.plus(3, ChronoUnit.NANOS))));
Mockito.when(topicListener.listen(ArgumentMatchers.any())).thenReturn(Flux.empty());
topicMessageService.subscribeTopic(retrieverFilter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L).expectComplete().verify(Duration.ofMillis(700));
}
use of com.hedera.mirror.grpc.listener.TopicListener in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method missingMessages.
@Test
void 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());
TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
TopicMessage beforeMissing = topicMessage(1);
TopicMessage afterMissing = topicMessage(4);
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.empty());
Mockito.when(topicListener.listen(filter)).thenReturn(Flux.just(beforeMissing, afterMissing));
Mockito.when(topicMessageRetriever.retrieve(ArgumentMatchers.argThat(t -> t.getLimit() == 2 && t.getStartTime().equals(beforeMissing.getConsensusTimestampInstant().plusNanos(1)) && t.getEndTime().equals(afterMissing.getConsensusTimestampInstant())), ArgumentMatchers.eq(false))).thenReturn(Flux.just(topicMessage(2), topicMessage(3)));
topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L, 3L, 4L).thenCancel().verify(Duration.ofMillis(700));
}
use of com.hedera.mirror.grpc.listener.TopicListener in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method missingMessagesFromRetrieverAndListener.
@Test
void missingMessagesFromRetrieverAndListener() {
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());
TopicMessageFilter retrieverFilter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
TopicMessage retrieved1 = topicMessage(1);
TopicMessage retrieved2 = topicMessage(2);
TopicMessage beforeMissing1 = topicMessage(3);
TopicMessage beforeMissing2 = topicMessage(4);
TopicMessage afterMissing1 = topicMessage(8);
TopicMessage afterMissing2 = topicMessage(9);
TopicMessage afterMissing3 = topicMessage(10);
Mockito.when(entityRepository.findById(retrieverFilter.getTopicId().getId())).thenReturn(Optional.of(Entity.builder().type(EntityType.TOPIC).build()));
TopicMessageFilter listenerFilter = TopicMessageFilter.builder().startTime(retrieved2.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.isA(TopicMessageFilter.class), ArgumentMatchers.eq(true))).thenReturn(Flux.just(retrieved1));
Mockito.when(topicMessageRetriever.retrieve(ArgumentMatchers.isA(TopicMessageFilter.class), ArgumentMatchers.eq(false))).thenReturn(// missing historic
Flux.just(retrieved2), Flux.just(// missing incoming
topicMessage(5), topicMessage(6), topicMessage(7)));
topicMessageService.subscribeTopic(retrieverFilter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L).expectComplete().verify(Duration.ofMillis(700));
}
use of com.hedera.mirror.grpc.listener.TopicListener 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