use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientReliableTopicOnClusterRestartTest method shouldFail_OnClusterRestart_whenDataLoss_notLossTolerant.
@Test
public void shouldFail_OnClusterRestart_whenDataLoss_notLossTolerant() {
Config config = smallInstanceConfig();
String topicName = "topic";
config.getRingbufferConfig(topicName).setCapacity(10);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
AtomicLong messageCount = new AtomicLong();
// initialises listener seq up to 10000
for (int i = 0; i < 10_000; i++) {
member.getReliableTopic(topicName).publish("message");
}
ITopic<String> topic = client.getReliableTopic(topicName);
UUID registrationId = topic.addMessageListener(createListener(false, m -> messageCount.incrementAndGet()));
member.shutdown();
member = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance finalMember = member;
assertTrueEventually(() -> {
// we require at least one new message to detect that the ringbuffer was recreated
finalMember.getReliableTopic(topicName).publish("message");
ClientReliableTopicProxy<?> proxy = (ClientReliableTopicProxy<?>) topic;
assertTrue(proxy.isListenerCancelled(registrationId));
});
assertEquals(0, messageCount.get());
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientReliableTopicTest method testListener.
@Test
public void testListener() throws InterruptedException {
ITopic topic = client.getReliableTopic(randomString());
int messageCount = 10;
final CountDownLatch latch = new CountDownLatch(messageCount);
MessageListener listener = new MessageListener() {
public void onMessage(Message message) {
latch.countDown();
}
};
topic.addMessageListener(listener);
for (int i = 0; i < messageCount; i++) {
topic.publish(i);
}
assertTrue(latch.await(20, TimeUnit.SECONDS));
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientTopicTest method testRemoveListener.
@Test
public void testRemoveListener() {
ITopic topic = client.getTopic(randomString());
MessageListener listener = new MessageListener() {
public void onMessage(Message message) {
}
};
UUID id = topic.addMessageListener(listener);
assertTrue(topic.removeMessageListener(id));
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientReliableTopicTest method testMessageFieldSetCorrectly.
@Test
public void testMessageFieldSetCorrectly() {
ITopic topic = client.getReliableTopic(randomString());
final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
topic.addMessageListener(listener);
final long beforePublishTime = Clock.currentTimeMillis();
final String messageStr = randomString();
topic.publish(messageStr);
final long afterPublishTime = Clock.currentTimeMillis();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.messages.size());
Message<String> message = listener.messages.get(0);
assertEquals(messageStr, message.getMessageObject());
assertNull(message.getPublishingMember());
long actualPublishTime = message.getPublishTime();
assertTrue(actualPublishTime >= beforePublishTime);
assertTrue(actualPublishTime <= afterPublishTime);
}
});
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class AllTest method loadTopicOperations.
private List<Runnable> loadTopicOperations() {
ITopic topic = hazelcast.getTopic("myTopic");
topic.addMessageListener(new MessageListener() {
public void onMessage(Message message) {
messagesReceived.incrementAndGet();
}
});
List<Runnable> operations = new ArrayList<Runnable>();
addOperation(operations, new Runnable() {
public void run() {
ITopic topic = hazelcast.getTopic("myTopic");
topic.publish(String.valueOf(random.nextInt(100000000)));
messagesSend.incrementAndGet();
}
}, 10);
return operations;
}
Aggregations