use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testDeadlock_WhenDoingOperationFromLifecycleListenerWithInitialPartitionTable.
@Test
public void testDeadlock_WhenDoingOperationFromLifecycleListenerWithInitialPartitionTable() {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final ClientConfig clientConfig = new ClientConfig();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig.setExecutorPoolSize(1));
hazelcastFactory.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
final IMap<Object, Object> map = client.getMap(randomMapName());
// Let the partition table retrieved the first time
map.get(1);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleState.CLIENT_DISCONNECTED) {
for (int i = 0; i < 1000; i++) {
map.get(i);
}
latch.countDown();
}
}
});
instance.shutdown();
assertOpenEventually(latch);
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientReconnectTest method testClientReconnectOnClusterDown.
@Test
public void testClientReconnectOnClusterDown() throws Exception {
final HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final CountDownLatch connectedLatch = new CountDownLatch(2);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
connectedLatch.countDown();
}
});
IMap<String, String> m = client.getMap("default");
h1.shutdown();
hazelcastFactory.newHazelcastInstance();
assertOpenEventually(connectedLatch);
assertNull(m.put("test", "test"));
assertEquals("test", m.get("test"));
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache.
@Test
public void testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache() {
String mapName = randomMapName();
EvictionConfig evictionConfig = new EvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(1);
NearCacheConfig nearCacheConfig = new NearCacheConfig().setName(mapName).setEvictionConfig(evictionConfig);
ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(nearCacheConfig).setExecutorPoolSize(1);
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
hazelcastFactory.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
final IMap<Object, Object> map = client.getMap(mapName);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleState.CLIENT_DISCONNECTED) {
map.get(1);
map.get(2);
latch.countDown();
}
}
});
instance.shutdown();
assertOpenEventually(latch);
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testAuthentication_whenHeartbeatResumed.
@Test
public void testAuthentication_whenHeartbeatResumed() throws Exception {
HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
ClientConfig config = new ClientConfig();
config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
HazelcastClientInstanceImpl hazelcastClientInstanceImpl = getHazelcastClientInstanceImpl(client);
final ClusterListenerSupport clientClusterService = (ClusterListenerSupport) hazelcastClientInstanceImpl.getClientClusterService();
final CountDownLatch countDownLatch = new CountDownLatch(2);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
countDownLatch.countDown();
}
});
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
blockMessagesFromInstance(instance2, client);
final HazelcastInstance instance3 = hazelcastFactory.newHazelcastInstance();
hazelcastInstance.shutdown();
//wait for disconnect from instance1 since it is shutdown // CLIENT_DISCONNECTED event
//and wait for connect to from instance3 // CLIENT_CONNECTED event
assertOpenEventually(countDownLatch);
//verify and wait for authentication to 3 is complete
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
String uuid = instance3.getLocalEndpoint().getUuid();
assertEquals(uuid, getClientEngineImpl(instance3).getOwnerUuid(client.getLocalEndpoint().getUuid()));
assertEquals(uuid, getClientEngineImpl(instance2).getOwnerUuid(client.getLocalEndpoint().getUuid()));
assertEquals(uuid, clientClusterService.getPrincipal().getOwnerUuid());
assertEquals(instance3.getCluster().getLocalMember().getAddress(), clientClusterService.getOwnerConnectionAddress());
}
});
//unblock instance 2 for authentication response.
unblockMessagesFromInstance(instance2, client);
//late authentication response from instance2 should not be able to change state in both client and cluster
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
String uuid = instance3.getLocalEndpoint().getUuid();
assertEquals(uuid, getClientEngineImpl(instance3).getOwnerUuid(client.getLocalEndpoint().getUuid()));
assertEquals(uuid, getClientEngineImpl(instance2).getOwnerUuid(client.getLocalEndpoint().getUuid()));
assertEquals(uuid, clientClusterService.getPrincipal().getOwnerUuid());
assertEquals(instance3.getCluster().getLocalMember().getAddress(), clientClusterService.getOwnerConnectionAddress());
}
});
}
use of com.hazelcast.core.LifecycleEvent in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method testListenersWaitMemberDestroySmartRouting.
//-------------------------- testListenersWaitMemberDestroy --------------------- //
@Test
public void testListenersWaitMemberDestroySmartRouting() {
Config config = new Config();
int endpointDelaySeconds = 2;
config.setProperty(GroupProperty.CLIENT_ENDPOINT_REMOVE_DELAY_SECONDS.getName(), String.valueOf(endpointDelaySeconds));
factory.newInstances(config, 3);
client = factory.newHazelcastClient(getSmartClientConfig());
setupListener();
Collection<HazelcastInstance> allHazelcastInstances = factory.getAllHazelcastInstances();
final CountDownLatch disconnectedLatch = new CountDownLatch(1);
final CountDownLatch connectedLatch = new CountDownLatch(1);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (LifecycleEvent.LifecycleState.CLIENT_DISCONNECTED == event.getState()) {
disconnectedLatch.countDown();
}
if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
connectedLatch.countDown();
}
}
});
final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(3, clientInstanceImpl.getConnectionManager().getActiveConnections().size());
}
});
HazelcastInstance ownerMember = getOwnerServer(factory, clientInstanceImpl);
for (HazelcastInstance member : allHazelcastInstances) {
blockMessagesFromInstance(member, client);
}
ownerMember.getLifecycleService().terminate();
for (HazelcastInstance member : allHazelcastInstances) {
unblockMessagesFromInstance(member, client);
}
assertOpenEventually(disconnectedLatch);
assertOpenEventually(connectedLatch);
sleepAtLeastMillis(endpointDelaySeconds * 1000 + 2000);
clusterSize = clusterSize - 1;
validateRegistrationsAndListenerFunctionality();
}
Aggregations