use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestCommandExecutor method testCommandExecutorHelper.
private void testCommandExecutorHelper() throws Exception {
DBAdapter dbAdapter = ssm.getDBAdapter();
String cidCondition = ">= 1 ";
String ridCondition = ">= 1 ";
while (true) {
Thread.sleep(2000);
int current = ssm.getCommandExecutor().cacheSize();
System.out.printf("Command Cache size = %d\n ", current);
if (current == 0) {
break;
}
}
List<CommandInfo> com = dbAdapter.getCommandsTableItem(cidCondition, ridCondition, CommandState.DONE);
System.out.printf("Size = %d\n", com.size());
// Check Status
Assert.assertTrue(com.size() == 1);
Assert.assertTrue(com.get(0).getState() == CommandState.DONE);
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestDBAdapter method testGetFileIds.
@Test
public void testGetFileIds() throws Exception {
createTables(databaseTester.getConnection());
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("files.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
List<String> paths = Arrays.asList("file1", "file2", "file3");
Map<String, Long> pathToID = dbAdapter.getFileIDs(paths);
Assert.assertTrue(pathToID.get("file1") == 101);
Assert.assertTrue(pathToID.get("file2") == 102);
Assert.assertTrue(pathToID.get("file3") == 103);
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestDBAdapter method testCreateProportionView.
@Test
public void testCreateProportionView() throws Exception {
Statement statement = databaseTester.getConnection().getConnection().createStatement();
statement.execute(AccessCountTable.createTableSQL("table1"));
statement.execute(AccessCountTable.createTableSQL("table2"));
statement.execute(AccessCountTable.createTableSQL("table3"));
statement.execute(AccessCountTable.createTableSQL("expect"));
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
AccessCountTable table3 = new AccessCountTable("table3", 0L, 10L, TimeGranularity.SECOND);
DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
// 50%
AccessCountTable viewTable = new AccessCountTable(0L, 5L);
dbAdapter.createProportionView(viewTable, table3);
ITable actual = databaseTester.getConnection().createTable(viewTable.getTableName());
ITable expect = databaseTester.getConnection().createTable(table3.getTableName());
SortedTable sortedActual = new SortedTable(actual, new String[] { "fid" });
sortedActual.setUseComparable(true);
Assert.assertTrue(sortedActual.getRowCount() == expect.getRowCount());
for (int i = 0; i < expect.getRowCount(); i++) {
Integer actualAC = (Integer) sortedActual.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
Integer expectAC = (Integer) expect.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
Assert.assertTrue(actualAC == expectAC / 2);
}
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestCommandExecutor method generateTestCases.
private void generateTestCases() throws Exception {
DBAdapter dbAdapter = ssm.getDBAdapter();
CommandDescriptor commandDescriptor = generateCommandDescriptor();
CommandInfo commandInfo = new CommandInfo(0, commandDescriptor.getRuleId(), ActionType.CacheFile, CommandState.PENDING, commandDescriptor.getCommandString(), 123178333l, 232444994l);
CommandInfo[] commands = { commandInfo };
dbAdapter.insertCommandsTable(commands);
}
use of org.smartdata.server.metastore.DBAdapter in project SSM by Intel-bigdata.
the class TestDruid method test.
@Test
public void test() throws Exception {
InputStream in = getClass().getClassLoader().getResourceAsStream("druid-template.xml");
Properties p = new Properties();
p.loadFromXML(in);
String dbFile = TestDBUtil.getUniqueEmptySqliteDBFile();
String url = Util.SQLITE_URL_PREFIX + dbFile;
p.setProperty("url", url);
DruidPool druidPool = new DruidPool(p);
DBAdapter adapter = new DBAdapter(druidPool);
String rule = "file : accessCountX(10m) > 20 \n\n" + "and length() > 3 | cachefile";
long submitTime = System.currentTimeMillis();
RuleInfo info1 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
Assert.assertTrue(adapter.insertNewRule(info1));
RuleInfo info1_1 = adapter.getRuleInfo(info1.getId());
Assert.assertTrue(info1.equals(info1_1));
long now = System.currentTimeMillis();
adapter.updateRuleInfo(info1.getId(), RuleState.DELETED, now, 1, 1);
RuleInfo info1_2 = adapter.getRuleInfo(info1.getId());
Assert.assertTrue(info1_2.getLastCheckTime() == now);
druidPool.close();
}
Aggregations