CassandraTableManager { public InitializationStatus initializeTables() { KeyspaceMetadata keyspaceMetadata = session.getCluster() .getMetadata() .getKeyspace(session.getLoggedKeyspace()); return module.moduleTables() .stream() .map(table -> table.initialize(keyspaceMetadata, session)) .reduce((left, right) -> left.reduce(right)) .orElse(InitializationStatus.ALREADY_DONE); } @Inject  CassandraTableManager(CassandraModule module, Session session); InitializationStatus initializeTables(); void clearAllTables();  }
@Test void initializeTableShouldCreateAllTheTables() { cassandra.getConf().execute(SchemaBuilder.dropTable(TABLE_NAME)); cassandra.getConf().execute(SchemaBuilder.dropTable(CassandraSchemaVersionTable.TABLE_NAME)); assertThat(new CassandraTableManager(MODULE, cassandra.getConf()).initializeTables()) .isEqualByComparingTo(CassandraTable.InitializationStatus.FULL); ensureTableExistence(TABLE_NAME); }
@Test void initializeTableShouldCreateAllTheMissingTable() { cassandra.getConf().execute(SchemaBuilder.dropTable(TABLE_NAME)); assertThat(new CassandraTableManager(MODULE, cassandra.getConf()).initializeTables()) .isEqualByComparingTo(CassandraTable.InitializationStatus.PARTIAL); ensureTableExistence(TABLE_NAME); }
@Test void initializeTableShouldNotPerformIfCalledASecondTime() { assertThat(new CassandraTableManager(MODULE, cassandra.getConf()).initializeTables()) .isEqualByComparingTo(CassandraTable.InitializationStatus.ALREADY_DONE); }
@Test void initializeTableShouldNotFailIfCalledASecondTime() { new CassandraTableManager(MODULE, cassandra.getConf()).initializeTables(); ensureTableExistence(TABLE_NAME); }