use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientConnectionTest method testWithIllegalAddress.
@Test(expected = IllegalStateException.class)
public void testWithIllegalAddress() {
String illegalAddress = randomString();
hazelcastFactory.newHazelcastInstance();
ClientConfig config = new ClientConfig();
config.getNetworkConfig().setConnectionAttemptPeriod(1);
config.getNetworkConfig().addAddress(illegalAddress);
hazelcastFactory.newHazelcastClient(config);
}
use of com.hazelcast.client.config.ClientConfig 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.client.config.ClientConfig 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.client.config.ClientConfig 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.client.config.ClientConfig 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());
}
});
}
Aggregations