Search in sources :

Example 21 with ListenerConfig

use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.

the class ReliableTopicCreateTest method testConfiguredListenerClassAndHazelcastInstanceAware.

@Test
public void testConfiguredListenerClassAndHazelcastInstanceAware() {
    Config config = new Config();
    config.addReliableTopicConfig(new ReliableTopicConfig("foo*").addMessageListenerConfig(new ListenerConfig(InstanceAwareReliableMessageListenerMock.class.getName())));
    HazelcastInstance hz = createHazelcastInstance(config);
    ITopic topic = hz.getReliableTopic("foo");
    ReliableTopicProxy proxy = assertInstanceOf(ReliableTopicProxy.class, topic);
    // check there is one listener.
    assertEquals(1, proxy.runnersMap.size());
    // check that the listener is of the right class.
    ReliableMessageListenerRunner runner = (ReliableMessageListenerRunner) proxy.runnersMap.values().iterator().next();
    InstanceAwareReliableMessageListenerMock mock = assertInstanceOf(InstanceAwareReliableMessageListenerMock.class, runner.listener);
    assertNotNull(mock.hz);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ITopic(com.hazelcast.core.ITopic) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with ListenerConfig

use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.

the class ReliableTopicCreateTest method testConfiguredListenerClassNotExist.

@Test(expected = HazelcastException.class)
public void testConfiguredListenerClassNotExist() {
    Config config = new Config();
    config.addReliableTopicConfig(new ReliableTopicConfig("foo*").addMessageListenerConfig(new ListenerConfig("kfosajdajdksajdj")));
    HazelcastInstance hz = createHazelcastInstance(config);
    hz.getReliableTopic("foo");
    fail();
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with ListenerConfig

use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.

the class ReliableTopicCreateTest method testConfiguredListenerInstance.

@Test
public void testConfiguredListenerInstance() {
    final ReliableMessageListenerMock messageListener = new ReliableMessageListenerMock();
    Config config = new Config();
    config.addReliableTopicConfig(new ReliableTopicConfig("foo*").addMessageListenerConfig(new ListenerConfig(messageListener)));
    HazelcastInstance hz = createHazelcastInstance(config);
    ITopic<String> topic = hz.getReliableTopic("foo");
    ReliableTopicProxy proxy = assertInstanceOf(ReliableTopicProxy.class, topic);
    assertEquals(1, proxy.runnersMap.size());
    topic.publish("item");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertContains(messageListener.objects, "item");
        }
    });
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) HazelcastException(com.hazelcast.core.HazelcastException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with ListenerConfig

use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.

the class TopicTest method testConfigListenerRegistration.

@Test
public void testConfigListenerRegistration() throws InterruptedException {
    String topicName = "default";
    Config config = new Config();
    final CountDownLatch latch = new CountDownLatch(1);
    config.getTopicConfig(topicName).addMessageListenerConfig(new ListenerConfig().setImplementation(new MessageListener() {

        public void onMessage(Message message) {
            latch.countDown();
        }
    }));
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.getTopic(topicName).publish(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Message(com.hazelcast.core.Message) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MessageListener(com.hazelcast.core.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with ListenerConfig

use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.

the class PartitionLostListenerRegistrationTest method test_partitionLostListener_whenListenerRegisteredViaConfiguration.

@Test
public void test_partitionLostListener_whenListenerRegisteredViaConfiguration() {
    final Config config = new Config();
    config.addListenerConfig(new ListenerConfig(mock(PartitionLostListener.class)));
    final HazelcastInstance instance = createHazelcastInstance(config);
    assertRegistrationsSizeEventually(instance, 1);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ListenerConfig(com.hazelcast.config.ListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ListenerConfig (com.hazelcast.config.ListenerConfig)46 Test (org.junit.Test)43 QuickTest (com.hazelcast.test.annotation.QuickTest)40 Config (com.hazelcast.config.Config)30 HazelcastInstance (com.hazelcast.core.HazelcastInstance)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 CountDownLatch (java.util.concurrent.CountDownLatch)22 AssertTask (com.hazelcast.test.AssertTask)11 ClientConfig (com.hazelcast.client.config.ClientConfig)10 NightlyTest (com.hazelcast.test.annotation.NightlyTest)9 ReliableTopicConfig (com.hazelcast.config.ReliableTopicConfig)8 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 RingbufferConfig (com.hazelcast.config.RingbufferConfig)6 LifecycleListener (com.hazelcast.core.LifecycleListener)6 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)5 LifecycleEvent (com.hazelcast.core.LifecycleEvent)5 ItemListenerConfig (com.hazelcast.config.ItemListenerConfig)4 MapPartitionLostListenerConfig (com.hazelcast.config.MapPartitionLostListenerConfig)4 ClientListener (com.hazelcast.core.ClientListener)4 InternalPartition (com.hazelcast.internal.partition.InternalPartition)4