use of com.hedera.mirror.grpc.domain.TopicMessage 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.TopicMessage in project hedera-mirror-node by hashgraph.
the class TopicMessageRepositoryCustomImpl method findByFilter.
@Override
public Stream<TopicMessage> findByFilter(TopicMessageFilter filter) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<TopicMessage> query = cb.createQuery(TopicMessage.class);
Root<TopicMessage> root = query.from(TopicMessage.class);
Predicate predicate = cb.and(cb.equal(root.get("topicId"), filter.getTopicId().getId()), cb.greaterThanOrEqualTo(root.get("consensusTimestamp"), converter.convert(filter.getStartTime())));
if (filter.getEndTime() != null) {
predicate = cb.and(predicate, cb.lessThan(root.get("consensusTimestamp"), converter.convert(filter.getEndTime())));
}
query = query.select(root).where(predicate).orderBy(cb.asc(root.get("consensusTimestamp")));
TypedQuery<TopicMessage> typedQuery = entityManager.createQuery(query);
typedQuery.setHint(QueryHints.HINT_READONLY, true);
if (filter.hasLimit()) {
typedQuery.setMaxResults((int) filter.getLimit());
}
entityManager.createNativeQuery(TOPIC_MESSAGES_BY_ID_QUERY_HINT).executeUpdate();
// getResultStream()'s cursor doesn't work with reactive streams
return typedQuery.getResultList().stream();
}
use of com.hedera.mirror.grpc.domain.TopicMessage 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.TopicMessage 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));
}
use of com.hedera.mirror.grpc.domain.TopicMessage in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceTest method missingMessagesFromListenerSomeRetrieved.
@Test
void missingMessagesFromListenerSomeRetrieved() {
TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(topicId).build();
missingMessagesFromListenerTest(filter, Flux.just(topicMessage(5), topicMessage(6)));
topicMessageService.subscribeTopic(filter).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L, 3L, 4L, 5L, 6L).expectError(IllegalStateException.class).verify(Duration.ofMillis(700));
}
Aggregations