FoxtrotTableManager implements TableManager { @Override public void save(Table table) { validateTableParams(table); if(metadataManager.exists(table.getName())) { throw FoxtrotExceptions.createTableExistsException(table.getName()); } queryStore.initializeTable(table.getName()); dataStore.initializeTable(table, false); metadataManager.save(table); } @Inject  FoxtrotTableManager(TableMetadataManager metadataManager, QueryStore queryStore, DataStore dataStore); @Override void save(Table table); @Override void save(Table table, boolean forceCreateTable); @Override Table get(String name); @Override List<Table> getAll(); @Override void update(Table table); @Override void delete(String tableName);  }
@Test public void saveTableNullName() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); try { Table table = new Table(); table.setName(null); table.setTtl(60); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.INVALID_REQUEST, e.getCode()); } }
@Test public void saveTableEmptyName() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); try { Table table = new Table(); table.setName(" "); table.setTtl(60); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.INVALID_REQUEST, e.getCode()); } }
@Test public void saveNullTable() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); try { tableManager.save(null); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.INVALID_REQUEST, e.getCode()); } }
@Test public void saveTableInvalidTtl() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); try { Table table = new Table(); table.setName("abcd"); table.setTtl(0); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.INVALID_REQUEST, e.getCode()); } }
@Test public void saveTable() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); Table table = new Table(); table.setName("abcd"); table.setTtl(10); tableManager.save(table); }
@Test public void saveExistingTable() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); doReturn(true).when(metadataManager) .exists(any(String.class)); try { Table table = new Table(); table.setName("abcd"); table.setTtl(10); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.TABLE_ALREADY_EXISTS, e.getCode()); } }
@Test public void saveTableQueryStoreFailed() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doNothing().when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doThrow(FoxtrotExceptions.createExecutionException("dummy", new IOException())).when(queryStore) .initializeTable(any(String.class)); try { Table table = new Table(); table.setName("abcd"); table.setTtl(10); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.STORE_EXECUTION_ERROR, e.getCode()); } }
@Test public void saveTableDataStoreFailed() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doThrow(FoxtrotExceptions.createExecutionException("dummy", new IOException())).when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); try { Table table = new Table(); table.setName("abcd"); table.setTtl(10); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.STORE_EXECUTION_ERROR, e.getCode()); } }
@Test public void saveTableDataStoreNoTableFound() throws Exception { doNothing().when(metadataManager) .save(any(Table.class)); doThrow(FoxtrotExceptions.createTableMissingException("Dummy")).when(dataStore) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(queryStore) .initializeTable(any(String.class)); try { Table table = new Table(); table.setName("abcd"); table.setTtl(10); tableManager.save(table); fail(); } catch (FoxtrotException e) { assertEquals(ErrorCode.TABLE_NOT_FOUND, e.getCode()); } }