Пример #1
0
  @Test
  public void testMultiClusterMultipleClients() throws MalformedURLException, URISyntaxException {
    final String cacheName = "test";
    final String key1 = "key1";
    final String valuecm1 = "Value-is-cm1";
    final String valuecm2 = "Value-is-cm2";

    final HazelcastClientCachingProvider cachingProvider = new HazelcastClientCachingProvider();
    final CacheManager cm1 = cachingProvider.getCacheManager(uri1, null);
    final CacheManager cm2 = cachingProvider.getCacheManager(uri2, null);
    final CacheConfig<String, String> cacheConfig = new CacheConfig<String, String>();
    final Cache<String, String> cache1 = cm1.createCache(cacheName, cacheConfig);
    final Cache<String, String> cache2 = cm2.createCache(cacheName, cacheConfig);

    cache1.put(key1, valuecm1);
    cache2.put(key1, valuecm2);

    assertEquals(valuecm1, cache1.get(key1));
    assertEquals(valuecm2, cache2.get(key1));

    cachingProvider.close(uri1, null);
    cachingProvider.close(uri2, null);
    //        cm1.close();
    //        cm2.close();

    final CacheManager cm11 = cachingProvider.getCacheManager(uri1, null);

    final Cache<String, String> cache11 = cm11.getCache(cacheName);

    assertEquals(valuecm1, cache11.get(key1));

    cm11.close();
  }
  private static void initializeCaches() {
    cachingProvider1 = HazelcastClientCachingProvider.createCachingProvider(c1);
    cachingProvider2 = HazelcastClientCachingProvider.createCachingProvider(c2);
    cachingProvider3 = HazelcastClientCachingProvider.createCachingProvider(c3);
    cachingProvider4 = HazelcastClientCachingProvider.createCachingProvider(c4);
    cachingProvider5 = HazelcastClientCachingProvider.createCachingProvider(c5);

    final String cacheName = CACHE_NAME_PREFIX + randomString();
    cache1 = (ICache) cachingProvider1.getCacheManager().getCache(cacheName);
    cache2 = (ICache) cachingProvider2.getCacheManager().getCache(cacheName);
    cache3 = (ICache) cachingProvider3.getCacheManager().getCache(cacheName);
    cache4 = (ICache) cachingProvider4.getCacheManager().getCache(cacheName);
    cache5 = (ICache) cachingProvider5.getCacheManager().getCache(cacheName);
  }
 @Override
 protected CachingProvider getCachingProvider() {
   return HazelcastClientCachingProvider.createCachingProvider(getHazelcastInstance());
 }
 /**
  * Helper method for creating caching provider for testing etc
  *
  * @param hazelcastInstance
  * @return HazelcastClientCachingProvider
  */
 public static HazelcastClientCachingProvider createCachingProvider(
     HazelcastInstance hazelcastInstance) {
   final HazelcastClientCachingProvider cachingProvider = new HazelcastClientCachingProvider();
   cachingProvider.hazelcastInstance = hazelcastInstance;
   return cachingProvider;
 }