コード例 #1
0
ファイル: NearCacheTest.java プロジェクト: derjust/hazelcast
 @Test
 public void testNearCacheEvictionByUsingMapClear() throws InterruptedException {
   final Config cfg = new Config();
   final String mapName = "testNearCacheEviction";
   final NearCacheConfig nearCacheConfig = new NearCacheConfig();
   nearCacheConfig.setInvalidateOnChange(true);
   cfg.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
   final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
   final HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance(cfg);
   final HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance(cfg);
   final IMap map1 = hazelcastInstance1.getMap(mapName);
   final IMap map2 = hazelcastInstance2.getMap(mapName);
   final int size = 10;
   // populate map.
   for (int i = 0; i < size; i++) {
     map1.put(i, i);
   }
   // populate near cache
   for (int i = 0; i < size; i++) {
     map1.get(i);
     map2.get(i);
   }
   // clear map should trigger near cache eviction.
   map1.clear();
   for (int i = 0; i < size; i++) {
     assertNull(map1.get(i));
   }
 }
コード例 #2
0
  @Test
  public void testMapClear_shouldClearNearCaches_onOwnerAndBackupNodes() throws Exception {
    Config config = getConfig();
    configureBatching(config, true, 10, 1);
    HazelcastInstance server = factory.newHazelcastInstance(config);

    factory.newHazelcastInstance(config);

    ClientConfig clientConfig = newClientConfig(mapName);

    HazelcastInstance client = factory.newHazelcastClient(clientConfig);

    IMap<Integer, Integer> serverMap = server.getMap(mapName);
    IMap<Integer, Integer> clientMap = client.getMap(mapName);

    int size = 1000;

    // fill serverMap
    for (int i = 0; i < size; i++) {
      serverMap.put(i, i);
    }

    // fill near-cache on client
    for (int i = 0; i < size; i++) {
      clientMap.get(i);
    }

    serverMap.clear();

    assertNearCacheSizeEventually(clientMap, 0);
  }
 @Test
 public void clear() {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("clear");
   for (int i = 0; i < 100; i++) {
     assertNull(map.put(i, i));
     assertEquals(i, map.get(i));
   }
   map.clear();
   for (int i = 0; i < 100; i++) {
     assertNull(map.get(i));
   }
 }
コード例 #4
0
ファイル: NearCacheTest.java プロジェクト: derjust/hazelcast
  @Test
  public void testBasicUsage() throws Exception {
    int n = 3;
    String mapName = "test";

    Config config = new Config();
    config
        .getMapConfig(mapName)
        .setNearCacheConfig(new NearCacheConfig().setInvalidateOnChange(true));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(n);

    HazelcastInstance[] instances = factory.newInstances(config);
    IMap<Object, Object> map = instances[0].getMap(mapName);

    int count = 5000;
    for (int i = 0; i < count; i++) {
      map.put(i, i);
    }

    for (HazelcastInstance instance : instances) {
      IMap<Object, Object> m = instance.getMap(mapName);
      for (int i = 0; i < count; i++) {
        Assert.assertNotNull(m.get(i));
      }
    }

    for (int i = 0; i < count; i++) {
      map.put(i, i * 2);
    }

    for (HazelcastInstance instance : instances) {
      IMap<Object, Object> m = instance.getMap(mapName);
      for (int i = 0; i < count; i++) {
        Assert.assertNotNull(m.get(i));
      }
    }

    for (HazelcastInstance instance : instances) {
      NearCache nearCache = getNearCache(mapName, instance);
      int size = nearCache.size();
      assertTrue("NearCache Size: " + size, size > 0);
    }

    map.clear();
    for (HazelcastInstance instance : instances) {
      NearCache nearCache = getNearCache(mapName, instance);
      int size = nearCache.size();
      assertEquals(0, size);
    }
  }
