Search in sources :

Example 1 with ReliableMessageListenerMock

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);
}
Also used : ITopic(com.hazelcast.core.ITopic) ReliableMessageListenerMock(com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with ReliableMessageListenerMock

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);
        }
    });
}
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 3 with ReliableMessageListenerMock

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()));
        }
    });
}
Also used : ITopic(com.hazelcast.core.ITopic) ReliableMessageListenerMock(com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock) ArrayList(java.util.ArrayList) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ReliableMessageListenerMock

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());
        }
    });
}
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 5 with ReliableMessageListenerMock

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);
        }
    });
}
Also used : ITopic(com.hazelcast.core.ITopic) Message(com.hazelcast.core.Message) 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