use of herddb.model.TableDoesNotExistException in project herddb by diennea.
the class RawSQLTest method createDropIndexTest.
@Test
public void createDropIndexTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
try {
execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
fail();
} catch (IndexAlreadyExistsException ok) {
}
execute(manager, "DROP INDEX tblspace1.ix1", Collections.emptyList());
execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
execute(manager, "CREATE HASH INDEX ix_hash ON tblspace1.tsql(n1)", Collections.emptyList());
try {
execute(manager, "CREATE BADTYPE INDEX ix_bad ON tblspace1.tsql(n1)", Collections.emptyList());
fail();
} catch (StatementExecutionException ok) {
assertTrue(ok.getMessage().contains("badtype"));
}
try {
execute(manager, "DROP INDEX tblspace1.ix2", Collections.emptyList());
fail();
} catch (IndexDoesNotExistException ok) {
}
try {
execute(manager, "DROP INDEX ix1", Collections.emptyList());
fail();
} catch (IndexDoesNotExistException ok) {
}
try {
execute(manager, "CREATE INDEX ix2 ON tsql(n1)", Collections.emptyList());
fail();
} catch (TableDoesNotExistException ok) {
}
try {
execute(manager, "CREATE INDEX duplicatecolumn ON tblspace1.tsql(n1,n1)", Collections.emptyList());
fail();
} catch (StatementExecutionException ok) {
}
execute(manager, "CREATE UNIQUE INDEX ixu1 ON tblspace1.tsql(n1)", Collections.emptyList());
Map<String, AbstractIndexManager> indexesOnTable = manager.getTableSpaceManager("tblspace1").getIndexesOnTable("tsql");
assertTrue(indexesOnTable.values().stream().anyMatch(s -> s.getIndexName().equals("ixu1") && s.isUnique()));
}
}
Aggregations