Search in sources :

Example 11 with TopicMessage

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

the class TopicMessageServiceTest method bothMessages.

@Test
void bothMessages() {
    domainBuilder.topicMessages(3, now).blockLast();
    TopicMessageFilter filter = TopicMessageFilter.builder().limit(5).startTime(Instant.EPOCH).topicId(topicId).build();
    topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).thenAwait(Duration.ofMillis(100)).then(() -> domainBuilder.topicMessages(3, future).blockLast()).expectNext(1L, 2L, 3L, 4L, 5L).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 12 with TopicMessage

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

the class TopicMessageServiceTest method historicalMessagesWithEndTimeExceedsPageSize.

@Test
void historicalMessagesWithEndTimeExceedsPageSize() {
    int oldMaxPageSize = retrieverProperties.getMaxPageSize();
    retrieverProperties.setMaxPageSize(1);
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage4 = domainBuilder.topicMessage().block();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).endTime(topicMessage4.getConsensusTimestampInstant()).topicId(topicId).build();
    topicMessageService.subscribeTopic(filter).as(StepVerifier::create).expectNext(topicMessage1).expectNext(topicMessage2).expectNext(topicMessage3).expectComplete().verify(Duration.ofMillis(500));
    retrieverProperties.setMaxPageSize(oldMaxPageSize);
}
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 13 with TopicMessage

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

the class TopicMessageServiceTest method incomingMessages.

@Test
void incomingMessages() {
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
    topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).thenAwait(Duration.ofMillis(100)).then(() -> domainBuilder.topicMessages(3, future).blockLast()).expectNext(1L, 2L, 3L).thenCancel().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 14 with TopicMessage

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

the class TopicMessageServiceTest method bothMessagesWithTopicId.

@Test
void bothMessagesWithTopicId() {
    domainBuilder.entity(e -> e.num(1L).id(1L)).block();
    domainBuilder.entity(e -> e.num(2L).id(2L)).block();
    domainBuilder.topicMessage(t -> t.topicId(0).sequenceNumber(1)).block();
    domainBuilder.topicMessage(t -> t.topicId(1).sequenceNumber(1)).block();
    Flux<TopicMessage> generator = Flux.concat(domainBuilder.topicMessage(t -> t.topicId(0).sequenceNumber(2).consensusTimestamp(future.plusNanos(1))), domainBuilder.topicMessage(t -> t.topicId(1).sequenceNumber(2).consensusTimestamp(future.plusNanos(2))), domainBuilder.topicMessage(t -> t.topicId(2).sequenceNumber(1).consensusTimestamp(future.plusNanos(3))));
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(EntityId.of(1L, EntityType.TOPIC)).build();
    topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).thenAwait(Duration.ofMillis(100)).then(generator::blockLast).expectNext(1L, 2L).thenCancel().verify(Duration.ofMillis(500));
}
Also used : 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) 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 15 with TopicMessage

use of com.hedera.mirror.grpc.domain.TopicMessage 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));
}
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) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

TopicMessage (com.hedera.mirror.grpc.domain.TopicMessage)58 TopicMessageFilter (com.hedera.mirror.grpc.domain.TopicMessageFilter)50 Test (org.junit.jupiter.api.Test)45 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)43 Instant (java.time.Instant)17 StepVerifier (reactor.test.StepVerifier)15 Duration (java.time.Duration)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 DomainBuilder (com.hedera.mirror.grpc.domain.DomainBuilder)10 Resource (javax.annotation.Resource)10 ValueSource (org.junit.jupiter.params.provider.ValueSource)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Flux (reactor.core.publisher.Flux)10 EntityId (com.hedera.mirror.common.domain.entity.EntityId)9 EntityType (com.hedera.mirror.common.domain.entity.EntityType)9 AfterEach (org.junit.jupiter.api.AfterEach)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ConsensusTopicQuery (com.hedera.mirror.api.proto.ConsensusTopicQuery)6 GrpcProperties (com.hedera.mirror.grpc.GrpcProperties)5 ListenerProperties (com.hedera.mirror.grpc.listener.ListenerProperties)5