Search in sources :

Example 51 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.

the class SysnodesTest method listNodesTest.

@Test
public void listNodesTest() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager(nodeId, new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
        try (DataScanner scan = scan(manager, "SELECT * FROM SYSNODES", Collections.emptyList())) {
            List<DataAccessor> tuples = scan.consume();
            assertEquals(1, tuples.size());
            for (DataAccessor t : tuples) {
                System.out.println("node: " + t.toMap());
                assertNotNull(t.get("nodeid"));
                assertNotNull(t.get("address"));
            }
        }
    }
}
Also used : DataScanner(herddb.model.DataScanner) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) DataAccessor(herddb.utils.DataAccessor) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 52 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.

the class CreateTableTest method weThrowExceptionOnInsertingNullInNonNullColumn.

@Test(expected = StatementExecutionException.class)
public void weThrowExceptionOnInsertingNullInNonNullColumn() 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);
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.NOTNULL_STRING).primaryKey("id").build();
        CreateTableStatement st2 = new CreateTableStatement(table);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        TranslatedQuery translated1 = manager.getPlanner().translate("tblspace1", "INSERT INTO t1 (id,name) values(?,?)", Arrays.asList("test", "test1"), true, true, false, -1);
        manager.executePlan(translated1.plan, translated1.context, TransactionContext.NO_TRANSACTION);
        TranslatedQuery translated = manager.getPlanner().translate("tblspace1", "INSERT INTO t1 (id,name) values(?,?)", Arrays.asList("test", null), true, true, false, -1);
        manager.executePlan(translated.plan, translated.context, TransactionContext.NO_TRANSACTION);
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) TranslatedQuery(herddb.sql.TranslatedQuery) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 53 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.

the class CreateTableTest method createTableWithForeignKeys.

@Test
public void createTableWithForeignKeys() 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);
        Table parentTable = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        Table childTable = Table.builder().tablespace("tblspace1").name("t2").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).column("parenttableid", ColumnTypes.NOTNULL_STRING).primaryKey("id").foreingKey(ForeignKeyDef.builder().name("myfk").onDeleteAction(ForeignKeyDef.ACTION_NO_ACTION).onUpdateAction(ForeignKeyDef.ACTION_NO_ACTION).column("parenttableid").parentTableId(parentTable.uuid).parentTableColumn("id").build()).build();
        CreateTableStatement st2 = new CreateTableStatement(parentTable);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        CreateTableStatement st3 = new CreateTableStatement(childTable);
        manager.executeStatement(st3, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        ForeignKeyViolationException err = expectThrows(ForeignKeyViolationException.class, () -> {
            execute(manager, "INSERT INTO tblspace1.t2(id,name,parentTableId) values('a','name','pvalue')", Collections.emptyList());
        });
        assertEquals("myfk", err.getForeignKeyName());
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) ForeignKeyViolationException(herddb.model.ForeignKeyViolationException) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 54 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.

the class CreateTableTest method createTable1.

@Test
public void createTable1() 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);
        Table table = Table.builder().tablespace("tblspace1").name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
        CreateTableStatement st2 = new CreateTableStatement(table);
        manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        CreateTableStatement st2IfNotExists = new CreateTableStatement(table, Collections.emptyList(), true);
        manager.executeStatement(st2IfNotExists, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    }
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Example 55 with MemoryMetadataStorageManager

use of herddb.mem.MemoryMetadataStorageManager 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

MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)257 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)256 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)252 Test (org.junit.Test)247 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)240 DataScanner (herddb.model.DataScanner)156 RawString (herddb.utils.RawString)138 DBManager (herddb.core.DBManager)133 DataAccessor (herddb.utils.DataAccessor)83 Table (herddb.model.Table)80 ScanStatement (herddb.model.commands.ScanStatement)65 CreateTableStatement (herddb.model.commands.CreateTableStatement)57 TranslatedQuery (herddb.sql.TranslatedQuery)55 List (java.util.List)54 Index (herddb.model.Index)40 TransactionContext (herddb.model.TransactionContext)39 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)37 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)30 RuntimeProjectedDataAccessor (herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor)28 StatementExecutionException (herddb.model.StatementExecutionException)26