Search in sources :

Example 41 with TopicMessage

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

the class TopicMessageServiceTest method historicalMessages.

@Test
void historicalMessages() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
    topicMessageService.subscribeTopic(filter).as(StepVerifier::create).expectNext(topicMessage1, topicMessage2, topicMessage3).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 42 with TopicMessage

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

the class TopicMessageServiceTest method incomingMessagesWithEndTimeEquals.

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

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

the class AbstractTopicListenerTest method multipleSubscribers.

@Test
void multipleSubscribers() {
    // @formatter:off
    Flux<TopicMessage> generator = Flux.concat(domainBuilder.topicMessage(t -> t.topicId(1).sequenceNumber(1).consensusTimestamp(future.plusNanos(1L))), domainBuilder.topicMessage(t -> t.topicId(1).sequenceNumber(2).consensusTimestamp(future.plusNanos(2L))), domainBuilder.topicMessage(t -> t.topicId(2).sequenceNumber(7).consensusTimestamp(future.plusNanos(3L))), domainBuilder.topicMessage(t -> t.topicId(2).sequenceNumber(8).consensusTimestamp(future.plusNanos(4L))), domainBuilder.topicMessage(t -> t.topicId(1).sequenceNumber(3).consensusTimestamp(future.plusNanos(5L))));
    // @formatter:on
    TopicMessageFilter filter1 = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(EntityId.of(1L, EntityType.TOPIC)).build();
    TopicMessageFilter filter2 = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(EntityId.of(2L, EntityType.TOPIC)).build();
    StepVerifier stepVerifier1 = topicListener.listen(filter1).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L, 3L).thenCancel().verifyLater();
    StepVerifier stepVerifier2 = topicListener.listen(filter2).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(7L, 8L).thenCancel().verifyLater();
    Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    publish(generator);
    stepVerifier1.verify(Duration.ofMillis(500));
    stepVerifier2.verify(Duration.ofMillis(500));
    topicListener.listen(filter1).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).as("Verify can still re-subscribe after poller cancelled when no subscriptions").expectNextCount(0).thenCancel().verify(Duration.ofMillis(100));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) StepVerifier(reactor.test.StepVerifier) EntityId(com.hedera.mirror.common.domain.entity.EntityId) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Publisher(org.reactivestreams.Publisher) Resource(javax.annotation.Resource) Autowired(org.springframework.beans.factory.annotation.Autowired) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) Duration(java.time.Duration) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) DomainBuilder(com.hedera.mirror.grpc.domain.DomainBuilder) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) StepVerifier(reactor.test.StepVerifier) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 44 with TopicMessage

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

the class AbstractTopicListenerTest method startTimeAfter.

@Test
void startTimeAfter() {
    Mono<TopicMessage> topicMessage = domainBuilder.topicMessage(t -> t.consensusTimestamp(future.minusNanos(1)));
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(future).topicId(topicId).build();
    topicListener.listen(filter).as(StepVerifier::create).thenAwait(Duration.ofMillis(100)).then(() -> publish(topicMessage)).expectNextCount(0).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 45 with TopicMessage

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

the class AbstractTopicListenerTest method greaterThanPageSize.

@Test
void greaterThanPageSize() {
    int maxPageSize = listenerProperties.getMaxPageSize();
    listenerProperties.setMaxPageSize(2);
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
    topicListener.listen(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).thenAwait(Duration.ofMillis(50)).then(() -> publish(domainBuilder.topicMessages(3, future))).expectNext(1L, 2L, 3L).thenCancel().verify(Duration.ofMillis(500));
    listenerProperties.setMaxPageSize(maxPageSize);
}
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)

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