Search in sources :

Example 1 with TopicMessage

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

the class ConsensusControllerTest method subscribeTopicQueryLongOverflowEndTime.

@Test
void subscribeTopicQueryLongOverflowEndTime() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    ConsensusTopicQuery query = ConsensusTopicQuery.newBuilder().setLimit(5L).setConsensusStartTime(Timestamp.newBuilder().setSeconds(1).setNanos(2).build()).setConsensusEndTime(Timestamp.newBuilder().setSeconds(31556889864403199L).setNanos(999999999).build()).setTopicID(TopicID.newBuilder().setRealmNum(0).setTopicNum(100).build()).build();
    Flux<TopicMessage> generator = domainBuilder.topicMessages(2, Instant.now().plusSeconds(10L));
    grpcConsensusService.subscribeTopic(Mono.just(query)).as(StepVerifier::create).expectNext(topicMessage1.getResponse()).expectNext(topicMessage2.getResponse()).expectNext(topicMessage3.getResponse()).thenAwait(Duration.ofMillis(50)).then(() -> generator.blockLast()).expectNextCount(2).expectComplete().verify(Duration.ofMillis(500));
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) ConsensusTopicQuery(com.hedera.mirror.api.proto.ConsensusTopicQuery) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with TopicMessage

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

the class ConsensusControllerTest method subscribeVerifySequence.

@Test
void subscribeVerifySequence() {
    domainBuilder.topicMessage().block();
    domainBuilder.topicMessage().block();
    domainBuilder.topicMessage().block();
    ConsensusTopicQuery query = ConsensusTopicQuery.newBuilder().setLimit(7L).setConsensusStartTime(Timestamp.newBuilder().setSeconds(0).build()).setTopicID(TopicID.newBuilder().setRealmNum(0).setTopicNum(100).build()).build();
    Flux<TopicMessage> generator = domainBuilder.topicMessages(4, Instant.now().plusSeconds(10L));
    grpcConsensusService.subscribeTopic(Mono.just(query)).map(ConsensusTopicResponse::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L, 3L).thenAwait(Duration.ofMillis(50)).then(() -> generator.blockLast()).expectNext(4L, 5L, 6L, 7L).expectComplete().verify(Duration.ofMillis(1000));
}
Also used : ConsensusTopicQuery(com.hedera.mirror.api.proto.ConsensusTopicQuery) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with TopicMessage

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

the class ConsensusControllerTest method subscribeTopicReactive.

@Test
void subscribeTopicReactive() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    ConsensusTopicQuery query = ConsensusTopicQuery.newBuilder().setLimit(5L).setConsensusStartTime(Timestamp.newBuilder().setSeconds(0).build()).setTopicID(TopicID.newBuilder().setRealmNum(0).setTopicNum(100).build()).build();
    Flux<TopicMessage> generator = domainBuilder.topicMessages(2, Instant.now().plusSeconds(10L));
    grpcConsensusService.subscribeTopic(Mono.just(query)).as(StepVerifier::create).expectNext(topicMessage1.getResponse()).expectNext(topicMessage2.getResponse()).expectNext(topicMessage3.getResponse()).thenAwait(Duration.ofMillis(50)).then(() -> generator.blockLast()).expectNextCount(2).expectComplete().verify(Duration.ofMillis(500));
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) ConsensusTopicQuery(com.hedera.mirror.api.proto.ConsensusTopicQuery) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with TopicMessage

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

the class ConsensusControllerTest method subscribeTopicQueryPreEpochStartTime.

@Test
void subscribeTopicQueryPreEpochStartTime() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    ConsensusTopicQuery query = ConsensusTopicQuery.newBuilder().setLimit(5L).setConsensusStartTime(Timestamp.newBuilder().setSeconds(-123).setNanos(-456).build()).setTopicID(TopicID.newBuilder().setRealmNum(0).setTopicNum(100).build()).build();
    Flux<TopicMessage> generator = domainBuilder.topicMessages(2, Instant.now().plusSeconds(10L));
    grpcConsensusService.subscribeTopic(Mono.just(query)).as(StepVerifier::create).expectNext(topicMessage1.getResponse()).expectNext(topicMessage2.getResponse()).expectNext(topicMessage3.getResponse()).thenAwait(Duration.ofMillis(50)).then(() -> generator.blockLast()).expectNextCount(2).expectComplete().verify(Duration.ofMillis(500));
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) ConsensusTopicQuery(com.hedera.mirror.api.proto.ConsensusTopicQuery) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with TopicMessage

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

the class PollingTopicMessageRetriever method poll.

private Flux<TopicMessage> poll(PollingContext context) {
    TopicMessageFilter filter = context.getFilter();
    TopicMessage last = context.getLast();
    int limit = filter.hasLimit() ? (int) (filter.getLimit() - context.getTotal().get()) : Integer.MAX_VALUE;
    int pageSize = Math.min(limit, context.getMaxPageSize());
    Instant startTime = last != null ? last.getConsensusTimestampInstant().plusNanos(1) : filter.getStartTime();
    context.getPageSize().set(0L);
    TopicMessageFilter newFilter = filter.toBuilder().limit(pageSize).startTime(startTime).build();
    log.debug("Executing query: {}", newFilter);
    return Flux.fromStream(topicMessageRepository.findByFilter(newFilter)).name("findByFilter").metrics();
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) Instant(java.time.Instant) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter)

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