Search in sources :

Example 6 with Message

use of com.hazelcast.core.Message in project hazelcast by hazelcast.

the class ClientReliableTopicTest method testRemoveListener.

@Test
public void testRemoveListener() {
    ITopic topic = client.getReliableTopic(randomString());
    MessageListener listener = new MessageListener() {

        public void onMessage(Message message) {
        }
    };
    String id = topic.addMessageListener(listener);
    assertTrue(topic.removeMessageListener(id));
}
Also used : ITopic(com.hazelcast.core.ITopic) Message(com.hazelcast.core.Message) MessageListener(com.hazelcast.core.MessageListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with Message

use of com.hazelcast.core.Message in project camel by apache.

the class HazelcastTopicConsumerTest method receive.

@Test
@SuppressWarnings("unchecked")
public void receive() throws InterruptedException {
    MockEndpoint out = getMockEndpoint("mock:received");
    out.expectedMessageCount(1);
    final Message<String> msg = new Message<String>("foo", "foo", new java.util.Date().getTime(), null);
    argument.getValue().onMessage(msg);
    assertMockEndpointsSatisfied(2000, TimeUnit.MILLISECONDS);
    this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.RECEIVED);
}
Also used : Message(com.hazelcast.core.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 8 with Message

use of com.hazelcast.core.Message in project camel by apache.

the class HazelcastReliableTopicConsumerTest method receive.

@Test
@SuppressWarnings("unchecked")
public void receive() throws InterruptedException {
    MockEndpoint out = getMockEndpoint("mock:received");
    out.expectedMessageCount(1);
    final Message<String> msg = new Message<String>("foo", "foo", new java.util.Date().getTime(), null);
    argument.getValue().onMessage(msg);
    assertMockEndpointsSatisfied(2000, TimeUnit.MILLISECONDS);
    this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.RECEIVED);
}
Also used : Message(com.hazelcast.core.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 9 with Message

use of com.hazelcast.core.Message 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.core.ITopic) Message(com.hazelcast.core.Message) MessageListener(com.hazelcast.core.MessageListener) ArrayList(java.util.ArrayList)

Example 10 with Message

use of com.hazelcast.core.Message in project hazelcast by hazelcast.

the class ReliableMessageListenerRunner method toMessage.

private Message<E> toMessage(ReliableTopicMessage m) {
    MemberImpl member = clusterService.getMember(m.getPublisherAddress());
    E payload = serializationService.toObject(m.getPayload());
    return new Message<E>(topicName, payload, m.getPublishTime(), member);
}
Also used : Message(com.hazelcast.core.Message) MemberImpl(com.hazelcast.instance.MemberImpl)

Aggregations

Message (com.hazelcast.core.Message)18 Test (org.junit.Test)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 MessageListener (com.hazelcast.core.MessageListener)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 ITopic (com.hazelcast.core.ITopic)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 NightlyTest (com.hazelcast.test.annotation.NightlyTest)7 Config (com.hazelcast.config.Config)4 ListenerConfig (com.hazelcast.config.ListenerConfig)4 Member (com.hazelcast.core.Member)3 AssertTask (com.hazelcast.test.AssertTask)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 MemberImpl (com.hazelcast.instance.MemberImpl)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 LocalTopicStatsImpl (com.hazelcast.monitor.impl.LocalTopicStatsImpl)1