use of herddb.core.DBManager in project herddb by diennea.
the class JSQLParserPlannerTest method testColumnWithNameSize.
@Test
public void testColumnWithNameSize() 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,size int)", Collections.emptyList());
execute(manager, "INSERT INTO tblspace1.tsql (k1,size) values(?,?)", Arrays.asList("mykey", 1234), TransactionContext.NO_TRANSACTION);
try (DataScanner scan = scan(manager, "SELECT size,k1 FROM tblspace1.tsql where size=1234", Collections.emptyList())) {
assertEquals(1, scan.consume().size());
}
}
}
use of herddb.core.DBManager in project herddb by diennea.
the class RawSQLTest method insertJdbcParametersTest.
@Test
public void insertJdbcParametersTest() 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());
{
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(n1,k1) values(?,?)", Arrays.asList(Integer.valueOf(1234), "mykey2")).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(n1,k1,s1) values(?,?,?)", Arrays.asList(Integer.valueOf(1234), "mykey3", "string2")).getUpdateCount());
}
}
}
use of herddb.core.DBManager in project herddb by diennea.
the class AlterTablespaceSQLTest method createAlterTableSpace.
@Test
public void createAlterTableSpace() 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));
execute(manager, "EXECUTE CREATETABLESPACE 'ttt'", Collections.emptyList());
execute(manager, "CREATE TABLESPACE 'ttt2','leader:" + nodeId + "'", Collections.emptyList());
try {
execute(manager, "EXECUTE CREATETABLESPACE 'ttt2','leader:othernode'", Collections.emptyList());
fail();
} catch (TableSpaceAlreadyExistsException err) {
}
execute(manager, "EXECUTE CREATETABLESPACE 'ttt3','leader:othernode'", Collections.emptyList());
execute(manager, "EXECUTE CREATETABLESPACE 'ttt4','leader:othernode','replica:" + nodeId + ",othernode'", Collections.emptyList());
execute(manager, "EXECUTE ALTERTABLESPACE 'ttt3','replica:" + nodeId + ",othernode','expectedReplicaCount:2'", Collections.emptyList());
execute(manager, "EXECUTE ALTERTABLESPACE 'ttt3','leader:othernode'", Collections.emptyList());
execute(manager, "EXECUTE ALTERTABLESPACE 'ttt3','expectedReplicaCount:12'", Collections.emptyList());
TableSpace ttt3 = manager.getMetadataStorageManager().describeTableSpace("ttt3");
assertEquals("othernode", ttt3.leaderId);
assertEquals(12, ttt3.expectedReplicaCount);
assertTrue(ttt3.replicas.contains("othernode"));
assertTrue(ttt3.replicas.contains(nodeId));
try (DataScanner scan = scan(manager, "SELECT * FROM SYSTABLESPACES", Collections.emptyList())) {
List<DataAccessor> tuples = scan.consume();
assertEquals(5, tuples.size());
for (DataAccessor t : tuples) {
System.out.println("tablespace: " + t.toMap());
assertNotNull(t.get("expectedreplicacount"));
assertNotNull(t.get("tablespace_name"));
assertNotNull(t.get("replica"));
assertNotNull(t.get("leader"));
}
}
try (DataScanner scan = scan(manager, "SELECT expectedreplicacount FROM SYSTABLESPACES where tablespace_name='ttt3'", Collections.emptyList())) {
List<DataAccessor> tuples = scan.consume();
assertEquals(1, tuples.size());
for (DataAccessor t : tuples) {
System.out.println("tablespace: " + t.toMap());
assertEquals(12, t.get("expectedreplicacount"));
}
}
}
}
use of herddb.core.DBManager in project herddb by diennea.
the class DataConsistencyCheckTest method tableSpaceConsistencyCheck.
@Test
public void tableSpaceConsistencyCheck() throws Exception {
String tableSpaceName = "tblspace1";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
assertTrue(manager.waitForBootOfLocalTablespaces(10000));
execute(manager, "CREATE TABLESPACE 'tblspace1'", Collections.emptyList());
manager.waitForTablespace("tblspace1", 10000);
manager.waitForTablespace(tableSpaceName, 10000, false);
Table table = Table.builder().tablespace(tableSpaceName).name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
Table table2 = Table.builder().tablespace(tableSpaceName).name("t2").column("id", ColumnTypes.STRING).column("name", ColumnTypes.BOOLEAN).primaryKey("id").build();
CreateTableStatement st = new CreateTableStatement(table);
manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
CreateTableStatement st2 = new CreateTableStatement(table2);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
execute(manager, "INSERT INTO tblspace1.t1 (id,name) values (?,?)", Arrays.asList("1", true));
execute(manager, "INSERT INTO tblspace1.t1 (id,name) values (?,?)", Arrays.asList("2", false));
execute(manager, "INSERT INTO tblspace1.t2 (id,name) values (?,?)", Arrays.asList("1", true));
execute(manager, "INSERT INTO tblspace1.t2 (id,name) values (?,?)", Arrays.asList("2", false));
TableSpaceConsistencyCheckStatement statement = new TableSpaceConsistencyCheckStatement(tableSpaceName);
DataConsistencyStatementResult result = manager.createTableSpaceCheckSum(statement);
assertTrue("Check tableSpace ", result.getOk());
}
}
use of herddb.core.DBManager in project herddb by diennea.
the class DataConsistencyCheckTest method emptyTableConsistencyCheck.
@Test
public void emptyTableConsistencyCheck() throws Exception {
String tableSpaceName = "tblspace1";
String tableName = "t1";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
assertTrue(manager.waitForBootOfLocalTablespaces(10000));
execute(manager, "CREATE TABLESPACE 'tblspace1'", Collections.emptyList());
manager.waitForTablespace("tblspace1", 10000);
Table table = Table.builder().tablespace(tableSpaceName).name(tableName).column("k1", ColumnTypes.STRING).column("n1", ColumnTypes.INTEGER).column("s1", ColumnTypes.STRING).primaryKey("k1").build();
CreateTableStatement st = new CreateTableStatement(table);
manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
// check empty table
TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement(tableName, tableSpaceName);
DataConsistencyStatementResult result = manager.createTableCheckSum(statement, null);
assertTrue("Check empty table ", result.getOk());
}
}
Aggregations