use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestSubmitRule method testSubmitRule.
@Test
public void testSubmitRule() throws Exception {
String rule = "file: every 1s \n | length > 10 | cachefile";
SmartAdmin client = new SmartAdmin(conf);
long ruleId = 0l;
boolean wait = true;
while (wait) {
try {
ruleId = client.submitRule(rule, RuleState.ACTIVE);
wait = false;
} catch (IOException e) {
if (!e.toString().contains("not ready")) {
throw e;
}
}
}
for (int i = 0; i < 10; i++) {
long id = client.submitRule(rule, RuleState.ACTIVE);
Assert.assertTrue(ruleId + i + 1 == id);
}
String badRule = "something else";
try {
client.submitRule(badRule, RuleState.ACTIVE);
Assert.fail("Should have an exception here");
} catch (IOException e) {
}
try {
client.checkRule(badRule);
Assert.fail("Should have an exception here");
} catch (IOException e) {
}
}
use of org.smartdata.admin.SmartAdmin 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();
}
}
}
Aggregations