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;
}
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());
}
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));
}
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());
}
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);
}
Aggregations