use of com.hedera.mirror.grpc.domain.TopicMessageFilter 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();
}
use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceImpl method incomingMessages.
private Flux<TopicMessage> incomingMessages(TopicContext topicContext) {
if (topicContext.isComplete()) {
return Flux.empty();
}
TopicMessageFilter filter = topicContext.getFilter();
TopicMessage last = topicContext.getLast();
long limit = filter.hasLimit() ? filter.getLimit() - topicContext.getCount().get() : 0;
Instant startTime = last != null ? last.getConsensusTimestampInstant().plusNanos(1) : filter.getStartTime();
TopicMessageFilter newFilter = filter.toBuilder().limit(limit).startTime(startTime).build();
return topicListener.listen(newFilter).takeUntilOther(pastEndTime(topicContext)).concatMap(t -> missingMessages(topicContext, t));
}
use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method endTimeBeforeStartTime.
@Test
void endTimeBeforeStartTime() {
TopicMessageFilter filter = TopicMessageFilter.builder().startTime(now).endTime(now.minus(1, ChronoUnit.DAYS)).topicId(topicId).build();
assertThatThrownBy(() -> topicMessageService.subscribeTopic(filter)).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("End time must be after start time");
}
use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method duplicateMessages.
@Test
void duplicateMessages() {
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 retrieverFilter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
Mockito.when(entityRepository.findById(retrieverFilter.getTopicId().getId())).thenReturn(Optional.of(Entity.builder().type(EntityType.TOPIC).build()));
Mockito.when(topicMessageRetriever.retrieve(ArgumentMatchers.isA(TopicMessageFilter.class), ArgumentMatchers.eq(true))).thenReturn(Flux.just(topicMessage(1, Instant.EPOCH), topicMessage(1, Instant.EPOCH.plus(1, ChronoUnit.NANOS)), topicMessage(2, Instant.EPOCH.plus(2, ChronoUnit.NANOS)), topicMessage(1, Instant.EPOCH.plus(3, ChronoUnit.NANOS))));
Mockito.when(topicListener.listen(ArgumentMatchers.any())).thenReturn(Flux.empty());
topicMessageService.subscribeTopic(retrieverFilter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L).expectComplete().verify(Duration.ofMillis(700));
}
use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method noMessagesWithFutureEndTime.
@Test
void noMessagesWithFutureEndTime() {
Instant endTime = now.plusMillis(250);
TopicMessageFilter filter = TopicMessageFilter.builder().startTime(now).endTime(endTime).topicId(topicId).build();
topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNextCount(0L).expectComplete().verify(Duration.ofMillis(1000));
}
Aggregations