Search in sources :

Example 6 with ListenerConfig

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

the class TestFullApplicationContext method testReliableTopicConfig.

@Test
public void testReliableTopicConfig() {
    ReliableTopicConfig testReliableTopic = config.getReliableTopicConfig("testReliableTopic");
    assertNotNull(testReliableTopic);
    assertEquals("testReliableTopic", testReliableTopic.getName());
    assertEquals(1, testReliableTopic.getMessageListenerConfigs().size());
    assertEquals(false, testReliableTopic.isStatisticsEnabled());
    ListenerConfig listenerConfig = testReliableTopic.getMessageListenerConfigs().get(0);
    assertEquals("com.hazelcast.spring.DummyMessageListener", listenerConfig.getClassName());
    assertEquals(10, testReliableTopic.getReadBatchSize());
    assertEquals(TopicOverloadPolicy.BLOCK, testReliableTopic.getTopicOverloadPolicy());
}
Also used : EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 7 with ListenerConfig

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

the class TopicProxySupport method initialize.

@Override
public void initialize() {
    NodeEngine nodeEngine = getNodeEngine();
    TopicConfig config = nodeEngine.getConfig().findTopicConfig(name);
    multithreaded = config.isMultiThreadingEnabled();
    for (ListenerConfig listenerConfig : config.getMessageListenerConfigs()) {
        initialize(listenerConfig);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ListenerConfig(com.hazelcast.config.ListenerConfig) TopicConfig(com.hazelcast.config.TopicConfig)

Example 8 with ListenerConfig

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

the class ClusterMembershipTest method testMembershipListenerSequentialInvocation.

@Test
public void testMembershipListenerSequentialInvocation() throws Exception {
    final int nodeCount = 10;
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final CountDownLatch eventLatch = new CountDownLatch(nodeCount - 1);
    final CountDownLatch nodeLatch = new CountDownLatch(nodeCount - 1);
    Config config = new Config().addListenerConfig(new ListenerConfig().setImplementation(newAddMemberListener(eventLatch)));
    // first node has listener
    factory.newHazelcastInstance(config);
    for (int i = 1; i < nodeCount; i++) {
        executorService.execute(new Runnable() {

            public void run() {
                factory.newHazelcastInstance(new Config());
                nodeLatch.countDown();
            }
        });
    }
    assertOpenEventually(nodeLatch);
    assertOpenEventually(eventLatch);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with ListenerConfig

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

the class SplitBrainHandlerTest method testTcpIpSplitBrainJoinsCorrectCluster.

@Test
public void testTcpIpSplitBrainJoinsCorrectCluster() throws Exception {
    // This port selection ensures that when h3 restarts it will try to join h4 instead of joining the nodes in cluster one
    Config c1 = buildConfig(false, 15702);
    Config c2 = buildConfig(false, 15704);
    Config c3 = buildConfig(false, 15703);
    Config c4 = buildConfig(false, 15701);
    List<String> clusterOneMembers = Arrays.asList("127.0.0.1:15702", "127.0.0.1:15704");
    List<String> clusterTwoMembers = Arrays.asList("127.0.0.1:15703", "127.0.0.1:15701");
    c1.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterOneMembers);
    c2.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterOneMembers);
    c3.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterTwoMembers);
    c4.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterTwoMembers);
    final CountDownLatch latch = new CountDownLatch(2);
    c3.addListenerConfig(new ListenerConfig(new MergedEventLifeCycleListener(latch)));
    c4.addListenerConfig(new ListenerConfig(new MergedEventLifeCycleListener(latch)));
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(c1);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(c2);
    HazelcastInstance h3 = Hazelcast.newHazelcastInstance(c3);
    HazelcastInstance h4 = Hazelcast.newHazelcastInstance(c4);
    // We should have two clusters of two
    assertEquals(2, h1.getCluster().getMembers().size());
    assertEquals(2, h2.getCluster().getMembers().size());
    assertEquals(2, h3.getCluster().getMembers().size());
    assertEquals(2, h4.getCluster().getMembers().size());
    List<String> allMembers = Arrays.asList("127.0.0.1:15701", "127.0.0.1:15704", "127.0.0.1:15703", "127.0.0.1:15702");
    /*
         * This simulates restoring a network connection between h3 and the
         * other cluster. But it only make h3 aware of the other cluster so for
         * h4 to restart it will have to be notified by h3.
         */
    h3.getConfig().getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
    h4.getConfig().getNetworkConfig().getJoin().getTcpIpConfig().clear().setMembers(Collections.<String>emptyList());
    assertTrue(latch.await(60, TimeUnit.SECONDS));
    // Both nodes from cluster two should have joined cluster one
    assertEquals(4, h1.getCluster().getMembers().size());
    assertEquals(4, h2.getCluster().getMembers().size());
    assertEquals(4, h3.getCluster().getMembers().size());
    assertEquals(4, h4.getCluster().getMembers().size());
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) CountDownLatch(java.util.concurrent.CountDownLatch) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 10 with ListenerConfig

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

the class QueueAdvancedTest method testDeadTaker.

/**
     * Test for issue 730 (Google).
     */
@Test
public void testDeadTaker() throws Exception {
    Config config = new Config();
    final CountDownLatch shutdownLatch = new CountDownLatch(1);
    config.addListenerConfig(new ListenerConfig().setImplementation(new MembershipListener() {

        @Override
        public void memberAdded(MembershipEvent membershipEvent) {
        }

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            shutdownLatch.countDown();
        }

        @Override
        public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
        }
    }));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = factory.newInstances(config);
    final HazelcastInstance h1 = instances[0];
    final HazelcastInstance h2 = instances[1];
    warmUpPartitions(h1, h2);
    final IQueue<String> q1 = h1.getQueue("default");
    final IQueue<String> q2 = h2.getQueue("default");
    final CountDownLatch startLatch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                assertTrue("Expected startLatch.await() to succeed within 10 seconds", startLatch.await(10, SECONDS));
                Thread.sleep(5000);
                h2.getLifecycleService().terminate();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                startLatch.countDown();
                String value = q2.take();
                fail("Should not be able to take value from queue, but got: " + value);
            } catch (HazelcastInstanceNotActiveException e) {
                EmptyStatement.ignore(e);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
    assertTrue("Expected shutdownLatch.await() to succeed within 1 minute", shutdownLatch.await(1, MINUTES));
    q1.offer("item");
    assertEquals(1, q1.size());
    assertEquals("item", q1.poll());
}
Also used : MemberAttributeEvent(com.hazelcast.core.MemberAttributeEvent) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MembershipEvent(com.hazelcast.core.MembershipEvent) CountDownLatch(java.util.concurrent.CountDownLatch) TestThread(com.hazelcast.test.TestThread) ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MembershipListener(com.hazelcast.core.MembershipListener) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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