use of org.smartdata.model.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 | cache";
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.model.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 | cache";
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.model.RuleInfo in project SSM by Intel-bigdata.
the class TestSmallFileRule method testRule.
@Test(timeout = 180000)
public void testRule() throws Exception {
waitTillSSMExitSafeMode();
String rule = "file: path matches \"/test/small_files/file*\" and length < 20KB" + " | compact -containerFile \"/test/small_files/container_file_1\"";
SmartAdmin admin = new SmartAdmin(smartContext.getConf());
admin.submitRule(rule, RuleState.ACTIVE);
Thread.sleep(6000);
List<RuleInfo> ruleInfoList = admin.listRulesInfo();
for (RuleInfo info : ruleInfoList) {
System.out.println(info);
}
Assert.assertEquals(1, ruleInfoList.size());
}
use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.
the class TestSmartAdmin method test.
@Test
public void test() throws Exception {
waitTillSSMExitSafeMode();
SmartAdmin admin = null;
try {
admin = new SmartAdmin(smartContext.getConf());
// test listRulesInfo and submitRule
List<RuleInfo> ruleInfos = admin.listRulesInfo();
int ruleCounts0 = ruleInfos.size();
long ruleId = admin.submitRule("file: every 5s | path matches \"/foo*\"| cache", RuleState.DRYRUN);
ruleInfos = admin.listRulesInfo();
int ruleCounts1 = ruleInfos.size();
assertEquals(1, ruleCounts1 - ruleCounts0);
// test checkRule
// if success ,no Exception throw
admin.checkRule("file: every 5s | path matches \"/foo*\"| cache");
boolean caughtException = false;
try {
admin.checkRule("file.path");
} catch (IOException e) {
caughtException = true;
}
assertTrue(caughtException);
// test getRuleInfo
RuleInfo ruleInfo = admin.getRuleInfo(ruleId);
assertNotEquals(null, ruleInfo);
// test disableRule
admin.disableRule(ruleId, true);
assertEquals(RuleState.DISABLED, admin.getRuleInfo(ruleId).getState());
// test activateRule
admin.activateRule(ruleId);
assertEquals(RuleState.ACTIVE, admin.getRuleInfo(ruleId).getState());
// test deleteRule
admin.deleteRule(ruleId, true);
assertEquals(RuleState.DELETED, admin.getRuleInfo(ruleId).getState());
// test cmdletInfo
long id = admin.submitCmdlet("cache -file /foo*");
CmdletInfo cmdletInfo = admin.getCmdletInfo(id);
assertTrue("cache -file /foo*".equals(cmdletInfo.getParameters()));
// test actioninfo
List<Long> aidlist = cmdletInfo.getAids();
assertNotEquals(0, aidlist.size());
ActionInfo actionInfo = admin.getActionInfo(aidlist.get(0));
assertEquals(id, actionInfo.getCmdletId());
// test listActionInfoOfLastActions
admin.listActionInfoOfLastActions(2);
List<ActionDescriptor> actions = admin.listActionsSupported();
assertTrue(actions.size() > 0);
// test client close
admin.close();
try {
admin.getRuleInfo(ruleId);
Assert.fail("Should fail because admin has closed.");
} catch (IOException e) {
}
admin = null;
} finally {
if (admin != null) {
admin.close();
}
}
}
use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.
the class TestRuleDao method testUpdateRule.
@Test
public void testUpdateRule() throws Exception {
String rule = "file : accessCount(10m) > 20 \n\n" + "and length() > 3 | cache";
long submitTime = System.currentTimeMillis();
RuleInfo info1 = new RuleInfo(20L, submitTime, rule, RuleState.ACTIVE, 12, 12, 12);
ruleDao.insert(info1);
long rid = ruleDao.update(info1.getId(), RuleState.DISABLED.getValue());
Assert.assertTrue(rid == info1.getId());
info1 = ruleDao.getById(info1.getId());
Assert.assertTrue(info1.getNumChecked() == 12L);
ruleDao.update(rid, System.currentTimeMillis(), 100, 200);
RuleInfo info2 = ruleDao.getById(rid);
Assert.assertTrue(info2.getNumChecked() == 100L);
}
Aggregations