Search in sources :

Example 21 with RuleInfo

use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.

the class TestSubmitRuleThroughCli method test.

@Test
public void test() throws Exception {
    waitTillSSMExitSafeMode();
    String ruleFile = TestDBUtil.getUniqueFilePath();
    try {
        String rule = "file: every 1s \n | length > 10 | cachefile";
        FileOutputStream os = new FileOutputStream(ruleFile);
        os.write(rule.getBytes());
        os.close();
        SmartAdmin client = new SmartAdmin(conf);
        String[] args = new String[] { "submitrule", ruleFile };
        SmartShell.main(args);
        Thread.sleep(2000);
        List<RuleInfo> infos = client.listRulesInfo();
        Assert.assertTrue(infos.size() == 1);
        Thread.sleep(1500);
        List<RuleInfo> infos2 = client.listRulesInfo();
        long diff = infos2.get(0).getNumChecked() - infos.get(0).getNumChecked();
        Assert.assertTrue(diff >= 1);
    } finally {
        File f = new File(ruleFile);
        if (f.exists()) {
            f.deleteOnExit();
        }
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) FileOutputStream(java.io.FileOutputStream) RuleInfo(org.smartdata.common.rule.RuleInfo) File(java.io.File) Test(org.junit.Test)

Example 22 with RuleInfo

use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.

the class TestRuleManager method testMultiThreadUpdate.

@Test
public void testMultiThreadUpdate() throws Exception {
    String rule = "file: every 1s \n | length > 10 | cachefile";
    long now = System.currentTimeMillis();
    long rid = ruleManager.submitRule(rule, RuleState.DISABLED);
    ruleManager.updateRuleInfo(rid, null, now, 1, 1);
    long start = System.currentTimeMillis();
    Thread[] threads = new Thread[] { new Thread(new RuleInfoUpdater(rid, 3)), new Thread(new RuleInfoUpdater(rid, 7)), new Thread(new RuleInfoUpdater(rid, 11)), new Thread(new RuleInfoUpdater(rid, 17)) };
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    long end = System.currentTimeMillis();
    System.out.println("Time used = " + (end - start) + " ms");
    RuleInfo res = ruleManager.getRuleInfo(rid);
    System.out.println(res);
}
Also used : RuleInfo(org.smartdata.common.rule.RuleInfo) Test(org.junit.Test)

Aggregations

RuleInfo (org.smartdata.common.rule.RuleInfo)22 Test (org.junit.Test)14 IOException (java.io.IOException)5 SmartAdmin (org.smartdata.admin.SmartAdmin)4 ArrayList (java.util.ArrayList)3 ServiceException (com.google.protobuf.ServiceException)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 RuleInfoProto (org.smartdata.common.protocol.AdminServerProto.RuleInfoProto)2 DBAdapter (org.smartdata.server.metastore.DBAdapter)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 ListRulesInfoRequestProto (org.smartdata.common.protocol.AdminServerProto.ListRulesInfoRequestProto)1