Search in sources :

Example 1 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientNearCacheInvalidationTest method setup.

@Before
public void setup() {
    hazelcastFactory = new TestHazelcastFactory();
    member = hazelcastFactory.newHazelcastInstance(getConfig());
    if (MEMBER_COUNT > 1) {
        HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
        allMembers[0] = member;
        for (int i = 1; i < MEMBER_COUNT; i++) {
            allMembers[i] = hazelcastFactory.newHazelcastInstance(getConfig());
        }
        waitAllForSafeState(allMembers);
    }
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(createNearCacheConfig(inMemoryFormat));
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) HazelcastServerCachingProvider.createCachingProvider(member).getCacheManager();
    ICache<Object, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(inMemoryFormat));
    ICache<Object, String> memberCache = member.getCacheManager().getCache(CacheUtil.getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
    testContext = new NearCacheTestContext(client, member, cacheManager, memberCacheManager, nearCacheManager, cache, memberCache, nearCache);
    // make sure several partitions are populated with data
    for (int i = 0; i < 1000; i++) {
        testContext.memberCache.put(Integer.toString(i), Integer.toString(i));
    }
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) Before(org.junit.Before)

Example 2 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCacheBasicTest method createContext.

@Override
protected <K, V> com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String> createContext() {
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider memberProvider = HazelcastServerCachingProvider.createCachingProvider(member);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(DEFAULT_NEAR_CACHE_NAME);
    ICache<K, V> clientCache = cacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    ICache<K, V> memberCache = memberCacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new ICacheDataStructureAdapter<K, V>(clientCache), new ICacheDataStructureAdapter<K, V>(memberCache), false, nearCache, nearCacheManager, cacheManager, memberCacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 3 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class CacheConfigTest method cacheCacheManagerByLocationJarFileTest.

@Test
public void cacheCacheManagerByLocationJarFileTest() throws Exception {
    File jcacheConfigFile = File.createTempFile("jcache_config_", ".jar");
    JarUtil.createJarFile("src/test/resources/", newArrayList("test-hazelcast-jcache.xml"), jcacheConfigFile.getAbsolutePath());
    URI uri = new URI("jar:" + jcacheConfigFile.toURI() + "!/test-hazelcast-jcache.xml");
    CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, null, new Properties());
    assertThat(cacheManager).isNotNull();
    HazelcastServerCacheManager serverCacheManager = cacheManager.unwrap(HazelcastServerCacheManager.class);
    assertThat(serverCacheManager.getHazelcastInstance().getName()).isEqualTo("test-hazelcast-jcache");
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Properties(java.util.Properties) File(java.io.File) URI(java.net.URI) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCacheInvalidationTest method setup.

@Before
public void setup() {
    hazelcastFactory = new TestHazelcastFactory();
    HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
    for (int i = 0; i < MEMBER_COUNT; i++) {
        // every instance should have its own getConfig() call because an existing EE test relies on this
        Config config = getConfig().setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_ENABLED.getName(), "false");
        allMembers[i] = hazelcastFactory.newHazelcastInstance(config);
    }
    waitAllForSafeState(allMembers);
    NearCacheConfig nearCacheConfig = getNearCacheConfig(inMemoryFormat);
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastServerCachingProvider memberProvider = createServerCachingProvider(allMembers[0]);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    CacheConfig<Integer, String> cacheConfig = getCacheConfig(inMemoryFormat);
    ICache<Integer, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, cacheConfig);
    ICache<Integer, String> memberCache = memberCacheManager.getCache(getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
    NearCacheManager nearCacheManager = ((ClientCacheProxy) cache).getContext().getNearCacheManager(cache.getServiceName());
    NearCache<Object, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
    SerializationService serializationService = client.getSerializationService();
    invalidationListener = createInvalidationEventHandler(cache);
    NearCacheTestContextBuilder<Integer, String, Object, String> builder = new NearCacheTestContextBuilder<>(nearCacheConfig, serializationService);
    testContext = builder.setDataInstance(allMembers[0]).setNearCacheInstance(client).setDataAdapter(new ICacheDataStructureAdapter<>(memberCache)).setNearCacheAdapter(new ICacheDataStructureAdapter<>(cache)).setMemberCacheManager(memberCacheManager).setCacheManager(cacheManager).setNearCacheManager(nearCacheManager).setNearCache(nearCache).build();
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) SerializationService(com.hazelcast.internal.serialization.SerializationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) Before(org.junit.Before)

Example 5 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCacheBasicTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean loaderEnabled) {
    Config config = getConfig();
    CacheConfig<K, V> cacheConfig = getCacheConfig(nearCacheConfig, loaderEnabled);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
    CachingProvider memberProvider = createServerCachingProvider(member);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    ICache<K, V> memberCache = memberCacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    ICacheDataStructureAdapter<K, V> dataAdapter = new ICacheDataStructureAdapter<K, V>(memberCache);
    NearCacheTestContextBuilder<K, V, Data, String> builder = createNearCacheContextBuilder(cacheConfig);
    return builder.setDataInstance(member).setDataAdapter(dataAdapter).setMemberCacheManager(memberCacheManager).build();
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.createNearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.internal.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Aggregations

HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)14 CachingProvider (javax.cache.spi.CachingProvider)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)9 ClientConfig (com.hazelcast.client.config.ClientConfig)8 CacheConfig (com.hazelcast.config.CacheConfig)6 Config (com.hazelcast.config.Config)6 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)5 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)5 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)4 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)4 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)4 NearCacheConfig (com.hazelcast.config.NearCacheConfig)4 ICacheDataStructureAdapter (com.hazelcast.internal.adapter.ICacheDataStructureAdapter)4 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)4 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)4 Data (com.hazelcast.nio.serialization.Data)4 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)3 NearCacheTestContext (com.hazelcast.internal.nearcache.NearCacheTestContext)3 NearCacheTestUtils.createNearCacheConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.createNearCacheConfig)3