Search in sources :

Example 1 with TopicMessage

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

the class NotifyingEntityListenerTest method getNotifications.

private Flux<TopicMessage> getNotifications(PgConnection pgConnection) {
    Collection<TopicMessage> topicMessages = new ArrayList<>();
    try {
        PGNotification[] notifications = pgConnection.getNotifications(100);
        if (notifications != null) {
            for (PGNotification pgNotification : notifications) {
                TopicMessage topicMessage = NotifyingEntityListener.OBJECT_MAPPER.readValue(pgNotification.getParameter(), TopicMessage.class);
                topicMessages.add(topicMessage);
            }
        }
        return Flux.fromIterable(topicMessages);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) ArrayList(java.util.ArrayList) PGNotification(org.postgresql.PGNotification)

Example 2 with TopicMessage

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

the class NotifyingEntityListenerTest method onTopicMessagePayloadTooLong.

@Test
void onTopicMessagePayloadTooLong() throws InterruptedException {
    // given
    TopicMessage topicMessage = topicMessage();
    // Just exceeds 8000B
    topicMessage.setMessage(RandomUtils.nextBytes(5824));
    Flux<TopicMessage> topicMessages = subscribe(topicMessage.getTopicId().getId());
    // when
    entityListener.onTopicMessage(topicMessage);
    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) EntityBatchSaveEvent(com.hedera.mirror.importer.parser.record.entity.EntityBatchSaveEvent) BatchEntityListenerTest(com.hedera.mirror.importer.parser.record.entity.BatchEntityListenerTest) Test(org.junit.jupiter.api.Test)

Example 3 with TopicMessage

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

the class RedisEntityListenerIntegrationTest method subscribe.

@Override
protected Flux<TopicMessage> subscribe(long topicId) {
    Sinks.Many<TopicMessage> sink = Sinks.many().unicast().onBackpressureBuffer();
    RedisSerializer stringSerializer = ((RedisTemplate<String, ?>) redisOperations).getStringSerializer();
    RedisSerializer<TopicMessage> serializer = (RedisSerializer<TopicMessage>) redisOperations.getValueSerializer();
    RedisCallback<TopicMessage> redisCallback = connection -> {
        byte[] channel = stringSerializer.serialize("topic." + topicId);
        connection.subscribe((message, pattern) -> sink.emitNext(serializer.deserialize(message.getBody()), Sinks.EmitFailureHandler.FAIL_FAST), channel);
        return null;
    };
    redisOperations.execute(redisCallback);
    return sink.asFlux();
}
Also used : RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) Sinks(reactor.core.publisher.Sinks) Flux(reactor.core.publisher.Flux) TestInstance(org.junit.jupiter.api.TestInstance) RedisCallback(org.springframework.data.redis.core.RedisCallback) RedisOperations(org.springframework.data.redis.core.RedisOperations) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) BatchEntityListenerTest(com.hedera.mirror.importer.parser.record.entity.BatchEntityListenerTest) Autowired(org.springframework.beans.factory.annotation.Autowired) StreamMessage(com.hedera.mirror.common.domain.topic.StreamMessage) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) Sinks(reactor.core.publisher.Sinks) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage)

Example 4 with TopicMessage

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

the class BatchInserterTest method topicMessage.

private TopicMessage topicMessage(long consensusNs, int messageSize) {
    TopicMessage topicMessage = new TopicMessage();
    topicMessage.setConsensusTimestamp(consensusNs);
    topicMessage.setPayerAccountId(EntityId.of("0.0.1002", ACCOUNT));
    // Just exceeds 8000B
    topicMessage.setMessage(RandomUtils.nextBytes(messageSize));
    topicMessage.setRunningHash(Strings.toByteArray("running hash"));
    topicMessage.setRunningHashVersion(2);
    topicMessage.setSequenceNumber(consensusNs);
    topicMessage.setTopicId(EntityId.of("0.0.1001", EntityType.TOPIC));
    return topicMessage;
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage)

Example 5 with TopicMessage

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

the class BatchEntityListenerTest method onTopicMessageDisabled.

@Test
void onTopicMessageDisabled() throws InterruptedException {
    // given
    properties.setEnabled(false);
    TopicMessage topicMessage = topicMessage();
    Flux<TopicMessage> topicMessages = subscribe(topicMessage.getTopicId().getId());
    // when
    entityListener.onTopicMessage(topicMessage);
    entityListener.onSave(new EntityBatchSaveEvent(this));
    entityListener.onCleanup(new EntityBatchCleanupEvent(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)

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