Search in sources :

Example 1 with DropTableSpaceStatement

use of herddb.model.commands.DropTableSpaceStatement in project herddb by diennea.

the class DropTablespaceTest method test.

@Test
public void test() 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());
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(0, count.intValue());
        }
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM systablespaces WHERE tablespace_name=?", Arrays.asList("tblspace1"))) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(1, count.intValue());
        }
        manager.executeStatement(new DropTableSpaceStatement("tblspace1"), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM systablespaces WHERE tablespace_name=?", Arrays.asList("tblspace1"))) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(0, count.intValue());
        }
        boolean ok = false;
        for (int i = 0; i < 100; i++) {
            try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
                Thread.sleep(200);
            } catch (herddb.model.StatementExecutionException expected) {
                ok = true;
            }
        }
        assertTrue(ok);
        // create again the table space, all data should be lost
        CreateTableSpaceStatement st1_2 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1_2, 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());
        try (DataScanner scan = TestUtils.scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql ", Collections.emptyList())) {
            Number count = (Number) scan.consume().get(0).get(0);
            assertEquals(0, count.intValue());
        }
    }
}
Also used : DropTableSpaceStatement(herddb.model.commands.DropTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DataScanner(herddb.model.DataScanner) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)1 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)1 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)1 DataScanner (herddb.model.DataScanner)1 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)1 DropTableSpaceStatement (herddb.model.commands.DropTableSpaceStatement)1 Test (org.junit.Test)1