use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.
the class ClientReliableTopicTest method addMessageListener.
@Test
public void addMessageListener() {
ITopic topic = client.getReliableTopic(randomString());
String id = topic.addMessageListener(new ReliableMessageListenerMock());
assertNotNull(id);
}
use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.
the class ClientReliableTopicTest method publishSingle.
// ============================================
@Test
public void publishSingle() throws InterruptedException {
ITopic topic = client.getReliableTopic(randomString());
final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
topic.addMessageListener(listener);
final String msg = "foobar";
topic.publish(msg);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertContains(listener.objects, msg);
}
});
}
use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.
the class ClientReliableTopicTest method publishMultiple.
@Test
public void publishMultiple() throws InterruptedException {
ITopic topic = client.getReliableTopic(randomString());
final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
topic.addMessageListener(listener);
final List<String> items = new ArrayList<String>();
for (int k = 0; k < 5; k++) {
items.add("" + k);
}
for (String item : items) {
topic.publish(item);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(items, Arrays.asList(listener.objects.toArray()));
}
});
}
use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.
the class ClientReliableTopicTest method removeMessageListener_whenAlreadyRemoved.
@Test
public void removeMessageListener_whenAlreadyRemoved() {
ITopic topic = client.getReliableTopic(randomString());
final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
String id = topic.addMessageListener(listener);
topic.removeMessageListener(id);
boolean result = topic.removeMessageListener(id);
assertFalse(result);
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.impl.reliable.ReliableMessageListenerMock 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());
assertEquals(null, message.getPublishingMember());
long actualPublishTime = message.getPublishTime();
assertTrue(actualPublishTime >= beforePublishTime);
assertTrue(actualPublishTime <= afterPublishTime);
}
});
}
Aggregations