use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MigrationCommitTest method shouldRollbackMigrationWhenDestinationCrashesDuringCommit.
@Test
public void shouldRollbackMigrationWhenDestinationCrashesDuringCommit() {
CountDownLatch migrationStartLatch = new CountDownLatch(1);
Config config1 = createConfig();
config1.setLiteMember(true);
DelayMigrationStartOnMaster masterListener = new DelayMigrationStartOnMaster(migrationStartLatch);
config1.addListenerConfig(new ListenerConfig(masterListener));
HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
warmUpPartitions(hz1, hz2);
waitAllForSafeState(hz1, hz2);
CountDownLatch terminationLatch = new CountDownLatch(1);
TerminateOnMigrationCommit memberListener = new TerminateOnMigrationCommit(terminationLatch);
Config config3 = createConfig();
config3.addListenerConfig(new ListenerConfig(memberListener));
HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
warmUpPartitions(hz1, hz2, hz3);
migrationStartLatch.countDown();
waitAllForSafeState(hz1, hz2);
InternalPartition partition0 = getPartitionService(hz1).getPartition(0);
InternalPartition partition1 = getPartitionService(hz1).getPartition(1);
assertEquals(getAddress(hz2), partition0.getOwnerOrNull());
assertEquals(getAddress(hz2), partition1.getOwnerOrNull());
assertFalse(partition0.isMigrating());
assertFalse(partition1.isMigrating());
assertTrue(masterListener.rollback.get());
terminationLatch.countDown();
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MigrationCommitTest method shouldRollbackMigrationWhenDestinationCrashesBeforeCommit.
@Test
public void shouldRollbackMigrationWhenDestinationCrashesBeforeCommit() {
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);
masterListener.other = factory.newHazelcastInstance(createConfig());
migrationStartLatch.countDown();
sleepAtLeastSeconds(10);
waitAllForSafeState(hz1, hz2);
InternalPartition partition0 = getPartitionService(hz2).getPartition(0);
InternalPartition partition1 = getPartitionService(hz2).getPartition(1);
assertEquals(getAddress(hz2), partition0.getOwnerOrNull());
assertEquals(getAddress(hz2), partition1.getOwnerOrNull());
assertFalse(partition0.isMigrating());
assertFalse(partition1.isMigrating());
assertTrue(masterListener.rollback);
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class ReliableTopicCreateTest method testConfiguredListenerClassNotMessageListener.
@Test(expected = HazelcastException.class)
public void testConfiguredListenerClassNotMessageListener() {
Config config = new Config();
config.addReliableTopicConfig(new ReliableTopicConfig("foo*").addMessageListenerConfig(new ListenerConfig(String.class.getName())));
HazelcastInstance hz = createHazelcastInstance(config);
hz.getReliableTopic("foo");
fail();
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class ReliableTopicCreateTest method testConfiguredListenerInstanceHazelcastInstanceAware.
@Test
public void testConfiguredListenerInstanceHazelcastInstanceAware() {
final InstanceAwareReliableMessageListenerMock messageListener = new InstanceAwareReliableMessageListenerMock();
Config config = new Config();
config.addReliableTopicConfig(new ReliableTopicConfig("foo*").addMessageListenerConfig(new ListenerConfig(messageListener)));
HazelcastInstance hz = createHazelcastInstance(config);
ITopic<String> topic = hz.getReliableTopic("foo");
ReliableTopicProxy proxy = assertInstanceOf(ReliableTopicProxy.class, topic);
assertEquals(1, proxy.runnersMap.size());
assertNotNull(messageListener.hz);
topic.publish("item");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertContains(messageListener.objects, "item");
}
});
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class ReliableTopicCreateTest method testConfiguredListenerClass.
@Test
public void testConfiguredListenerClass() {
Config config = new Config();
config.addReliableTopicConfig(new ReliableTopicConfig("foo*").addMessageListenerConfig(new ListenerConfig(ReliableMessageListenerMock.class.getName())));
HazelcastInstance hz = createHazelcastInstance(config);
ITopic topic = hz.getReliableTopic("foo");
ReliableTopicProxy proxy = assertInstanceOf(ReliableTopicProxy.class, topic);
// check there is one listener.
assertEquals(1, proxy.runnersMap.size());
// check that the listener is of the right class.
ReliableMessageListenerRunner runner = (ReliableMessageListenerRunner) proxy.runnersMap.values().iterator().next();
assertInstanceOf(ReliableMessageListenerMock.class, runner.listener);
}
Aggregations