@Test
 public void addIndex() {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("addIndex");
   int size = 1000;
   for (int i = 0; i < size; i++) {
     map.put(String.valueOf(i), new Employee("name" + i, i, true, 0));
   }
   EntryObject e = new PredicateBuilder().getEntryObject();
   Predicate predicate = e.get("age").equal(23);
   long begin = Clock.currentTimeMillis();
   Set<Entry<Object, Object>> set = map.entrySet(predicate);
   long timeWithoutIndex = Clock.currentTimeMillis() - begin;
   assertEquals(1, set.size());
   assertEquals(size, map.size());
   map.destroy();
   map = hClient.getMap("addIndex");
   map.addIndex("age", true);
   for (int i = 0; i < size; i++) {
     map.put(String.valueOf(i), new Employee("name" + i, i, true, 0));
   }
   begin = Clock.currentTimeMillis();
   set = map.entrySet(predicate);
   long timeWithIndex = Clock.currentTimeMillis() - begin;
   assertEquals(1, set.size());
   assertEquals(size, map.size());
   assertTrue(timeWithoutIndex > 2 * timeWithIndex);
   //    	map.addIndex("age", true);
 }
 @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();
 }
 @Test
 public void destroyMap() throws InterruptedException {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("destroy");
   for (int i = 0; i < 100; i++) {
     assertNull(map.put(i, i));
     assertEquals(i, map.get(i));
   }
   IMap<Integer, Integer> map2 = hClient.getMap("destroy");
   assertTrue(map == map2);
   assertTrue(map.getId().equals(map2.getId()));
   map.destroy();
   //        map2 = hClient.getMap("destroy");
   //        assertFalse(map == map2);
   for (int i = 0; i < 100; i++) {
     //            assertNull(map2.get(i));
   }
 }
コード例 #4
0
 @Test
 public void testDestroyJustAfterCreate() {
   final HazelcastInstance instance = Hazelcast.newHazelcastInstance();
   instance.addDistributedObjectListener(new EventCountListener());
   IMap<Object, Object> map = instance.getMap(randomString());
   map.destroy();
   AssertTask task =
       new AssertTask() {
         @Override
         public void run() throws Exception {
           Assert.assertEquals(1, EventCountListener.createdCount.get());
           Assert.assertEquals(1, EventCountListener.destroyedCount.get());
           Collection<DistributedObject> distributedObjects = instance.getDistributedObjects();
           Assert.assertTrue(distributedObjects.isEmpty());
         }
       };
   assertTrueEventually(task, 5);
   assertTrueAllTheTime(task, 3);
 }