use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class TestActionDao method testUpdateAction.
@Test
public void testUpdateAction() throws Exception {
Map<String, String> args = new HashMap<>();
ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
actionDao.insert(actionInfo);
actionInfo.setSuccessful(true);
actionDao.update(actionInfo);
ActionInfo dbActionInfo = actionDao.getById(actionInfo.getActionId());
Assert.assertTrue(actionInfo.equals(dbActionInfo));
}
use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class TestActionDao method testGetNewDeleteAction.
@Test
public void testGetNewDeleteAction() throws Exception {
Map<String, String> args = new HashMap<>();
ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
List<ActionInfo> actionInfoList = actionDao.getLatestActions(0);
// Get from empty table
Assert.assertTrue(actionInfoList.size() == 0);
actionDao.insert(actionInfo);
actionInfo.setActionId(2);
actionDao.insert(actionInfo);
actionInfoList = actionDao.getLatestActions(0);
Assert.assertTrue(actionInfoList.size() == 2);
actionInfoList = actionDao.getByIds(Arrays.asList(1L, 2L));
Assert.assertTrue(actionInfoList.size() == 2);
actionDao.delete(actionInfo.getActionId());
actionInfoList = actionDao.getAll();
Assert.assertTrue(actionInfoList.size() == 1);
}
use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class TestActionDao method testGetLatestActionListByFinishAndSuccess.
@Test
public void testGetLatestActionListByFinishAndSuccess() {
Map<String, String> args = new HashMap<>();
ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
List<ActionInfo> actionInfoList = actionDao.getLatestActions("cache", 0, false, true);
// Get from empty table
Assert.assertTrue(actionInfoList.size() == 0);
actionDao.insert(actionInfo);
actionInfo.setActionId(2);
actionDao.insert(actionInfo);
actionInfoList = actionDao.getLatestActions("cache", 0, false, true);
Assert.assertTrue(actionInfoList.size() == 2);
actionInfoList = actionDao.getByIds(Arrays.asList(1L, 2L));
Assert.assertTrue(actionInfoList.size() == 2);
actionInfoList = actionDao.getLatestActions("cache", 1, false, true);
Assert.assertTrue(actionInfoList.size() == 1);
}
use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.
the class TestActionDao method testMaxId.
@Test
public void testMaxId() throws Exception {
Map<String, String> args = new HashMap<>();
ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
Assert.assertTrue(actionDao.getMaxId() == 0);
actionDao.insert(actionInfo);
Assert.assertTrue(actionDao.getMaxId() == 2);
}
use of org.smartdata.model.ActionInfo 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();
}
}
}
Aggregations