use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MembershipListenerTest method initialMemberEvents_whenAddedViaConfig.
@Test
public void initialMemberEvents_whenAddedViaConfig() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
final InitialMemberShipEventLogger listener = new InitialMemberShipEventLogger();
clientConfig.addListenerConfig(new ListenerConfig().setImplementation(listener));
hazelcastFactory.newHazelcastClient(clientConfig);
EventObject eventObject = listener.events.poll(ASSERT_TRUE_EVENTUALLY_TIMEOUT, TimeUnit.SECONDS);
assertInstanceOf(InitialMembershipEvent.class, eventObject);
InitialMembershipEvent event = (InitialMembershipEvent) eventObject;
assertEquals(2, event.getMembers().size());
assertEquals(0, listener.events.size());
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MembershipListenerTest method testAddInitialMembership_whenListenerAddedViaClientConfig.
/**
* related to issue #1181
*/
@Test
public void testAddInitialMembership_whenListenerAddedViaClientConfig() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.addListenerConfig(new ListenerConfig().setImplementation(mock(InitialMembershipListener.class)));
hazelcastFactory.newHazelcastClient(clientConfig);
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class MembershipListenerTest method givenMixOfListenerExists_whenConnect_thenCallInitialMembershipListener.
@Test
public void givenMixOfListenerExists_whenConnect_thenCallInitialMembershipListener() throws Exception {
hazelcastFactory.newHazelcastInstance();
final ClientConfig config = new ClientConfig();
// first add bunch of *regular* MembershipListener. They do not implement InitialMembershipListener
config.addListenerConfig(new ListenerConfig().setImplementation(new MemberShipEventLogger()));
config.addListenerConfig(new ListenerConfig().setImplementation(new MemberShipEventLogger()));
config.addListenerConfig(new ListenerConfig().setImplementation(new MemberShipEventLogger()));
// now add an InitialMembershipListener
// if there is an exception thrown during event delivery to regular listeners
// then no event will likely be delivered to InitialMemberShipEventLogger
final InitialMemberShipEventLogger initialListener = new InitialMemberShipEventLogger();
config.addListenerConfig(new ListenerConfig().setImplementation(initialListener));
//connect to a grid
hazelcastFactory.newHazelcastClient(config);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Expecting one event", 1, initialListener.events.size());
InitialMembershipEvent event = (InitialMembershipEvent) initialListener.events.getLast();
assertEquals(1, event.getMembers().size());
}
});
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class ClientServiceTest method testClientListener_fromConfig.
@Test
public void testClientListener_fromConfig() {
Config config = new Config();
final CountDownLatch connectedLatch = new CountDownLatch(1);
final CountDownLatch disconnectedLatch = new CountDownLatch(1);
ListenerConfig listenerConfig = new ListenerConfig(new ClientListener() {
@Override
public void clientConnected(Client client) {
connectedLatch.countDown();
}
@Override
public void clientDisconnected(Client client) {
disconnectedLatch.countDown();
}
});
config.addListenerConfig(listenerConfig);
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
client.shutdown();
assertOpenEventually(connectedLatch);
assertOpenEventually(disconnectedLatch);
instance.shutdown();
}
use of com.hazelcast.config.ListenerConfig in project hazelcast by hazelcast.
the class ClientServiceTest method testConnectedClientsWithReAuth.
@Test(timeout = 120000)
public void testConnectedClientsWithReAuth() throws InterruptedException {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptPeriod(1000 * 5);
clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
final CountDownLatch countDownLatch = new CountDownLatch(2);
clientConfig.addListenerConfig(new ListenerConfig(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleEvent.LifecycleState.CLIENT_CONNECTED) {
countDownLatch.countDown();
}
}
}));
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
//restart the node
instance.shutdown();
final HazelcastInstance restartedInstance = hazelcastFactory.newHazelcastInstance();
// do any operation
client.getMap(randomMapName()).size();
//wait for clients to reconnect & reAuth
assertOpenEventually(countDownLatch);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, restartedInstance.getClientService().getConnectedClients().size());
}
});
}
Aggregations