use of herddb.model.commands.TableConsistencyCheckStatement in project herddb by diennea.
the class MultiNodeConsistencyCheckTest method consistencyCheckReplicaTest.
@Test
public void consistencyCheckReplicaTest() throws Exception {
final AtomicInteger callCount = new AtomicInteger();
SystemInstrumentation.addListener(new SystemInstrumentation.SingleInstrumentationPointListener("createChecksum") {
@Override
public void acceptSingle(Object... args) throws Exception {
callCount.incrementAndGet();
}
});
try (DBManager manager1 = startDBManager("node1")) {
manager1.executeStatement(new CreateTableSpaceStatement(tableSpaceName, new HashSet<>(Arrays.asList("node1", "node2")), "node1", 1, 0, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager1.waitForTablespace(tableSpaceName, 10000, true);
try (DBManager manager2 = startDBManager("node2")) {
manager2.waitForTablespace(tableSpaceName, 10000, false);
Table table = Table.builder().tablespace(tableSpaceName).name(tableName).column("id", ColumnTypes.STRING).column("name", ColumnTypes.BOOLEAN).primaryKey("id").build();
CreateTableStatement st = new CreateTableStatement(table);
manager1.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager1.waitForTable(tableSpaceName, tableName, 10000, true);
execute(manager1, "INSERT INTO t2.table1 (id,name) values (?,?)", Arrays.asList("1", true));
execute(manager1, "INSERT INTO t2.table1 (id,name) values (?,?)", Arrays.asList("2", false));
manager2.waitForTable(tableSpaceName, tableName, 10000, false);
TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement("table1", "t2");
DataConsistencyStatementResult result = manager1.createTableCheckSum(statement, null);
assertTrue("Consistency check replicated test ", result.getOk());
// The follower is always back 1, I make an entry to make him apply consistency log
execute(manager1, "INSERT INTO t2.table1 (id,name) values (?,?)", Arrays.asList("3", false));
}
}
// Expected 2 call for createChecksum (node1 and node2)
assertEquals(2, callCount.get());
}
use of herddb.model.commands.TableConsistencyCheckStatement in project herddb by diennea.
the class DataConsistencyCheckTest method tableConsistencyCheckWithNullValue.
@Test
public void tableConsistencyCheckWithNullValue() 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);
execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (k1,n1 ,s1) values (?,?,?)", Arrays.asList("1", null, "b"));
execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (k1,n1 ,s1) values (?,?,?)", Arrays.asList("2", null, "b"));
TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement(tableName, tableSpaceName);
DataConsistencyStatementResult result = manager.createTableCheckSum(statement, null);
assertTrue("Check table with null value ", result.getOk());
}
}
Aggregations