Exemplo n.º 1
0
  @Test
  public void testGet_whenNotExist() {
    final MultiMap mm = client.getMultiMap(randomString());
    Collection coll = mm.get("NOT_THERE");

    assertEquals(Collections.EMPTY_SET, coll);
  }
 @Test
 public void testMultiMapPutAndGet() {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, String> map = hClient.getMultiMap("testMultiMapPutAndGet");
   map.put("Hello", "World");
   Collection<String> values = map.get("Hello");
   assertEquals("World", values.iterator().next());
   map.put("Hello", "Europe");
   map.put("Hello", "America");
   map.put("Hello", "Asia");
   map.put("Hello", "Africa");
   map.put("Hello", "Antarctica");
   map.put("Hello", "Australia");
   values = map.get("Hello");
   assertEquals(7, values.size());
   assertTrue(map.containsKey("Hello"));
   assertFalse(map.containsKey("Hi"));
 }
Exemplo n.º 3
0
  @Test
  public void testGet() {
    final Object key = "key";
    final int maxItemsPerKey = 33;
    final MultiMap mm = client.getMultiMap(randomString());

    Set expected = new TreeSet();
    for (int i = 0; i < maxItemsPerKey; i++) {
      mm.put(key, i);
      expected.add(i);
    }

    Collection resultSet = new TreeSet(mm.get(key));

    assertEquals(expected, resultSet);
  }
Exemplo n.º 4
0
  @Test
  public void testPutAndRoleBack() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "value";
    final MultiMap multiMap = client.getMultiMap(mapName);

    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();
    TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
    mulitMapTxn.put(key, value);
    mulitMapTxn.put(key, value);
    tx.rollbackTransaction();

    assertEquals(Collections.EMPTY_LIST, multiMap.get(key));
  }
Exemplo n.º 5
0
  @Test
  public void testRemoveAll() throws Exception {
    final String mapName = randomString();
    final String key = "key";

    MultiMap multiMap = client.getMultiMap(mapName);
    for (int i = 0; i < 10; i++) {
      multiMap.put(key, i);
    }

    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();

    TransactionalMultiMap txnMultiMap = tx.getMultiMap(mapName);
    txnMultiMap.remove(key);
    tx.commitTransaction();

    assertEquals(Collections.EMPTY_LIST, multiMap.get(key));
  }
 @Test
 public void get() throws InterruptedException {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, Integer> multiMap = hClient.getMultiMap("get");
   assertTrue(multiMap.put("a", 1));
   assertTrue(multiMap.put("a", 2));
   Map<Integer, CountDownLatch> map = new HashMap<Integer, CountDownLatch>();
   map.put(1, new CountDownLatch(1));
   map.put(2, new CountDownLatch(1));
   Collection<Integer> collection = multiMap.get("a");
   assertEquals(Values.class, collection.getClass());
   assertEquals(2, collection.size());
   for (Iterator<Integer> it = collection.iterator(); it.hasNext(); ) {
     Integer o = it.next();
     map.get(o).countDown();
   }
   assertTrue(map.get(1).await(10, TimeUnit.SECONDS));
   assertTrue(map.get(2).await(10, TimeUnit.SECONDS));
 }
 @Test
 public void testTransactionAtomicity_whenMultiMapGetIsUsed_withoutTransaction()
     throws InterruptedException {
   final HazelcastInstance hz = Hazelcast.newHazelcastInstance(createConfigWithDummyTxService());
   final String name = HazelcastTestSupport.generateRandomString(5);
   Thread producerThread = startProducerThread(hz, name);
   try {
     IQueue<String> q = hz.getQueue(name);
     for (int i = 0; i < 1000; i++) {
       String id = q.poll();
       if (id != null) {
         MultiMap<Object, Object> multiMap = hz.getMultiMap(name);
         Collection<Object> values = multiMap.get(id);
         assertFalse(values.isEmpty());
         multiMap.remove(id);
       } else {
         LockSupport.parkNanos(100);
       }
     }
   } finally {
     stopProducerThread(producerThread);
   }
 }
Exemplo n.º 8
0
 @Override
 public void get(final K k, final Handler<AsyncResult<ChoosableIterable<V>>> resultHandler) {
   ChoosableSet<V> entries = cache.get(k);
   Future<ChoosableIterable<V>> result = Future.future();
   if (entries != null && entries.isInitialised()) {
     result.setResult(entries).setHandler(resultHandler);
   } else {
     vertx.executeBlocking(
         () -> map.get(k),
         (AsyncResult<Collection<V>> res2) -> {
           Future<ChoosableIterable<V>> sresult = Future.future();
           if (res2.succeeded()) {
             Collection<V> entries2 = res2.result();
             ChoosableSet<V> sids;
             if (entries2 != null) {
               sids = new ChoosableSet<>(entries2.size());
               for (V hid : entries2) {
                 sids.add(hid);
               }
             } else {
               sids = new ChoosableSet<>(0);
             }
             ChoosableSet<V> prev = cache.putIfAbsent(k, sids);
             if (prev != null) {
               // Merge them
               prev.merge(sids);
               sids = prev;
             }
             sids.setInitialised();
             sresult.setResult(sids);
           } else {
             sresult.setFailure(result.cause());
           }
           sresult.setHandler(resultHandler);
         });
   }
 }
 public Collection<V> get(K key) {
   return delegate.get(key);
 }