Search in sources :

Example 11 with ListenerConfig

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));
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) ListenerConfig(com.hazelcast.config.ListenerConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with ListenerConfig

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));
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ListenerConfig(com.hazelcast.config.ListenerConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with ListenerConfig

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();
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with ListenerConfig

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);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MigrationProgressNotification(com.hazelcast.internal.partition.impl.InternalMigrationListenerTest.MigrationProgressNotification) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) InternalMigrationListenerImpl(com.hazelcast.internal.partition.impl.InternalMigrationListenerTest.InternalMigrationListenerImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with ListenerConfig

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());
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) 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