Search in sources :

Example 1 with DruidPool

use of org.smartdata.server.metastore.DruidPool 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)

Example 2 with DruidPool

use of org.smartdata.server.metastore.DruidPool in project SSM by Intel-bigdata.

the class SmartServer method getDBAdapter.

public DBAdapter getDBAdapter() throws Exception {
    String fileName = "druid.xml";
    URL urlPoolConf = getClass().getResource(fileName);
    if (urlPoolConf != null) {
        LOG.info("Using pool configure file: " + urlPoolConf.getFile());
        Properties p = new Properties();
        p.loadFromXML(getClass().getResourceAsStream(fileName));
        return new DBAdapter(new DruidPool(p));
    } else {
        LOG.info(fileName + " NOT found.");
    }
    // TODO: keep it now for testing, remove it later.
    Connection conn = getDBConnection();
    return new DBAdapter(conn);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) Connection(java.sql.Connection) Properties(java.util.Properties) URL(java.net.URL) DruidPool(org.smartdata.server.metastore.DruidPool)

Aggregations

Properties (java.util.Properties)2 DBAdapter (org.smartdata.server.metastore.DBAdapter)2 DruidPool (org.smartdata.server.metastore.DruidPool)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 Test (org.junit.Test)1 RuleInfo (org.smartdata.common.rule.RuleInfo)1