Search in sources :

Example 1 with GridPartitionStateMap

use of org.apache.ignite.internal.util.GridPartitionStateMap in project ignite by apache.

the class CacheAffinitySharedManager method affinityFullMap.

private Map<UUID, GridDhtPartitionMap> affinityFullMap(AffinityAssignment aff) {
    Map<UUID, GridDhtPartitionMap> map = new HashMap<>();
    for (int p = 0; p < aff.assignment().size(); p++) {
        HashSet<UUID> ids = aff.getIds(p);
        for (UUID nodeId : ids) {
            GridDhtPartitionMap partMap = map.get(nodeId);
            if (partMap == null) {
                partMap = new GridDhtPartitionMap(nodeId, 1L, aff.topologyVersion(), new GridPartitionStateMap(), false);
                map.put(nodeId, partMap);
            }
            partMap.put(p, GridDhtPartitionState.OWNING);
        }
    }
    return map;
}
Also used : GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UUID(java.util.UUID) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap)

Example 2 with GridPartitionStateMap

use of org.apache.ignite.internal.util.GridPartitionStateMap in project ignite by apache.

the class GridPartitionMapSelfTest method testPartitionStateMap.

/**
 */
public void testPartitionStateMap() {
    GridPartitionStateMap map = initMap(new GridPartitionStateMap());
    Set<Map.Entry<Integer, GridDhtPartitionState>> entries = map.entrySet();
    assertEquals(10, map.size());
    for (Map.Entry<Integer, GridDhtPartitionState> entry : entries) entry.setValue(GridDhtPartitionState.OWNING);
    assertEquals(10, map.size());
    for (GridDhtPartitionState state : map.values()) assertEquals(GridDhtPartitionState.OWNING, state);
    Set<Map.Entry<Integer, GridDhtPartitionState>> tmp = new HashSet<>();
    for (Map.Entry<Integer, GridDhtPartitionState> entry : entries) {
        tmp.add(entry);
        entry.setValue(GridDhtPartitionState.LOST);
    }
    for (Map.Entry<Integer, GridDhtPartitionState> entry : tmp) entry.setValue(GridDhtPartitionState.LOST);
    for (GridDhtPartitionState state : map.values()) assertEquals(GridDhtPartitionState.LOST, state);
    assertFalse(map.containsKey(10));
    assertNull(map.remove(10));
    assertEquals(10, map.size());
    assertEquals(GridDhtPartitionState.LOST, map.put(9, GridDhtPartitionState.EVICTED));
    assertEquals(10, map.size());
    assertEquals(GridDhtPartitionState.EVICTED, map.put(9, GridDhtPartitionState.EVICTED));
    assertEquals(10, map.size());
    map.remove(5);
    assertEquals(9, map.size());
    assertEquals(9, map.keySet().size());
    assertEquals(9, map.values().size());
    map.clear();
    assertEquals(0, map.size());
    assertEquals(0, map.keySet().size());
    assertEquals(0, map.values().size());
}
Also used : GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) Map(java.util.Map) HashMap(java.util.HashMap) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) HashSet(java.util.HashSet)

Example 3 with GridPartitionStateMap

use of org.apache.ignite.internal.util.GridPartitionStateMap in project ignite by apache.

the class GridPartitionMapSelfTest method testEqualsAndHashCode.

/**
 */
public void testEqualsAndHashCode() {
    GridPartitionStateMap map1 = initMap(new GridPartitionStateMap());
    GridPartitionStateMap map2 = initMap(new GridPartitionStateMap());
    assertEquals(map1, map2);
    assertEquals(map1.hashCode(), map2.hashCode());
    assertFalse(map1.equals(new HashMap()));
    assertFalse(map1.equals(null));
}
Also used : HashMap(java.util.HashMap) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap)

Example 4 with GridPartitionStateMap

use of org.apache.ignite.internal.util.GridPartitionStateMap in project ignite by apache.

the class GridPartitionMapSelfTest method testCopyNoActive.

/**
 */
public void testCopyNoActive() {
    GridPartitionStateMap map2 = new GridPartitionStateMap();
    map2.put(100, GridDhtPartitionState.EVICTED);
    map2.put(101, GridDhtPartitionState.EVICTED);
    map2.put(102, GridDhtPartitionState.EVICTED);
    map2.put(103, GridDhtPartitionState.OWNING);
    GridPartitionStateMap cp2 = new GridPartitionStateMap(map2, true);
    assertEquals(1, cp2.size());
}
Also used : GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap)

Example 5 with GridPartitionStateMap

use of org.apache.ignite.internal.util.GridPartitionStateMap in project ignite by apache.

the class GridPartitionMapSelfTest method testCopy.

/**
 */
public void testCopy() {
    GridPartitionStateMap map1 = initMap(new GridPartitionStateMap());
    GridPartitionStateMap cp1 = new GridPartitionStateMap(map1, false);
    assertEquals(map1, cp1);
    GridPartitionStateMap map2 = new GridPartitionStateMap();
    map2.put(0, GridDhtPartitionState.MOVING);
    map2.put(1, GridDhtPartitionState.RENTING);
    map2.put(2, GridDhtPartitionState.LOST);
    map2.put(3, GridDhtPartitionState.OWNING);
    map2.put(5, GridDhtPartitionState.MOVING);
    map2.put(6, GridDhtPartitionState.RENTING);
    map2.put(7, GridDhtPartitionState.LOST);
    map2.put(8, GridDhtPartitionState.OWNING);
    GridPartitionStateMap cp2 = new GridPartitionStateMap(map1, true);
    assertEquals(map2, cp2);
}
Also used : GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap)

Aggregations

GridPartitionStateMap (org.apache.ignite.internal.util.GridPartitionStateMap)7 HashMap (java.util.HashMap)3 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)1