use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestRuleManager method testSubmitAutoEndsRule.
@Test
public void testSubmitAutoEndsRule() throws Exception {
String rule = "file: every 1s from now to now + 2s \n | " + "length > 300 | cachefile";
long id = ruleManager.submitRule(rule, RuleState.ACTIVE);
RuleInfo ruleInfo = ruleManager.getRuleInfo(id);
Assert.assertTrue(ruleInfo.getRuleText().equals(rule));
RuleInfo info = ruleInfo;
for (int i = 0; i < 5; i++) {
Thread.sleep(1000);
info = ruleManager.getRuleInfo(id);
System.out.println(info);
}
Assert.assertTrue(info.getState() == RuleState.FINISHED);
Assert.assertTrue(info.getNumChecked() - ruleInfo.getNumChecked() <= 3);
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestRuleManager method testSubmitNewDisabledRule.
@Test
public void testSubmitNewDisabledRule() throws Exception {
String rule = "file: every 1s \n | length > 300 | cachefile";
long id = ruleManager.submitRule(rule, RuleState.DISABLED);
RuleInfo ruleInfo = ruleManager.getRuleInfo(id);
Assert.assertTrue(ruleInfo.getRuleText().equals(rule));
RuleInfo info = ruleInfo;
for (int i = 0; i < 5; i++) {
Thread.sleep(1000);
info = ruleManager.getRuleInfo(id);
System.out.println(info);
}
Assert.assertTrue(info.getNumChecked() - ruleInfo.getNumChecked() == 0);
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestRuleManager method testSubmitNewActiveRule.
@Test
public void testSubmitNewActiveRule() throws Exception {
String rule = "file: every 1s \n | accessCount(5s) > 3 | cachefile";
long id = ruleManager.submitRule(rule, RuleState.ACTIVE);
RuleInfo ruleInfo = ruleManager.getRuleInfo(id);
Assert.assertTrue(ruleInfo.getRuleText().equals(rule));
RuleInfo info = ruleInfo;
for (int i = 0; i < 5; i++) {
Thread.sleep(1000);
info = ruleManager.getRuleInfo(id);
System.out.println(info);
}
Assert.assertTrue(info.getNumChecked() - ruleInfo.getNumChecked() > 3);
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class TestRulesTable method testRuleInsert.
/**
* Insert rules into table and retrieve them back.
* @throws Exception
*/
@Test
public void testRuleInsert() throws Exception {
String dbFile = TestDBUtil.getUniqueDBFilePath();
Connection conn = null;
try {
conn = Util.createSqliteConnection(dbFile);
Util.initializeDataBase(conn);
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);
DBAdapter adapter = new DBAdapter(conn);
Assert.assertTrue(adapter.insertNewRule(info1));
RuleInfo info1_1 = adapter.getRuleInfo(info1.getId());
Assert.assertTrue(info1.equals(info1_1));
RuleInfo info2 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
Assert.assertTrue(adapter.insertNewRule(info2));
RuleInfo info2_1 = adapter.getRuleInfo(info2.getId());
Assert.assertFalse(info1_1.equals(info2_1));
List<RuleInfo> infos = adapter.getRuleInfo();
assert (infos.size() == 2);
} finally {
if (conn != null) {
conn.close();
}
File file = new File(dbFile);
file.deleteOnExit();
}
}
use of org.smartdata.common.rule.RuleInfo in project SSM by Intel-bigdata.
the class DBAdapter method doGetRuleInfo.
private List<RuleInfo> doGetRuleInfo(String sql) throws SQLException {
QueryHelper queryHelper = new QueryHelper(sql);
List<RuleInfo> infos = new LinkedList<>();
try {
ResultSet rs = queryHelper.executeQuery();
while (rs.next()) {
infos.add(new RuleInfo(rs.getLong("id"), rs.getLong("submit_time"), rs.getString("rule_text"), RuleState.fromValue((int) rs.getByte("state")), rs.getLong("checked_count"), rs.getLong("commands_generated"), rs.getLong("last_check_time")));
}
return infos;
} finally {
queryHelper.close();
}
}
Aggregations