Search in sources :

Example 1 with FastCopyHashMap

use of org.infinispan.commons.util.FastCopyHashMap in project infinispan by infinispan.

the class VersionAwareMarshallerTest method testMapMarshalling.

public void testMapMarshalling() throws Exception {
    Map<Integer, GlobalTransaction> m1 = new HashMap<>();
    Map<Integer, GlobalTransaction> m2 = new TreeMap<>();
    Map<Integer, GlobalTransaction> m3 = new HashMap<>();
    Map<Integer, GlobalTransaction> m4 = new FastCopyHashMap<>();
    for (int i = 0; i < 10; i++) {
        JGroupsAddress jGroupsAddress = new JGroupsAddress(UUID.randomUUID());
        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);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FastCopyHashMap(org.infinispan.commons.util.FastCopyHashMap) HashMap(java.util.HashMap) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) TreeMap(java.util.TreeMap) FastCopyHashMap(org.infinispan.commons.util.FastCopyHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FastCopyHashMap(org.infinispan.commons.util.FastCopyHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FastCopyHashMap (org.infinispan.commons.util.FastCopyHashMap)1 JGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddress)1 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)1