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());
}
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);
}
}
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);
}
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());
}
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());
}
Aggregations