use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class LifeCycleListenerTest method testListenerInvocationWhenNodeStarts.
@Test
public void testListenerInvocationWhenNodeStarts() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
final Config config = new Config();
final EventCountingListener listener = new EventCountingListener();
config.addListenerConfig(new ListenerConfig(listener));
factory.newHazelcastInstance(config);
assertEquals(LifecycleState.STARTING, listener.events.get(0));
assertEquals(LifecycleState.STARTED, listener.events.get(1));
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class LifeCycleListenerTest method testListenerInvocationWhenNodeTerminates.
@Test
public void testListenerInvocationWhenNodeTerminates() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
final Config config = new Config();
final EventCountingListener listener = new EventCountingListener();
config.addListenerConfig(new ListenerConfig(listener));
HazelcastInstance instance = factory.newHazelcastInstance(config);
listener.events.clear();
instance.getLifecycleService().terminate();
assertEquals(LifecycleState.SHUTTING_DOWN, listener.events.get(0));
assertEquals(LifecycleState.SHUTDOWN, listener.events.get(1));
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MigrationCommitTest method shouldRollbackMigrationWhenMasterCrashesBeforeCommit.
@Test
public void shouldRollbackMigrationWhenMasterCrashesBeforeCommit() {
CountDownLatch migrationStartLatch = new CountDownLatch(1);
Config config1 = createConfig();
config1.setLiteMember(true);
HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
warmUpPartitions(hz1, hz2);
waitAllForSafeState(hz1, hz2);
final TerminateOtherMemberOnMigrationComplete listener3 = new TerminateOtherMemberOnMigrationComplete(migrationStartLatch);
listener3.other = hz1;
migrationStartLatch.countDown();
Config config3 = createConfig();
config3.addListenerConfig(new ListenerConfig(listener3));
HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
assertClusterSizeEventually(2, hz2);
assertClusterSizeEventually(2, hz3);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(listener3.rollback);
}
});
waitAllForSafeState(hz2, hz3);
factory.terminateAll();
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MigrationCommitTest method shouldCommitMigrationWhenSourceFailsDuringCommit.
@Test
public void shouldCommitMigrationWhenSourceFailsDuringCommit() {
CountDownLatch migrationStartLatch = new CountDownLatch(1);
Config config1 = createConfig();
config1.setLiteMember(true);
TerminateOtherMemberOnMigrationComplete masterListener = new TerminateOtherMemberOnMigrationComplete(migrationStartLatch);
config1.addListenerConfig(new ListenerConfig(masterListener));
HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
warmUpPartitions(hz1, hz2);
waitAllForSafeState(hz1, hz2);
Config config3 = createConfig();
InternalMigrationListenerImpl targetListener = new InternalMigrationListenerImpl();
config3.addListenerConfig(new ListenerConfig(targetListener));
HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
masterListener.other = hz2;
migrationStartLatch.countDown();
waitAllForSafeState(hz1, hz3);
InternalPartition partition0 = getPartitionService(hz3).getPartition(0);
InternalPartition partition1 = getPartitionService(hz3).getPartition(1);
assertEquals(getAddress(hz3), partition0.getOwnerOrNull());
assertEquals(getAddress(hz3), partition1.getOwnerOrNull());
assertFalse(partition0.isMigrating());
assertFalse(partition1.isMigrating());
assertFalse(masterListener.rollback);
List<MigrationProgressNotification> notifications = targetListener.getNotifications();
assertFalse(notifications.isEmpty());
assertEquals(COMMIT, notifications.get(notifications.size() - 1).event);
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MigrationCommitTest method shouldCommitMigrationWhenMasterCrashesAfterDestinationCommit.
@Test
public void shouldCommitMigrationWhenMasterCrashesAfterDestinationCommit() {
CountDownLatch migrationStartLatch = new CountDownLatch(1);
Config config1 = createConfig();
config1.setLiteMember(true);
HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
Config config2 = createConfig();
final CollectMigrationTaskOnCommit sourceListener = new CollectMigrationTaskOnCommit();
config2.addListenerConfig(new ListenerConfig(sourceListener));
HazelcastInstance hz2 = factory.newHazelcastInstance(config2);
warmUpPartitions(hz1, hz2);
waitAllForSafeState(hz1, hz2);
Config config3 = createConfig();
TerminateOtherMemberOnMigrationCommit destinationListener = new TerminateOtherMemberOnMigrationCommit(migrationStartLatch);
destinationListener.other = hz1;
config3.addListenerConfig(new ListenerConfig(destinationListener));
HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
migrationStartLatch.countDown();
waitAllForSafeState(hz2, hz3);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(sourceListener.commit);
}
});
InternalPartition hz2Partition = getOwnedPartition(hz2);
InternalPartition hz3Partition = getOwnedPartition(hz3);
assertNotNull(hz2Partition);
assertNotNull(hz3Partition);
assertNotEquals(hz2Partition, hz3Partition);
assertFalse(hz2Partition.isMigrating());
assertFalse(hz3Partition.isMigrating());
}
Aggregations