use of org.apache.cassandra.db.DiskBoundaries in project cassandra by apache.
the class CompactionStrategyManagerTest method groupSSTables.
/**
* Test that csm.groupSSTables correctly groups sstables by repaired status and directory
*/
@Test
public void groupSSTables() throws Exception {
final int numDir = 4;
ColumnFamilyStore cfs = createJBODMockCFS(numDir);
Keyspace.open(cfs.keyspace.getName()).getColumnFamilyStore(cfs.name).disableAutoCompaction();
assertTrue(cfs.getLiveSSTables().isEmpty());
List<SSTableReader> transientRepairs = new ArrayList<>();
List<SSTableReader> pendingRepair = new ArrayList<>();
List<SSTableReader> unrepaired = new ArrayList<>();
List<SSTableReader> repaired = new ArrayList<>();
for (int i = 0; i < numDir; i++) {
int key = 100 * i;
transientRepairs.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
pendingRepair.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
unrepaired.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
repaired.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
}
cfs.getCompactionStrategyManager().mutateRepaired(transientRepairs, 0, UUID.randomUUID(), true);
cfs.getCompactionStrategyManager().mutateRepaired(pendingRepair, 0, UUID.randomUUID(), false);
cfs.getCompactionStrategyManager().mutateRepaired(repaired, 1000, null, false);
DiskBoundaries boundaries = new DiskBoundaries(cfs, cfs.getDirectories().getWriteableLocations(), Lists.newArrayList(forKey(100), forKey(200), forKey(300)), 10, 10);
CompactionStrategyManager csm = new CompactionStrategyManager(cfs, () -> boundaries, true);
List<GroupedSSTableContainer> grouped = csm.groupSSTables(Iterables.concat(transientRepairs, pendingRepair, repaired, unrepaired));
for (int x = 0; x < grouped.size(); x++) {
GroupedSSTableContainer group = grouped.get(x);
AbstractStrategyHolder holder = csm.getHolders().get(x);
for (int y = 0; y < numDir; y++) {
SSTableReader sstable = Iterables.getOnlyElement(group.getGroup(y));
assertTrue(holder.managesSSTable(sstable));
SSTableReader expected;
if (sstable.isRepaired())
expected = repaired.get(y);
else if (sstable.isPendingRepair()) {
if (sstable.isTransient()) {
expected = transientRepairs.get(y);
} else {
expected = pendingRepair.get(y);
}
} else
expected = unrepaired.get(y);
assertSame(expected, sstable);
}
}
}
Aggregations