RepairUnitService { Set<String> getTablesToRepair(Cluster cluster, RepairUnit repairUnit) throws ReaperException { String keyspace = repairUnit.getKeyspaceName(); Set<String> result; if (repairUnit.getColumnFamilies().isEmpty()) { Set<Table> tables = ClusterFacade.create(context).getTablesForKeyspace(cluster, keyspace); Set<String> twcsBlacklisted = findBlacklistedCompactionStrategyTables(cluster, tables); result = tables.stream() .map(Table::getName) .filter(tableName -> !repairUnit.getBlacklistedTables().contains(tableName)) .filter(tableName -> !twcsBlacklisted.contains(tableName)) .collect(Collectors.toSet()); } else { result = repairUnit.getColumnFamilies().stream() .filter(tableName -> !repairUnit.getBlacklistedTables().contains(tableName)) .collect(Collectors.toSet()); } Preconditions.checkState( repairUnit.getBlacklistedTables().isEmpty() || !result.isEmpty(), "Invalid blacklist definition. It filtered out all tables in the keyspace."); return result; } private  RepairUnitService(AppContext context); static RepairUnitService create(AppContext context); RepairUnit getOrCreateRepairUnit(Cluster cluster, RepairUnit.Builder params); Set<String> findBlacklistedCompactionStrategyTables(Cluster clstr, Set<Table> tables); Set<String> getTableNamesForKeyspace(Cluster cluster, String keyspace);  }
@Test public void getTablesToRepairRemoveOneTableTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .blacklistedTables(Sets.newHashSet("table1")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2", "table3"), service.getTablesToRepair(cluster, unit)); }
@Test public void getTablesToRepairDefaultCompactionStrategyTable() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").build(), Table.builder().withName("table2").build(), Table.builder().withName("table3").build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .blacklistedTables(Sets.newHashSet("table1")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2", "table3"), service.getTablesToRepair(cluster, unit)); }
@Test public void getTablesToRepairRemoveOneTableWithTwcsTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(TWCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2", "table3"), service.getTablesToRepair(cluster, unit)); }
@Test public void getTablesToRepairRemoveTwoTablesTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .blacklistedTables(Sets.newHashSet("table1", "table3")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2"), service.getTablesToRepair(cluster, unit)); }
@Test public void getTablesToRepairRemoveTwoTablesOneWithTwcsTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(TWCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .blacklistedTables(Sets.newHashSet("table1")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2"), service.getTablesToRepair(cluster, unit)); }
@Test public void getTablesToRepairRemoveOneTableFromListTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .columnFamilies(Sets.newHashSet("table1", "table2")) .blacklistedTables(Sets.newHashSet("table1")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2"), service.getTablesToRepair(cluster, unit)); }
@Test public void getTablesToRepairRemoveOneTableFromListOneWithTwcsTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(TWCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .columnFamilies(Sets.newHashSet("table1", "table2")) .blacklistedTables(Sets.newHashSet("table1")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); assertEquals(Sets.newHashSet("table2"), service.getTablesToRepair(cluster, unit)); }
@Test(expected = IllegalStateException.class) public void getTablesToRepairRemoveAllFailingTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .blacklistedTables(Sets.newHashSet("table1", "table2", "table3")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); service.getTablesToRepair(cluster, unit); }
@Test(expected = IllegalStateException.class) public void getTablesToRepairRemoveAllFromListFailingTest() throws ReaperException { JmxProxy proxy = JmxProxyTest.mockJmxProxyImpl(); when(proxy.getCassandraVersion()).thenReturn("3.11.4"); when(context.jmxConnectionFactory.connectAny(Mockito.any(Collection.class))).thenReturn(proxy); when(proxy.getTablesForKeyspace(Mockito.anyString())) .thenReturn(Sets.newHashSet( Table.builder().withName("table1").withCompactionStrategy(STCS).build(), Table.builder().withName("table2").withCompactionStrategy(STCS).build(), Table.builder().withName("table3").withCompactionStrategy(STCS).build(), Table.builder().withName("table4").withCompactionStrategy(STCS).build())); RepairUnit unit = RepairUnit.builder() .clusterName(cluster.getName()) .keyspaceName("test") .columnFamilies(Sets.newHashSet("table1", "table2", "table3")) .blacklistedTables(Sets.newHashSet("table1", "table2", "table3")) .incrementalRepair(false) .repairThreadCount(4) .build(UUIDs.timeBased()); service.getTablesToRepair(cluster, unit); }