use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientServiceTest method testClientListenerDisconnected.
@Test(timeout = 120000)
public void testClientListenerDisconnected() throws InterruptedException {
Config config = new Config();
config.setProperty(GroupProperty.IO_THREAD_COUNT.getName(), "1");
final HazelcastInstance hz = hazelcastFactory.newHazelcastInstance(config);
final HazelcastInstance hz2 = hazelcastFactory.newHazelcastInstance(config);
int clientCount = 10;
ClientDisconnectedListenerLatch listenerLatch = new ClientDisconnectedListenerLatch(2 * clientCount);
hz.getClientService().addClientListener(listenerLatch);
hz2.getClientService().addClientListener(listenerLatch);
Collection<HazelcastInstance> clients = new LinkedList<HazelcastInstance>();
for (int i = 0; i < clientCount; i++) {
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
IMap<Object, Object> map = client.getMap(randomMapName());
map.addEntryListener(new EntryAdapter<Object, Object>(), true);
map.put(generateKeyOwnedBy(hz), "value");
map.put(generateKeyOwnedBy(hz2), "value");
clients.add(client);
}
ExecutorService ex = Executors.newFixedThreadPool(4);
try {
for (final HazelcastInstance client : clients) {
ex.execute(new Runnable() {
@Override
public void run() {
client.shutdown();
}
});
}
assertOpenEventually(listenerLatch);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, hz.getClientService().getConnectedClients().size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, hz2.getClientService().getConnectedClients().size());
}
});
} finally {
ex.shutdown();
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientSplitBrainTest method checkEventsEventually.
private void checkEventsEventually(final AtomicBoolean[] listenerGotEventFlags) {
for (int i = 0; i < listenerGotEventFlags.length; i++) {
final int id = i;
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue("listener id " + id, listenerGotEventFlags[id].get());
}
});
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testNearCache_WhenRegisteredNodeIsDead.
@Test
public void testNearCache_WhenRegisteredNodeIsDead() {
final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
final String mapName = randomMapName();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setName(mapName);
nearCacheConfig.setInvalidateOnChange(true);
clientConfig.addNearCacheConfig(nearCacheConfig);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final IMap<Object, Object> map = client.getMap(mapName);
map.put("a", "b");
// populate Near Cache
map.get("a");
instance.shutdown();
hazelcastFactory.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(null, map.get("a"));
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientOwnershipTest method test_ownerShip_afterClusterRestart.
@Test
public void test_ownerShip_afterClusterRestart() {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
instance.shutdown();
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
// wait for client to connect to node
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, client.getCluster().getMembers().size());
assertEquals(1, instance2.getCluster().getMembers().size());
}
});
final String instanceUuid = instance2.getLocalEndpoint().getUuid();
final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
final String clientUuid = client.getLocalEndpoint().getUuid();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientOwnershipTest method test_clientOwnedInfoPropagatedToAllMembers.
@Test
public void test_clientOwnedInfoPropagatedToAllMembers() {
HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
final String instanceUuid = instance1.getLocalEndpoint().getUuid();
final String clientUuid = client.getLocalEndpoint().getUuid();
final ClientEngineImpl clientEngine1 = getClientEngineImpl(instance1);
final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(instanceUuid, clientEngine1.getOwnerUuid(clientUuid));
assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
}
});
}
Aggregations