Search in sources :

Example 46 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method createNearCacheTest.

protected NearCacheTestContext createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig cacheConfig) {
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    //noinspection unchecked
    ICache<Object, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
    return new NearCacheTestContext(client, cacheManager, nearCacheManager, cache, nearCache);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 47 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientExecutorServiceCancelTest method createClient.

private HazelcastInstance createClient(boolean smartRouting) {
    ClientConfig config = new ClientConfig();
    config.getNetworkConfig().setSmartRouting(smartRouting);
    return hazelcastFactory.newHazelcastClient(config);
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 48 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientDurableExecutionDelayTest method runClient.

private void runClient(Task task, int executions) throws Exception {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setRedoOperation(true);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    DurableExecutorService executor = client.getDurableExecutorService("executor");
    for (int i = 0; i < executions; i++) {
        Future future = executor.submitToKeyOwner(task, i);
        future.get();
        Thread.sleep(100);
    }
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 49 with ClientConfig

use of com.hazelcast.client.config.ClientConfig 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());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleListener(com.hazelcast.core.LifecycleListener) Matchers.containsString(org.hamcrest.Matchers.containsString) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterListenerSupport(com.hazelcast.client.spi.impl.ClusterListenerSupport) ExpectedException(org.junit.rules.ExpectedException) ExecutionException(java.util.concurrent.ExecutionException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 50 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientLoggerConfigurationTest method testLoggingWithConfiguration.

// Test with programmatic or system property configuration according to boolean parameter.
// the idea of the test is to configure a specific logging type for a client and then
// test its LoggingService produce instances of the expected Logger impl
protected void testLoggingWithConfiguration(boolean programmaticConfiguration) throws IOException {
    hazelcastFactory = new TestHazelcastFactory();
    Config cg = new Config();
    cg.setProperty("hazelcast.logging.type", "jdk");
    hazelcastFactory.newHazelcastInstance(cg);
    ClientConfig config = new ClientConfig();
    if (programmaticConfiguration) {
        config.setProperty("hazelcast.logging.type", "log4j2");
    } else {
        System.setProperty("hazelcast.logging.type", "log4j2");
    }
    client = hazelcastFactory.newHazelcastClient(config);
    ILogger clientLogger = client.getLoggingService().getLogger("loggerName");
    // this part is fragile.
    // client wraps the actual logger in its own class
    ILogger actualLogger = (ILogger) getFromField(clientLogger, "logger");
    Class<?> clientLoggerClass = actualLogger.getClass();
    ILogger expectedLogger = new Log4j2Factory().getLogger("expectedLogger");
    Class<?> expectedLoggerClass = expectedLogger.getClass();
    assertSame(expectedLoggerClass, clientLoggerClass);
}
Also used : Log4j2Factory(com.hazelcast.logging.Log4j2Factory) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ILogger(com.hazelcast.logging.ILogger) ClientConfig(com.hazelcast.client.config.ClientConfig)

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