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);
}
}
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));
}
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();
}
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;
}
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));
}
Aggregations