Search in sources :

Example 6 with ReliableMessageListenerMock

use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.

the class ClientReliableTopicTest method testAlwaysStartAfterTail.

// makes sure that when a listener is register, we don't see any messages being published before
// it got registered. We'll only see the messages after it got registered.
@Test
public void testAlwaysStartAfterTail() {
    final ITopic topic = client.getReliableTopic(randomString());
    topic.publish("1");
    topic.publish("2");
    topic.publish("3");
    spawn(new Runnable() {

        @Override
        public void run() {
            sleepSeconds(5);
            topic.publish("4");
            topic.publish("5");
            topic.publish("6");
        }
    });
    final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
    topic.addMessageListener(listener);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(asList("4", "5", "6"), Arrays.asList(listener.objects.toArray()));
        }
    });
}
Also used : ITopic(com.hazelcast.core.ITopic) ReliableMessageListenerMock(com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with ReliableMessageListenerMock

use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.

the class ClientReliableTopicTest method publishNull.

@Test
public void publishNull() throws InterruptedException {
    ITopic topic = client.getReliableTopic(randomString());
    final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
    topic.addMessageListener(listener);
    topic.publish(null);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertContains(listener.objects, null);
        }
    });
}
Also used : ITopic(com.hazelcast.core.ITopic) ReliableMessageListenerMock(com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with ReliableMessageListenerMock

use of com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock in project hazelcast by hazelcast.

the class ClientReliableTopicTest method removeMessageListener_whenExisting.

@Test
public void removeMessageListener_whenExisting() {
    ITopic topic = client.getReliableTopic(randomString());
    final ReliableMessageListenerMock listener = new ReliableMessageListenerMock();
    String 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());
        }
    });
}
Also used : ITopic(com.hazelcast.core.ITopic) ReliableMessageListenerMock(com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ITopic (com.hazelcast.core.ITopic)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 ReliableMessageListenerMock (com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock)8 Test (org.junit.Test)8 AssertTask (com.hazelcast.test.AssertTask)7 Message (com.hazelcast.core.Message)1 ArrayList (java.util.ArrayList)1