@Test
 public void putAllMany() {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("putAllMany");
   int counter = 100;
   for (int j = 0; j < 4; j++, counter *= 10) {
     Map tempMap = new HashMap();
     for (int i = 0; i < counter; i++) {
       tempMap.put(i, i);
     }
     map.putAll(tempMap);
     assertEquals(1, map.get(1));
   }
   map.destroy();
 }
Exemple #2
0
  @Test
  @Category(ProblematicTest.class)
  public void testNearCacheInvalidationByUsingMapPutAll() {
    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);
    }

    // populate the near cache
    for (int i = 0; i < count; i++) {
      map.get(i);
    }

    final NearCache nearCache = getNearCache(mapName, instances[0]);
    assertTrue(
        nearCache.size()
            > (count / n
                - count
                    * 0.1)); // more-or-less (count / no_of_nodes) should be in the near cache now

    Map<Object, Object> invalidationMap = new HashMap<Object, Object>(count);
    for (int i = 0; i < count; i++) {
      invalidationMap.put(i, i);
    }
    map.putAll(invalidationMap); // this should invalidate the near cache

    assertTrueEventually(
        new AssertTask() {
          @Override
          public void run() {
            assertEquals("Invalidation is not working on putAll()", 0, nearCache.size());
          }
        });
  }
 @Test
 public void putAll() {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("putAll");
   int counter = 100;
   Set keys = new HashSet(counter);
   for (int i = 0; i < counter; i++) {
     keys.add(i);
   }
   Map all = map.getAll(keys);
   assertEquals(0, all.size());
   Map tempMap = new HashMap();
   for (int i = 0; i < counter; i++) {
     tempMap.put(i, i);
   }
   map.putAll(tempMap);
   for (int i = 0; i < counter; i++) {
     assertEquals(i, map.get(i));
   }
   all = map.getAll(keys);
   assertEquals(counter, all.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));
 }
Exemple #5
0
 @Override
 public void putAll(Map<? extends K, ? extends V> map) {
   //noinspection unchecked
   cache.putAll(map);
 }