use of javax.cache.spi.CachingProvider 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));
}
}
use of javax.cache.spi.CachingProvider 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);
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class ClientCacheConfigTest method createCacheConfigOnAllNodes.
@Test
public void createCacheConfigOnAllNodes() {
final String CACHE_NAME = "myCache";
HazelcastInstance client = null;
HazelcastInstance server1 = null;
HazelcastInstance server2 = null;
try {
Config config = new Config();
CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig().setName(CACHE_NAME).setBackupCount(// Be sure that cache put operation is mirrored to backup node
1);
config.addCacheConfig(cacheSimpleConfig);
// Create servers with configured caches
server1 = Hazelcast.newHazelcastInstance(config);
server2 = Hazelcast.newHazelcastInstance(config);
ICacheService cacheService1 = getCacheService(server1);
ICacheService cacheService2 = getCacheService(server2);
// Create the hazelcast client instance
client = HazelcastClient.newHazelcastClient();
// Create the client cache manager
CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<String, String> cache = cacheManager.getCache(CACHE_NAME);
assertNotNull(cache);
CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
assertNotNull(cacheService1.getCacheConfig(cacheConfig.getNameWithPrefix()));
assertNotNull(cacheService2.getCacheConfig(cacheConfig.getNameWithPrefix()));
// First attempt to use the cache will trigger to create its record store.
// So, we are testing also this case. There should not be any exception.
// In here, we are testing both of nodes since there is a backup,
// put is also applied to other (backup node).
cache.put("key", "value");
} finally {
if (client != null) {
client.shutdown();
}
if (server1 != null) {
server1.shutdown();
}
if (server2 != null) {
server2.shutdown();
}
}
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_removed.
@Test
public void test_cachePartitionLostListener_removed() {
final String cacheName = randomName();
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
cacheManager.createCache(cacheName, config);
final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
final ICache iCache = cache.unwrap(ICache.class);
final String registrationId = iCache.addPartitionLostListener(mock(CachePartitionLostListener.class));
assertRegistrationsSizeEventually(instance, cacheName, 1);
assertTrue(iCache.removePartitionLostListener(registrationId));
assertRegistrationsSizeEventually(instance, cacheName, 0);
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked_fromOtherNode.
@Test
public void test_cachePartitionLostListener_invoked_fromOtherNode() {
final String cacheName = randomName();
HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance1);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
cacheManager.createCache(cacheName, config);
final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
final ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
iCache.addPartitionLostListener(listener);
assertRegistrationsSizeEventually(instance1, cacheName, 1);
assertRegistrationsSizeEventually(instance2, cacheName, 1);
final CacheService cacheService1 = getNode(instance1).getNodeEngine().getService(CacheService.SERVICE_NAME);
final CacheService cacheService2 = getNode(instance2).getNodeEngine().getService(CacheService.SERVICE_NAME);
final int partitionId = 5;
cacheService1.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
cacheService2.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertCachePartitionLostEventEventually(listener, partitionId);
}
Aggregations