use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class ProfileEqualsAllocationsTest method simpleEqualsLongTest.
@Test
public void simpleEqualsLongTest() 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 ,n1 long primary key,n2 long, s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey", Integer.valueOf(1), "a", Long.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey2", Integer.valueOf(2), "a", Long.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey3", Integer.valueOf(5), "b", Long.valueOf(1))).getUpdateCount());
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5L))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5.0))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=5", Arrays.asList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
}
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class ProfileEqualsAllocationsTest method simpleEqualsTest.
@Test
public void simpleEqualsTest() 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,n2 long, s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey", Integer.valueOf(1), "a", Long.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey2", Integer.valueOf(2), "a", Long.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1,s1,n2) values(?,?,?,?)", Arrays.asList("mykey3", Integer.valueOf(5), "b", Long.valueOf(1))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1) values(?)", Arrays.asList("mykey4")).getUpdateCount());
{
long _start = System.currentTimeMillis();
for (int i = 0; i < 1; i++) {
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where k1=?", Arrays.asList("mykey"))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
if (i % 1000 == 0) {
long _stop = System.currentTimeMillis();
System.out.println(i + " time:" + (_stop - _start) + " ms");
}
}
}
long _stop = System.currentTimeMillis();
System.out.println("time:" + (_stop - _start) + " ms");
}
{
long _start = System.currentTimeMillis();
for (int i = 0; i < 1; i++) {
try (DataScanner scan1 = scan(manager, "SELECT * FROM tblspace1.tsql where n1=?", Arrays.asList(5))) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
if (i % 1000 == 0) {
long _stop = System.currentTimeMillis();
System.out.println(i + " time:" + (_stop - _start) + " ms");
}
}
}
long _stop = System.currentTimeMillis();
System.out.println("time:" + (_stop - _start) + " ms");
}
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class RecordTooBigTest method update.
@Test(expected = RecordTooBigException.class)
public void update() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.setMaxLogicalPageSize(160);
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string, s1 string, n1 int, primary key(k1))", Collections.emptyList());
try {
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey", "a", Integer.valueOf(1234))).getUpdateCount());
} catch (Exception e) {
e.printStackTrace();
fail("Got an unexpected of exception, insertion failed!");
}
try {
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql SET s1 = ? WHERE k1 = ?", Arrays.asList(RandomString.getInstance().nextString(25), "mykey")).getUpdateCount());
} catch (IllegalStateException e) {
e.printStackTrace();
fail("Got a wrong type of exception, record failed during page insertion!");
}
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class RawSQLTest method updateTest.
@Test
public void updateTest() 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,s1) values(?,?,?)", Arrays.asList("mykey", Integer.valueOf(1234), "value1")).getUpdateCount());
assertEquals(1, scan(manager, "SELECT * FROM tblspace1.tsql where s1='value1'", Collections.emptyList()).consumeAndClose().size());
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=k1 where k1=?", Arrays.asList("mykey")).getUpdateCount());
assertEquals(1, scan(manager, "SELECT * FROM tblspace1.tsql where s1='mykey'", Collections.emptyList()).consumeAndClose().size());
}
}
use of herddb.mem.MemoryMetadataStorageManager in project herddb by diennea.
the class RawSQLTest method simpleCountTest.
@Test
public void simpleCountTest() 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(1))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(2))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(3))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1) values(?)", Arrays.asList("mykey4")).getUpdateCount());
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(Long.valueOf(4), result.get(0).get(0));
assertEquals(Long.valueOf(4), result.get(0).get("cc"));
}
}
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(Long.valueOf(4), result.get(0).get(0));
assertEquals(Long.valueOf(4), result.get(0).get("expr$0"));
}
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc FROM tblspace1.tsql WHERE k1='mykey3'", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(1, result.size());
assertEquals(Long.valueOf(1), result.get(0).get(0));
assertEquals(Long.valueOf(1), result.get(0).get("cc"));
}
}
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*),k1 FROM tblspace1.tsql", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
Assert.fail();
} catch (StatementExecutionException error) {
assertTrue("field k1 MUST appear in GROUP BY clause".equals(error.getMessage()) || error.getMessage().equals("From line 1, column 17 to line 1, column 18: Expression 'K1' is not being grouped"));
}
}
{
try (DataScanner scan1 = scan(manager, "SELECT COUNT(*) as cc,k1 FROM tblspace1.tsql GROUP BY k1", Collections.emptyList())) {
List<DataAccessor> result = scan1.consume();
assertEquals(4, result.size());
for (DataAccessor t : result) {
assertEquals(Long.valueOf(1), t.get("cc"));
switch(t.get("k1") + "") {
case "mykey":
case "mykey2":
case "mykey3":
case "mykey4":
break;
default:
fail();
}
}
}
}
}
}
Aggregations