Search in sources :

Example 36 with TopicMessageFilter

use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.

the class PollingTopicMessageRetrieverTest method timeout.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void timeout(boolean throttle) {
    int maxPageSize = retrieverProperties.getMaxPageSize();
    Duration timeout = retrieverProperties.getTimeout();
    retrieverProperties.setMaxPageSize(1);
    retrieverProperties.setTimeout(Duration.ofMillis(10));
    domainBuilder.topicMessages(10, Instant.now()).blockLast();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(TOPIC_ID).build();
    pollingTopicMessageRetriever.retrieve(filter, throttle).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).thenConsumeWhile(i -> true).expectTimeout(Duration.ofMillis(500)).verify();
    retrieverProperties.setMaxPageSize(maxPageSize);
    retrieverProperties.setTimeout(timeout);
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) Duration(java.time.Duration) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with TopicMessageFilter

use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.

the class TopicMessageServiceTest method historicalMessagesWithEndTimeAfter.

@Test
void historicalMessagesWithEndTimeAfter() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).endTime(topicMessage3.getConsensusTimestampInstant().plusNanos(1)).topicId(topicId).build();
    topicMessageService.subscribeTopic(filter).as(StepVerifier::create).expectNext(topicMessage1, topicMessage2, topicMessage3).expectComplete().verify(Duration.ofMillis(500));
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 38 with TopicMessageFilter

use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.

the class TopicMessageServiceTest method incomingMessagesWithEndTimeBefore.

@Test
void incomingMessagesWithEndTimeBefore() {
    Instant endTime = Instant.now().plusMillis(500);
    Flux<TopicMessage> generator = domainBuilder.topicMessages(2, endTime.minusNanos(2));
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).endTime(endTime).topicId(topicId).build();
    topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).thenAwait(Duration.ofMillis(50)).then(generator::blockLast).expectNext(1L, 2L).expectComplete().verify(Duration.ofMillis(1000));
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) Instant(java.time.Instant) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 39 with TopicMessageFilter

use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.

the class TopicMessageServiceTest method endTimeEqualsStartTime.

@Test
void endTimeEqualsStartTime() {
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(now).endTime(now).topicId(topicId).build();
    assertThatThrownBy(() -> topicMessageService.subscribeTopic(filter)).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("End time must be after start time");
}
Also used : ConstraintViolationException(javax.validation.ConstraintViolationException) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 40 with TopicMessageFilter

use of com.hedera.mirror.grpc.domain.TopicMessageFilter 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

TopicMessageFilter (com.hedera.mirror.grpc.domain.TopicMessageFilter)62 TopicMessage (com.hedera.mirror.grpc.domain.TopicMessage)52 Test (org.junit.jupiter.api.Test)50 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)47 Instant (java.time.Instant)18 StepVerifier (reactor.test.StepVerifier)15 Duration (java.time.Duration)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 EntityId (com.hedera.mirror.common.domain.entity.EntityId)11 EntityType (com.hedera.mirror.common.domain.entity.EntityType)11 DomainBuilder (com.hedera.mirror.grpc.domain.DomainBuilder)11 Resource (javax.annotation.Resource)11 ValueSource (org.junit.jupiter.params.provider.ValueSource)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Flux (reactor.core.publisher.Flux)11 AfterEach (org.junit.jupiter.api.AfterEach)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ConstraintViolationException (javax.validation.ConstraintViolationException)9 GrpcProperties (com.hedera.mirror.grpc.GrpcProperties)6 EntityNotFoundException (com.hedera.mirror.grpc.exception.EntityNotFoundException)6