use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testMulticastJoin_DuringSplitBrainHandlerRunning.
@Test
public void testMulticastJoin_DuringSplitBrainHandlerRunning() throws InterruptedException {
String groupName = generateRandomString(10);
final CountDownLatch latch = new CountDownLatch(1);
Config config1 = new Config();
// bigger port to make sure address.hashCode() check pass during merge!
config1.getNetworkConfig().setPort(5901);
config1.getGroupConfig().setName(groupName);
config1.setProperty(GroupProperty.WAIT_SECONDS_BEFORE_JOIN.getName(), "5");
config1.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "0");
config1.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "0");
config1.addListenerConfig(new ListenerConfig(new LifecycleListener() {
public void stateChanged(final LifecycleEvent event) {
switch(event.getState()) {
case MERGING:
case MERGED:
latch.countDown();
default:
break;
}
}
}));
Hazelcast.newHazelcastInstance(config1);
Thread.sleep(5000);
Config config2 = new Config();
config2.getGroupConfig().setName(groupName);
config2.getNetworkConfig().setPort(5701);
config2.setProperty(GroupProperty.WAIT_SECONDS_BEFORE_JOIN.getName(), "5");
config2.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "0");
config2.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "0");
Hazelcast.newHazelcastInstance(config2);
assertFalse("Latch should not be countdown!", latch.await(3, TimeUnit.SECONDS));
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testTcpIpSplitBrainStillWorks_WhenTargetDisappears.
@Test
public void testTcpIpSplitBrainStillWorks_WhenTargetDisappears() throws Exception {
// The ports are ordered like this so h3 will always attempt to merge with h1
Config c1 = buildConfig(false, 25701);
Config c2 = buildConfig(false, 25704);
Config c3 = buildConfig(false, 25703);
List<String> clusterOneMembers = Arrays.asList("127.0.0.1:25701");
List<String> clusterTwoMembers = Arrays.asList("127.0.0.1:25704");
List<String> clusterThreeMembers = Arrays.asList("127.0.0.1:25703");
c1.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterOneMembers);
c2.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterTwoMembers);
c3.getNetworkConfig().getJoin().getTcpIpConfig().setMembers(clusterThreeMembers);
final HazelcastInstance h1 = Hazelcast.newHazelcastInstance(c1);
final HazelcastInstance h2 = Hazelcast.newHazelcastInstance(c2);
final CountDownLatch latch = new CountDownLatch(1);
c3.addListenerConfig(new ListenerConfig(new LifecycleListener() {
public void stateChanged(final LifecycleEvent event) {
if (event.getState() == LifecycleState.MERGING) {
h1.shutdown();
} else if (event.getState() == LifecycleState.MERGED) {
latch.countDown();
}
}
}));
final HazelcastInstance h3 = Hazelcast.newHazelcastInstance(c3);
// We should have three clusters of one
assertEquals(1, h1.getCluster().getMembers().size());
assertEquals(1, h2.getCluster().getMembers().size());
assertEquals(1, h3.getCluster().getMembers().size());
List<String> allMembers = Arrays.asList("127.0.0.1:25701", "127.0.0.1:25704", "127.0.0.1:25703");
h3.getConfig().getNetworkConfig().getJoin().getTcpIpConfig().setMembers(allMembers);
assertTrue(latch.await(60, TimeUnit.SECONDS));
// Both nodes from cluster two should have joined cluster one
assertFalse(h1.getLifecycleService().isRunning());
assertEquals(2, h2.getCluster().getMembers().size());
assertEquals(2, h3.getCluster().getMembers().size());
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class NodeShutdownEventsTest method testNodeShutdown_firesLifecycleEvents_afterJoinFailure.
/**
* When a node fails due to a join time out, it will be shutdowned.
* In that scenario we are expecting lifecycle events (SHUTTING_DOWN & SHUTDOWN)
* to be fired locally.
*/
@Test
public void testNodeShutdown_firesLifecycleEvents_afterJoinFailure() throws Exception {
// Only expecting SHUTTING_DOWN & SHUTDOWN events so latch count should be 2.
final CountDownLatch shutdownEventCount = new CountDownLatch(2);
final Config config1 = new Config();
final Config config2 = new Config();
// force join failure.
config2.setProperty(GroupProperty.MAX_JOIN_SECONDS.getName(), "-100");
// add lifecycle listener.
final ListenerConfig listenerConfig = new ListenerConfig();
listenerConfig.setImplementation(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
// Only expecting SHUTTING_DOWN & SHUTDOWN.
if (LifecycleEvent.LifecycleState.SHUTTING_DOWN.equals(event.getState()) || LifecycleEvent.LifecycleState.SHUTDOWN.equals(event.getState())) {
shutdownEventCount.countDown();
}
}
});
config2.addListenerConfig(listenerConfig);
final HazelcastInstance node1 = Hazelcast.newHazelcastInstance(config1);
try {
final HazelcastInstance node2 = Hazelcast.newHazelcastInstance(config2);
} catch (IllegalStateException e) {
// ignore IllegalStateException since we are only testing lifecyle events.
}
assertOpenEventually(shutdownEventCount);
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class InternalMigrationListenerTest method shouldInvokeInternalMigrationListenerOnSuccessfulMigration.
@Test
public void shouldInvokeInternalMigrationListenerOnSuccessfulMigration() {
final Config config1 = new Config();
config1.setProperty(GroupProperty.PARTITION_COUNT.getName(), String.valueOf(PARTITION_COUNT));
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
warmUpPartitions(hz1);
final InternalMigrationListenerImpl listener = new InternalMigrationListenerImpl();
final Config config2 = new Config();
config2.setProperty(GroupProperty.PARTITION_COUNT.getName(), String.valueOf(PARTITION_COUNT));
config2.addListenerConfig(new ListenerConfig(listener));
final HazelcastInstance hz2 = factory.newHazelcastInstance(config2);
waitAllForSafeState(hz1, hz2);
final List<Integer> hz2PartitionIds = getNodeEngineImpl(hz2).getPartitionService().getMemberPartitions(getAddress(hz2));
assertEquals(1, hz2PartitionIds.size());
final List<MigrationProgressNotification> notifications = listener.getNotifications();
int partition0Events = 0, partition1Events = 0;
assertEquals(6, notifications.size());
for (MigrationProgressNotification n : notifications) {
if (n.migrationInfo.getPartitionId() == 0) {
partition0Events++;
} else {
partition1Events++;
}
}
assertEquals(3, partition0Events);
assertEquals(3, partition1Events);
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MigrationCommitTest method shouldNotEvictCompletedMigrationsWhenSomeMembersDoNotAckPublishedPartitionTableAfterSuccessfulMigration.
@Test
public void shouldNotEvictCompletedMigrationsWhenSomeMembersDoNotAckPublishedPartitionTableAfterSuccessfulMigration() {
CountDownLatch migrationStartLatch = new CountDownLatch(1);
CountDownLatch migrationCommitLatch = new CountDownLatch(1);
Config config1 = createConfig();
config1.setLiteMember(true);
final AssertNonEmptyCompletedMigrationsOnSecondMigrationStart masterListener = new AssertNonEmptyCompletedMigrationsOnSecondMigrationStart();
config1.addListenerConfig(new ListenerConfig(masterListener));
HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
Config config2 = createConfig();
config2.addListenerConfig(new ListenerConfig(new DelayMigrationCommit(migrationCommitLatch)));
HazelcastInstance hz2 = factory.newHazelcastInstance(config2);
warmUpPartitions(hz1, hz2);
waitAllForSafeState(hz1, hz2);
factory.newHazelcastInstance(createConfig());
migrationStartLatch.countDown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotNull(masterListener.nonEmptyCompletedMigrationsVerified);
assertTrue(masterListener.nonEmptyCompletedMigrationsVerified);
}
});
migrationCommitLatch.countDown();
}
Aggregations