Search in sources :

Example 46 with TopicMessage

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

the class NotifyingTopicListenerTest method json.

// Test deserialization from JSON to verify contract with PostgreSQL listen/notify
@Test
void json() {
    String json = "{" + "\"@type\":\"TopicMessage\"," + "\"chunk_num\":1," + "\"chunk_total\":2," + "\"consensus_timestamp\":1594401417000000000," + "\"message\":\"AQID\"," + "\"payer_account_id\":4294968296," + "\"running_hash\":\"BAUG\"," + "\"running_hash_version\":2," + "\"sequence_number\":1," + "\"topic_id\":1001," + "\"valid_start_timestamp\":1594401416000000000" + "}";
    TopicMessage topicMessage = TopicMessage.builder().chunkNum(1).chunkTotal(2).consensusTimestamp(Instant.ofEpochSecond(1594401417)).message(new byte[] { 1, 2, 3 }).payerAccountId(4294968296L).runningHash(new byte[] { 4, 5, 6 }).runningHashVersion(2).sequenceNumber(1L).topicId(1001).validStartTimestamp(Instant.ofEpochSecond(1594401416)).build();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).topicId(EntityId.of(1001L, EntityType.TOPIC)).build();
    topicListener.listen(filter).as(StepVerifier::create).thenAwait(Duration.ofMillis(50)).then(() -> jdbcTemplate.execute("NOTIFY topic_message, '" + json + "'")).expectNext(topicMessage).thenCancel().verify(Duration.ofMillis(500L));
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) Test(org.junit.jupiter.api.Test)

Example 47 with TopicMessage

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

the class TopicMessageRepositoryTest method findByFilterWithTopicId.

@Test
void findByFilterWithTopicId() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage(t -> t.topicId(1)).block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage(t -> t.topicId(2)).block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage(t -> t.topicId(3)).block();
    TopicMessageFilter filter = TopicMessageFilter.builder().topicId(EntityId.of(2L, EntityType.TOPIC)).startTime(topicMessage1.getConsensusTimestampInstant()).build();
    assertThat(topicMessageRepository.findByFilter(filter)).containsExactly(topicMessage2);
}
Also used : TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) EntityId(com.hedera.mirror.common.domain.entity.EntityId) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Autowired(org.springframework.beans.factory.annotation.Autowired) PageRequest(org.springframework.data.domain.PageRequest) Instant(java.time.Instant) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Test(org.junit.jupiter.api.Test) Pageable(org.springframework.data.domain.Pageable) 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 48 with TopicMessage

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

the class TopicMessageRepositoryTest method findLatest.

@Test
void findLatest() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage4 = domainBuilder.topicMessage().block();
    Pageable pageable = PageRequest.of(0, 2);
    assertThat(topicMessageRepository.findLatest(topicMessage1.getConsensusTimestamp(), pageable)).containsExactly(topicMessage2, topicMessage3);
}
Also used : Pageable(org.springframework.data.domain.Pageable) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 49 with TopicMessage

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

the class TopicMessageRepositoryTest method findByFilterWithStartTime.

@Test
void findByFilterWithStartTime() {
    TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
    TopicMessage topicMessage3 = domainBuilder.topicMessage().block();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(topicMessage2.getConsensusTimestampInstant()).topicId(EntityId.of(topicMessage1.getTopicId(), EntityType.TOPIC)).build();
    assertThat(topicMessageRepository.findByFilter(filter)).containsExactly(topicMessage2, topicMessage3);
}
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 50 with TopicMessage

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

the class PollingTopicMessageRetrieverTest method limitEqualPageSize.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void limitEqualPageSize(boolean throttle) {
    int maxPageSize = overrideMaxPageSize(throttle, 2);
    domainBuilder.topicMessages(4, Instant.now()).blockLast();
    TopicMessageFilter filter = TopicMessageFilter.builder().startTime(Instant.EPOCH).limit(2L).topicId(TOPIC_ID).build();
    pollingTopicMessageRetriever.retrieve(filter, throttle).map(TopicMessage::getSequenceNumber).as(StepVerifier::create).expectNext(1L, 2L).expectComplete().verify(Duration.ofMillis(500));
    restoreMaxPageSize(throttle, maxPageSize);
}
Also used : TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) TopicMessageFilter(com.hedera.mirror.grpc.domain.TopicMessageFilter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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