GridGgfsFileMap map = new GridGgfsFileMap();
GridUuid affKey = GridUuid.randomUuid();
for (int i = 0; i < 4; i++)
map.addRange(new GridGgfsFileAffinityRange(i * 20 + 10, i * 20 + 19, affKey));
// Middle, first, last.
map.updateRangeStatus(new GridGgfsFileAffinityRange(30, 35, affKey), RANGE_STATUS_MOVING);
map.updateRangeStatus(new GridGgfsFileAffinityRange(10, 15, affKey), RANGE_STATUS_MOVING);
map.updateRangeStatus(new GridGgfsFileAffinityRange(70, 75, affKey), RANGE_STATUS_MOVING);
List<GridGgfsFileAffinityRange> ranges = map.ranges();
assertEquals(7, ranges.size());
int idx = 0;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(10, 15, affKey)));
assertEquals(RANGE_STATUS_MOVING, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(16, 19, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(30, 35, affKey)));
assertEquals(RANGE_STATUS_MOVING, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(36, 39, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(50, 59, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(70, 75, affKey)));
assertEquals(RANGE_STATUS_MOVING, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(76, 79, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
// Middle, first, last.
map.updateRangeStatus(new GridGgfsFileAffinityRange(30, 35, affKey), RANGE_STATUS_MOVED);
map.updateRangeStatus(new GridGgfsFileAffinityRange(10, 15, affKey), RANGE_STATUS_MOVED);
map.updateRangeStatus(new GridGgfsFileAffinityRange(70, 75, affKey), RANGE_STATUS_MOVED);
idx = 0;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(10, 15, affKey)));
assertEquals(RANGE_STATUS_MOVED, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(16, 19, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(30, 35, affKey)));
assertEquals(RANGE_STATUS_MOVED, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(36, 39, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(50, 59, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(70, 75, affKey)));
assertEquals(RANGE_STATUS_MOVED, ranges.get(idx).status());
idx++;
assertTrue(ranges.get(idx).regionEqual(new GridGgfsFileAffinityRange(76, 79, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(idx).status());
// Middle, first, last.
map.deleteRange(new GridGgfsFileAffinityRange(30, 35, affKey));
map.deleteRange(new GridGgfsFileAffinityRange(10, 15, affKey));
map.deleteRange(new GridGgfsFileAffinityRange(70, 75, affKey));
ranges = map.ranges();
assertEquals(4, ranges.size());
assertEquals(RANGE_STATUS_INITIAL, ranges.get(0).status());
assertTrue(ranges.get(0).regionEqual(new GridGgfsFileAffinityRange(16, 19, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(1).status());
assertTrue(ranges.get(1).regionEqual(new GridGgfsFileAffinityRange(36, 39, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(2).status());
assertTrue(ranges.get(2).regionEqual(new GridGgfsFileAffinityRange(50, 59, affKey)));
assertEquals(RANGE_STATUS_INITIAL, ranges.get(3).status());
assertTrue(ranges.get(3).regionEqual(new GridGgfsFileAffinityRange(76, 79, affKey)));
}