Search in sources :

Example 1 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientReplicatedMapNearCacheBasicTest method createNearCacheContextBuilder.

private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder() {
    ClientConfig clientConfig = getClientConfig();
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    ReplicatedMap<K, V> clientMap = client.getReplicatedMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = ((ClientReplicatedMapProxy) clientMap).getContext().getNearCacheManager(clientMap.getServiceName());
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ReplicatedMapDataStructureAdapter<>(clientMap)).setNearCache(nearCache).setNearCacheManager(nearCacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) Data(com.hazelcast.internal.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy)

Example 2 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientReplicatedMapNearCacheSerializationCountTest method createNearCacheContextBuilder.

private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder() {
    ClientConfig clientConfig = getClientConfig();
    if (nearCacheConfig != null) {
        clientConfig.addNearCacheConfig(nearCacheConfig);
    }
    prepareSerializationConfig(clientConfig.getSerializationConfig());
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    ReplicatedMap<K, V> clientMap = client.getReplicatedMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = ((ClientReplicatedMapProxy) clientMap).getContext().getNearCacheManager(clientMap.getServiceName());
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ReplicatedMapDataStructureAdapter<K, V>(clientMap)).setNearCache(nearCache).setNearCacheManager(nearCacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) Data(com.hazelcast.internal.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy)

Example 3 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class TestBeansApplicationContext method testApplicationContext.

@Test
public void testApplicationContext() {
    assertTrue(HazelcastClient.getAllHazelcastClients().isEmpty());
    context.getBean("map2");
    assertEquals(1, Hazelcast.getAllHazelcastInstances().size());
    assertEquals(1, HazelcastClient.getAllHazelcastClients().size());
    HazelcastInstance hazelcast = Hazelcast.getAllHazelcastInstances().iterator().next();
    long distributedObjectsSize = hazelcast.getDistributedObjects().stream().filter(distributedObject -> !distributedObject.getName().startsWith(INTERNAL_JET_OBJECTS_PREFIX)).count();
    assertEquals(2, distributedObjectsSize);
    context.getBean("client");
    context.getBean("client");
    assertEquals(3, HazelcastClient.getAllHazelcastClients().size());
    HazelcastClientProxy client = (HazelcastClientProxy) HazelcastClient.getAllHazelcastClients().iterator().next();
    assertNull(client.getClientConfig().getManagedContext());
    int batchSize = client.getClientConfig().getQueryCacheConfigs().get("").get("cache1").getBatchSize();
    assertEquals(12, batchSize);
    assertFalse(client.getClientConfig().getMetricsConfig().isEnabled());
    HazelcastInstance instance = (HazelcastInstance) context.getBean("instance");
    assertEquals(1, Hazelcast.getAllHazelcastInstances().size());
    assertEquals(instance, Hazelcast.getAllHazelcastInstances().iterator().next());
    assertNull(instance.getConfig().getManagedContext());
}
Also used : RANDOM(com.hazelcast.config.EvictionPolicy.RANDOM) BeforeClass(org.junit.BeforeClass) HazelcastClient(com.hazelcast.client.HazelcastClient) QuickTest(com.hazelcast.test.annotation.QuickTest) QueueConfig(com.hazelcast.config.QueueConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AfterClass(org.junit.AfterClass) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) ApplicationContext(org.springframework.context.ApplicationContext) PER_PARTITION(com.hazelcast.config.MaxSizePolicy.PER_PARTITION) Assert.assertNull(org.junit.Assert.assertNull) Hazelcast(com.hazelcast.core.Hazelcast) Assert.assertFalse(org.junit.Assert.assertFalse) ContextConfiguration(org.springframework.test.context.ContextConfiguration) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) Assert.assertEquals(org.junit.Assert.assertEquals) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class TestSpringClientFailoverContext method testBlueGreenClient.

@Test
public void testBlueGreenClient() {
    HazelcastClientProxy blueGreenClient = applicationContext.getBean("blueGreenClient", HazelcastClientProxy.class);
    ClientFailoverConfig failoverConfig = blueGreenClient.client.getFailoverConfig();
    List<ClientConfig> clientConfigs = failoverConfig.getClientConfigs();
    assertEquals(2, clientConfigs.size());
    assertEquals("spring-cluster", clientConfigs.get(0).getClusterName());
    assertEquals("alternativeClusterName", clientConfigs.get(1).getClusterName());
    assertEquals(5, failoverConfig.getTryCount());
    blueGreenClient.shutdown();
}
Also used : ClientFailoverConfig(com.hazelcast.client.config.ClientFailoverConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class TestEnabledSpringAwareAnnotation method testSpringManagedContext.

@Test
public void testSpringManagedContext() {
    HazelcastInstance instance = (HazelcastInstance) context.getBean("instance");
    assertTrue(instance.getConfig().getManagedContext() instanceof SpringManagedContext);
    HazelcastClientProxy client = (HazelcastClientProxy) context.getBean("client");
    assertTrue(client.getClientConfig().getManagedContext() instanceof SpringManagedContext);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SpringManagedContext(com.hazelcast.spring.context.SpringManagedContext) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)42 ClientConfig (com.hazelcast.client.config.ClientConfig)27 Test (org.junit.Test)16 QuickTest (com.hazelcast.test.annotation.QuickTest)14 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)13 CachingProvider (javax.cache.spi.CachingProvider)13 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)12 Data (com.hazelcast.internal.serialization.Data)12 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 NearCacheTestContextBuilder (com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder)9 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)7 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)7 ClientMetricsConfig (com.hazelcast.client.config.ClientMetricsConfig)6 NearCacheConfig (com.hazelcast.config.NearCacheConfig)6 Config (com.hazelcast.config.Config)5 CacheManager (javax.cache.CacheManager)5 CacheConfig (com.hazelcast.config.CacheConfig)4 ICacheDataStructureAdapter (com.hazelcast.internal.adapter.ICacheDataStructureAdapter)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4