Search in sources :

Example 1 with Entity

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);
}
Also used : TopicMessageRetriever(com.hedera.mirror.grpc.retriever.TopicMessageRetriever) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArgumentMatchers(org.mockito.ArgumentMatchers) StepVerifier(reactor.test.StepVerifier) EntityId(com.hedera.mirror.common.domain.entity.EntityId) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityType(com.hedera.mirror.common.domain.entity.EntityType) EntityRepository(com.hedera.mirror.grpc.repository.EntityRepository) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) TopicMessageRetriever(com.hedera.mirror.grpc.retriever.TopicMessageRetriever) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Duration(java.time.Duration) TopicListener(com.hedera.mirror.grpc.listener.TopicListener) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) GrpcProperties(com.hedera.mirror.grpc.GrpcProperties) Resource(javax.annotation.Resource) ListenerProperties(com.hedera.mirror.grpc.listener.ListenerProperties) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) RetrieverProperties(com.hedera.mirror.grpc.retriever.RetrieverProperties) ChronoUnit(java.time.temporal.ChronoUnit) ConstraintViolationException(javax.validation.ConstraintViolationException) Entity(com.hedera.mirror.grpc.domain.Entity) Optional(java.util.Optional) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) DomainBuilder(com.hedera.mirror.grpc.domain.DomainBuilder) TopicListener(com.hedera.mirror.grpc.listener.TopicListener) GrpcProperties(com.hedera.mirror.grpc.GrpcProperties) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) EntityRepository(com.hedera.mirror.grpc.repository.EntityRepository) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)1 GrpcProperties (com.hedera.mirror.grpc.GrpcProperties)1 DomainBuilder (com.hedera.mirror.grpc.domain.DomainBuilder)1 Entity (com.hedera.mirror.grpc.domain.Entity)1 TopicMessage (com.hedera.mirror.grpc.domain.TopicMessage)1 TopicMessageFilter (com.hedera.mirror.grpc.domain.TopicMessageFilter)1 EntityNotFoundException (com.hedera.mirror.grpc.exception.EntityNotFoundException)1 ListenerProperties (com.hedera.mirror.grpc.listener.ListenerProperties)1 TopicListener (com.hedera.mirror.grpc.listener.TopicListener)1 EntityRepository (com.hedera.mirror.grpc.repository.EntityRepository)1 RetrieverProperties (com.hedera.mirror.grpc.retriever.RetrieverProperties)1 TopicMessageRetriever (com.hedera.mirror.grpc.retriever.TopicMessageRetriever)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Optional (java.util.Optional)1 Resource (javax.annotation.Resource)1