public void testMapMarshalling() throws Exception {
    Map m1 = new HashMap();
    Map m2 = new TreeMap();
    Map m3 = new HashMap();
    Map<Integer, GlobalTransaction> m4 = new FastCopyHashMap<Integer, GlobalTransaction>();
    for (int i = 0; i < 10; i++) {
      JGroupsAddress jGroupsAddress = new JGroupsAddress(new IpAddress(1000 * i));
      GlobalTransaction gtx = gtf.newGlobalTransaction(jGroupsAddress, false);
      m1.put(1000 * i, gtx);
      m2.put(1000 * i, gtx);
      m4.put(1000 * i, gtx);
    }
    Map m5 = Immutables.immutableMapWrap(m3);
    marshallAndAssertEquality(m1);
    marshallAndAssertEquality(m2);
    byte[] bytes = marshaller.objectToByteBuffer(m4);
    Map<Integer, GlobalTransaction> m4Read =
        (Map<Integer, GlobalTransaction>) marshaller.objectFromByteBuffer(bytes);
    for (Map.Entry<Integer, GlobalTransaction> entry : m4.entrySet()) {
      assert m4Read.get(entry.getKey()).equals(entry.getValue())
          : "Writen["
              + entry.getValue()
              + "] and read["
              + m4Read.get(entry.getKey())
              + "] objects should be the same";
    }

    marshallAndAssertEquality(m5);
  }
  public void testEntrySet() {
    dc.put("k1", "v1", 6000000, -1);
    dc.put("k2", "v2", -1, -1);
    dc.put("k3", "v3", -1, 6000000);
    dc.put("k4", "v4", 6000000, 6000000);

    Set expected = new HashSet();
    expected.add(Immutables.immutableInternalCacheEntry(dc.get("k1")));
    expected.add(Immutables.immutableInternalCacheEntry(dc.get("k2")));
    expected.add(Immutables.immutableInternalCacheEntry(dc.get("k3")));
    expected.add(Immutables.immutableInternalCacheEntry(dc.get("k4")));

    Set actual = new HashSet();
    for (Map.Entry o : dc.entrySet()) actual.add(o);

    assert actual.equals(expected) : "Expected to see keys " + expected + " but only saw " + actual;
  }
Beispiel #3
0
 private void removeChildren(AdvancedCache<?, ?> cache) {
   startAtomic();
   try {
     Map<Object, Fqn> s = getStructure(cache);
     for (Object o : Immutables.immutableSetCopy(s.keySet())) removeChild(cache, o);
   } finally {
     endAtomic();
   }
 }
 public List<Address> generateRecipients() {
   if (recipients == null) {
     Set<Address> addresses = new HashSet<Address>();
     Map<Object, List<Address>> recipientsMap = dm.locateAll(keys);
     for (List<Address> a : recipientsMap.values()) addresses.addAll(a);
     recipients = Immutables.immutableListConvert(addresses);
   }
   return recipients;
 }
 @Override
 public void removeChildren() {
   startAtomic();
   try {
     Map<Object, Fqn> s = getStructure();
     for (Object o : Immutables.immutableSetCopy(s.keySet())) removeChild(o);
   } finally {
     endAtomic();
   }
 }
Beispiel #6
0
 private Set<Node<K, V>> getChildren(AdvancedCache<?, ?> cache) {
   startAtomic();
   try {
     Set<Node<K, V>> result = new HashSet<Node<K, V>>();
     for (Fqn f : getStructure().values()) {
       NodeImpl<K, V> n = new NodeImpl<K, V>(f, cache, batchContainer);
       result.add(n);
     }
     return Immutables.immutableSetWrap(result);
   } finally {
     endAtomic();
   }
 }
 @Override
 public InternalCacheEntry next() {
   return Immutables.immutableInternalCacheEntry(super.next());
 }
Beispiel #8
0
 private Set<Object> getChildrenNames(AdvancedCache<?, ?> cache) {
   return Immutables.immutableSetCopy(getStructure(cache).keySet());
 }
 @Override
 public Set<Object> getChildrenNames() {
   return Immutables.immutableSetCopy(getStructure().keySet());
 }