Search in sources :

Example 1 with DBAdapter

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);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) CommandInfo(org.smartdata.common.command.CommandInfo)

Example 2 with DBAdapter

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);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Example 3 with DBAdapter

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);
    }
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) Statement(java.sql.Statement) SortedTable(org.dbunit.dataset.SortedTable) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) AccessCountTable(org.smartdata.server.metastore.tables.AccessCountTable) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Example 4 with DBAdapter

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);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) CommandInfo(org.smartdata.common.command.CommandInfo)

Example 5 with DBAdapter

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();
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) InputStream(java.io.InputStream) Properties(java.util.Properties) RuleInfo(org.smartdata.common.rule.RuleInfo) DruidPool(org.smartdata.server.metastore.DruidPool) Test(org.junit.Test)

Aggregations

DBAdapter (org.smartdata.server.metastore.DBAdapter)17 Test (org.junit.Test)11 Connection (java.sql.Connection)5 DBTest (org.smartdata.server.metastore.DBTest)4 File (java.io.File)3 IOException (java.io.IOException)3 FsPermission (org.apache.hadoop.fs.permission.FsPermission)3 DFSClient (org.apache.hadoop.hdfs.DFSClient)3 IDataSet (org.dbunit.dataset.IDataSet)3 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 Configuration (org.apache.hadoop.conf.Configuration)2 Path (org.apache.hadoop.fs.Path)2 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)2 Event (org.apache.hadoop.hdfs.inotify.Event)2 ITable (org.dbunit.dataset.ITable)2 SortedTable (org.dbunit.dataset.SortedTable)2 CommandInfo (org.smartdata.common.command.CommandInfo)2