Search in sources :

Example 6 with ClientConfig

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);
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with ClientConfig

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();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with ClientConfig

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());
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) EventObject(java.util.EventObject) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with ClientConfig

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);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with 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());
        }
    });
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)214 Test (org.junit.Test)129 HazelcastInstance (com.hazelcast.core.HazelcastInstance)110 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)81 Config (com.hazelcast.config.Config)45 NearCacheConfig (com.hazelcast.config.NearCacheConfig)32 NightlyTest (com.hazelcast.test.annotation.NightlyTest)32 CountDownLatch (java.util.concurrent.CountDownLatch)25 AssertTask (com.hazelcast.test.AssertTask)20 Before (org.junit.Before)20 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)16 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)15 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)13 CachingProvider (javax.cache.spi.CachingProvider)13 IMap (com.hazelcast.core.IMap)12 LifecycleListener (com.hazelcast.core.LifecycleListener)12 LifecycleEvent (com.hazelcast.core.LifecycleEvent)11 Data (com.hazelcast.nio.serialization.Data)11 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)10