コード例 #5
0
 /*
  * Test for Issue 572
  */
 @Test(timeout = 120000)
 public void testMapstoreDeleteOnClear() throws Exception {
   Config config = getConfig();
   SimpleMapStore store = new SimpleMapStore();
   config
       .getMapConfig("testMapstoreDeleteOnClear")
       .setMapStoreConfig(new MapStoreConfig().setEnabled(true).setImplementation(store));
   HazelcastInstance hz = createHazelcastInstance(config);
   IMap<Object, Object> map = hz.getMap("testMapstoreDeleteOnClear");
   int size = 10;
   for (int i = 0; i < size; i++) {
     map.put(i, i);
   }
   assertEquals(size, map.size());
   assertEquals(size, store.store.size());
   assertEquals(size, store.loadAllKeys().size());
   map.clear();
   assertEquals(0, map.size());
   assertEquals(0, store.loadAllKeys().size());
 }
 @Test
 public void addListenerForKey() throws InterruptedException, IOException {
   HazelcastClient hClient = getHazelcastClient();
   final IMap<String, String> map = hClient.getMap("addListenerForKey");
   map.clear();
   assertEquals(0, map.size());
   final CountDownLatch entryAddLatch = new CountDownLatch(1);
   final CountDownLatch entryUpdatedLatch = new CountDownLatch(1);
   final CountDownLatch entryRemovedLatch = new CountDownLatch(1);
   CountDownLatchEntryListener<String, String> listener =
       new CountDownLatchEntryListener<String, String>(
           entryAddLatch, entryUpdatedLatch, entryRemovedLatch);
   map.addEntryListener(listener, "hello", true);
   assertNull(map.get("hello"));
   map.put("hello", "world");
   map.put("hello", "new world");
   assertEquals("new world", map.get("hello"));
   map.remove("hello");
   assertTrue(entryAddLatch.await(10, TimeUnit.SECONDS));
   assertTrue(entryUpdatedLatch.await(10, TimeUnit.SECONDS));
   assertTrue(entryRemovedLatch.await(10, TimeUnit.SECONDS));
 }
コード例 #7
0
  @Test
  public void testSenderAndBackupTerminates_AfterInitialLoad() throws InterruptedException {
    String name = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(name);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new DummyMapLoader());
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(5);
    HazelcastInstance[] instances = instanceFactory.newInstances(config);

    IMap<Object, Object> map = instances[0].getMap(name);
    map.clear();

    HazelcastInstance[] ownerAndReplicas = findOwnerAndReplicas(instances, name);
    ownerAndReplicas[0].getLifecycleService().terminate();
    ownerAndReplicas[1].getLifecycleService().terminate();

    map = ownerAndReplicas[3].getMap(name);
    map.loadAll(false);
    assertEquals(DummyMapLoader.SIZE, map.size());
  }
 @Test
 public void addListenerAndMultiPut() throws InterruptedException, IOException {
   HazelcastClient hClient = getHazelcastClient();
   final IMap<String, byte[]> map = hClient.getMap("addListenerAndMultiPut");
   map.clear();
   int counter = 100;
   assertEquals(0, map.size());
   final CountDownLatch entryAddLatch = new CountDownLatch(counter);
   final CountDownLatch entryUpdatedLatch = new CountDownLatch(counter);
   final CountDownLatch entryRemovedLatch = new CountDownLatch(counter);
   CountDownLatchEntryListener<String, byte[]> listener =
       new CountDownLatchEntryListener<String, byte[]>(
           entryAddLatch, entryUpdatedLatch, entryRemovedLatch);
   map.addEntryListener(listener, true);
   assertNull(map.get("hello"));
   Map<String, byte[]> many = new HashMap<String, byte[]>();
   for (int i = 0; i < counter; i++) {
     many.put("" + i, new byte[i]);
   }
   map.putAll(many);
   assertTrue(entryAddLatch.await(10, TimeUnit.SECONDS));
   //        assertTrue(entryUpdatedLatch.await(10, TimeUnit.MILLISECONDS));
   //        assertTrue(entryRemovedLatch.await(10, TimeUnit.MILLISECONDS));
 }
コード例 #9
0
 public void clear() {
   nativeImpl.clear();
 }
コード例 #10
0
 public void clear() {
   map.clear();
 }