use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientConnectionTest method testAsyncConnectionCreationInAsyncMethods.
@Test
public void testAsyncConnectionCreationInAsyncMethods() throws ExecutionException, InterruptedException {
hazelcastFactory.newHazelcastInstance();
CountDownLatch countDownLatch = new CountDownLatch(1);
ClientConfig config = new ClientConfig();
WaitingCredentials credentials = new WaitingCredentials("dev", "dev-pass", countDownLatch);
config.setCredentials(credentials);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
final IExecutorService executorService = client.getExecutorService(randomString());
credentials.waitFlag.set(true);
final HazelcastInstance secondInstance = hazelcastFactory.newHazelcastInstance();
final AtomicReference<Future> atomicReference = new AtomicReference<Future>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Member secondMember = secondInstance.getCluster().getLocalMember();
Future future = executorService.submitToMember(new DummySerializableCallable(), secondMember);
atomicReference.set(future);
}
});
thread.start();
try {
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotNull(atomicReference.get());
}
}, 30);
} finally {
thread.interrupt();
thread.join();
countDownLatch.countDown();
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.
@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountingConnectionRemoveListener listener = new CountingConnectionRemoveListener();
connectionManager.addConnectionListener(listener);
final Address serverAddress = new Address(server.getCluster().getLocalMember().getSocketAddress());
final Connection connectionToServer = connectionManager.getConnection(serverAddress);
final CountDownLatch isConnected = new CountDownLatch(1);
clientImpl.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
isConnected.countDown();
}
}
});
connectionToServer.close(null, null);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(isConnected.await(5, TimeUnit.SECONDS));
}
});
connectionToServer.close(null, null);
assertEquals("connection removed should be called only once", 1, listener.count.get());
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MembershipListenerTest method whenMemberAdded_thenMemberAddedEvent.
@Test
public void whenMemberAdded_thenMemberAddedEvent() throws Exception {
final HazelcastInstance server1 = hazelcastFactory.newHazelcastInstance();
final MemberShipEventLogger listener = new MemberShipEventLogger();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
client.getCluster().addMembershipListener(listener);
//start a second server and verify that the listener receives it.
final HazelcastInstance server2 = hazelcastFactory.newHazelcastInstance();
//verify that the listener receives member added event.
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotEquals("Expecting one or more events", 0, listener.events.size());
MembershipEvent event = (MembershipEvent) listener.events.getLast();
assertEquals("Last event should be member added", MembershipEvent.MEMBER_ADDED, event.getEventType());
assertEquals(server2.getCluster().getLocalMember(), event.getMember());
assertEquals(getMembers(server1, server2), event.getMembers());
}
});
}
use of com.hazelcast.test.AssertTask 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.test.AssertTask 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