Search in sources :

Example 16 with ITopic

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));
}
Also used : ITopic(com.hazelcast.topic.ITopic) Message(com.hazelcast.topic.Message) MessageListener(com.hazelcast.topic.MessageListener) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with ITopic

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

Example 18 with ITopic

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

Example 19 with ITopic

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

Example 20 with ITopic

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;
}
Also used : ITopic(com.hazelcast.topic.ITopic) Message(com.hazelcast.topic.Message) MessageListener(com.hazelcast.topic.MessageListener) ArrayList(java.util.ArrayList)

Aggregations

ITopic (com.hazelcast.topic.ITopic)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 DurableSubscriptionTest (com.hazelcast.topic.impl.reliable.DurableSubscriptionTest)12 UUID (java.util.UUID)8 ReliableMessageListenerMock (com.hazelcast.topic.impl.reliable.ReliableMessageListenerMock)7 AssertTask (com.hazelcast.test.AssertTask)6 Message (com.hazelcast.topic.Message)6 Config (com.hazelcast.config.Config)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 MessageListener (com.hazelcast.topic.MessageListener)5 ClientConfig (com.hazelcast.client.config.ClientConfig)3 ClientProperty (com.hazelcast.client.properties.ClientProperty)3 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)3 ListenerConfig (com.hazelcast.config.ListenerConfig)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClientReliableTopicProxy (com.hazelcast.client.impl.proxy.ClientReliableTopicProxy)2 ReliableTopicConfig (com.hazelcast.config.ReliableTopicConfig)2 RingbufferConfig (com.hazelcast.config.RingbufferConfig)2