@Override public void createTaskTables() { if (config.get().isCreateTables()) { final MetadataStorageTablesConfig tablesConfig = tablesConfigSupplier.get(); final String entryType = tablesConfig.getTaskEntryType(); createEntryTable(tablesConfig.getEntryTable(entryType)); createLogTable(tablesConfig.getLogTable(entryType), entryType); createLockTable(tablesConfig.getLockTable(entryType), entryType); } }
@Test public void testCreateTables() throws Exception { final LinkedList<String> tables = new LinkedList<String>(); final String entryType = tablesConfig.getTaskEntryType(); tables.add(tablesConfig.getConfigTable()); tables.add(tablesConfig.getSegmentsTable()); tables.add(tablesConfig.getRulesTable()); tables.add(tablesConfig.getLockTable(entryType)); tables.add(tablesConfig.getLogTable(entryType)); tables.add(tablesConfig.getEntryTable(entryType)); tables.add(tablesConfig.getAuditTable()); connector.createSegmentTable(); connector.createConfigTable(); connector.createRulesTable(); connector.createTaskTables(); connector.createAuditTable(); connector .getDBI() .withHandle( new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { for (String table : tables) { Assert.assertTrue( String.format("table %s was not created!", table), connector.tableExists(handle, table)); } return null; } }); for (String table : tables) { dropTable(table); } }
public class TaskActionTestKit extends ExternalResource { private final MetadataStorageTablesConfig metadataStorageTablesConfig = MetadataStorageTablesConfig.fromBase("druid"); private TaskStorage taskStorage; private TaskLockbox taskLockbox; private TestDerbyConnector testDerbyConnector; private IndexerMetadataStorageCoordinator metadataStorageCoordinator; private TaskActionToolbox taskActionToolbox; public MetadataStorageTablesConfig getMetadataStorageTablesConfig() { return metadataStorageTablesConfig; } public TaskStorage getTaskStorage() { return taskStorage; } public TaskLockbox getTaskLockbox() { return taskLockbox; } public TestDerbyConnector getTestDerbyConnector() { return testDerbyConnector; } public IndexerMetadataStorageCoordinator getMetadataStorageCoordinator() { return metadataStorageCoordinator; } public TaskActionToolbox getTaskActionToolbox() { return taskActionToolbox; } @Override public void before() { taskStorage = new HeapMemoryTaskStorage(new TaskStorageConfig(new Period("PT24H"))); taskLockbox = new TaskLockbox(taskStorage); testDerbyConnector = new TestDerbyConnector( Suppliers.ofInstance(new MetadataStorageConnectorConfig()), Suppliers.ofInstance(metadataStorageTablesConfig)); metadataStorageCoordinator = new IndexerSQLMetadataStorageCoordinator( new TestUtils().getTestObjectMapper(), metadataStorageTablesConfig, testDerbyConnector); taskActionToolbox = new TaskActionToolbox(taskLockbox, metadataStorageCoordinator, new NoopServiceEmitter()); testDerbyConnector.createDataSourceTable(); testDerbyConnector.createPendingSegmentsTable(); testDerbyConnector.createSegmentTable(); testDerbyConnector.createRulesTable(); testDerbyConnector.createConfigTable(); testDerbyConnector.createTaskTables(); testDerbyConnector.createAuditTable(); } @Override public void after() { testDerbyConnector.tearDown(); taskStorage = null; taskLockbox = null; testDerbyConnector = null; metadataStorageCoordinator = null; taskActionToolbox = null; } }