Search in sources :

Example 11 with TopicMessage

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

the class BatchEntityListenerTest method onTopicMessage.

@Test
void onTopicMessage() throws InterruptedException {
    // given
    TopicMessage topicMessage1 = topicMessage();
    TopicMessage topicMessage2 = topicMessage();
    Flux<TopicMessage> topicMessages = subscribe(topicMessage1.getTopicId().getId());
    // when
    entityListener.onTopicMessage(topicMessage1);
    entityListener.onTopicMessage(topicMessage2);
    entityListener.onSave(new EntityBatchSaveEvent(this));
    entityListener.onCleanup(new EntityBatchCleanupEvent(this));
    // then
    topicMessages.as(StepVerifier::create).expectNext(topicMessage1, topicMessage2).thenCancel().verify(Duration.ofMillis(1000));
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 12 with TopicMessage

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

the class BatchEntityListenerTest method onCleanup.

@Test
void onCleanup() throws InterruptedException {
    // given
    TopicMessage topicMessage = topicMessage();
    Flux<TopicMessage> topicMessages = subscribe(topicMessage.getTopicId().getId());
    // when
    entityListener.onTopicMessage(topicMessage);
    entityListener.onCleanup(new EntityBatchCleanupEvent(this));
    entityListener.onSave(new EntityBatchSaveEvent(this));
    // then
    topicMessages.as(StepVerifier::create).expectNextCount(0L).thenCancel().verify(Duration.ofMillis(500));
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 13 with TopicMessage

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

the class RedisEntityListenerTest method onDuplicateTopicMessages.

@Test
void onDuplicateTopicMessages() throws InterruptedException {
    TopicMessage topicMessage1 = topicMessage();
    TopicMessage topicMessage2 = topicMessage();
    TopicMessage topicMessage3 = topicMessage();
    // submitAndSave two messages, verify publish logic called twice
    submitAndSave(topicMessage1);
    submitAndSave(topicMessage2);
    verify(redisOperations, timeout(TIMEOUT.toMillis()).times(2)).executePipelined(any(SessionCallback.class));
    // submitAndSave two duplicate messages, verify publish was not attempted
    Mockito.reset(redisOperations);
    submitAndSave(topicMessage1);
    submitAndSave(topicMessage2);
    verify(redisOperations, timeout(TIMEOUT.toMillis()).times(0)).executePipelined(any(SessionCallback.class));
    // submitAndSave third new unique message, verify publish called once.
    Mockito.reset(redisOperations);
    submitAndSave(topicMessage3);
    entityListener.onCleanup(new EntityBatchCleanupEvent(this));
    verify(redisOperations, timeout(TIMEOUT.toMillis()).times(1)).executePipelined(any(SessionCallback.class));
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) SessionCallback(org.springframework.data.redis.core.SessionCallback) EntityBatchCleanupEvent(com.hedera.mirror.importer.parser.record.entity.EntityBatchCleanupEvent) Test(org.junit.jupiter.api.Test)

Example 14 with TopicMessage

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

the class SqlEntityListenerTest method onTopicMessage.

@Test
void onTopicMessage() {
    // given
    TopicMessage topicMessage = domainBuilder.topicMessage().get();
    // when
    sqlEntityListener.onTopicMessage(topicMessage);
    completeFileAndCommit();
    // then
    assertThat(topicMessageRepository.findAll()).containsExactlyInAnyOrder(topicMessage);
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TopicMessage (com.hedera.mirror.common.domain.topic.TopicMessage)14 Test (org.junit.jupiter.api.Test)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 BatchEntityListenerTest (com.hedera.mirror.importer.parser.record.entity.BatchEntityListenerTest)2 RedisOperations (org.springframework.data.redis.core.RedisOperations)2 SessionCallback (org.springframework.data.redis.core.SessionCallback)2 StreamMessage (com.hedera.mirror.common.domain.topic.StreamMessage)1 EntityBatchCleanupEvent (com.hedera.mirror.importer.parser.record.entity.EntityBatchCleanupEvent)1 EntityBatchSaveEvent (com.hedera.mirror.importer.parser.record.entity.EntityBatchSaveEvent)1 ConsensusMessageChunkInfo (com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo)1 ConsensusSubmitMessageTransactionBody (com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)1 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)1 ArrayList (java.util.ArrayList)1 TestInstance (org.junit.jupiter.api.TestInstance)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 PGNotification (org.postgresql.PGNotification)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 RedisCallback (org.springframework.data.redis.core.RedisCallback)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 RedisSerializer (org.springframework.data.redis.serializer.RedisSerializer)1