use of com.hazelcast.topic.ITopic 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.ITopic in project hazelcast by hazelcast.
the class ClientReliableTopicTest method removeMessageListener_whenExisting.
// ============== removeMessageListener ==============================
@Test
public void removeMessageListener_whenExisting() {
ITopic topic = client.getReliableTopic(randomString());
final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
UUID id = topic.addMessageListener(listener);
boolean removed = topic.removeMessageListener(id);
assertTrue(removed);
topic.publish("1");
// it should not receive any events.
assertTrueDelayed5sec(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, listener.objects.size());
}
});
}
use of com.hazelcast.topic.ITopic 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.ITopic in project hazelcast by hazelcast.
the class ClientReliableTopicTest method testCreation.
@Test
public void testCreation() {
ITopic topic = client.getReliableTopic(randomString());
assertInstanceOf(ClientReliableTopicProxy.class, topic);
}
use of com.hazelcast.topic.ITopic 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