StorageCleanJobHbaseUtil { @SuppressWarnings("deprecation") public static List<String> cleanUnusedHBaseTables(boolean delete, int deleteTimeout, int threadsNum) throws IOException { try (HBaseAdmin hbaseAdmin = new HBaseAdmin(HBaseConfiguration.create())) { return cleanUnusedHBaseTables(hbaseAdmin, delete, deleteTimeout, threadsNum); } }  @SuppressWarnings("deprecation") static List<String> cleanUnusedHBaseTables(boolean delete, int deleteTimeout, int threadsNum);  }
@Test public void test() throws IOException { HBaseAdmin hBaseAdmin = mock(HBaseAdmin.class); HTableDescriptor[] hds = new HTableDescriptor[2]; HTableDescriptor d1 = mock(HTableDescriptor.class); HTableDescriptor d2 = mock(HTableDescriptor.class); hds[0] = d1; hds[1] = d2; when(d1.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/"); when(d2.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/"); when(d1.getTableName()).thenReturn(TableName.valueOf("KYLIN_J9TE08D9IA")); String toBeDel = "to-be-del"; when(d2.getTableName()).thenReturn(TableName.valueOf(toBeDel)); when(hBaseAdmin.listTables("KYLIN_.*")).thenReturn(hds); when(hBaseAdmin.tableExists(toBeDel)).thenReturn(true); when(hBaseAdmin.isTableEnabled(toBeDel)).thenReturn(false); StorageCleanJobHbaseUtil.cleanUnusedHBaseTables(hBaseAdmin, true, 100000, 1); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(hBaseAdmin).deleteTable(captor.capture()); assertEquals(Lists.newArrayList(toBeDel), captor.getAllValues()); }