use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class RulesTestTemplate method testRulesNoneModeEvents.
public static void testRulesNoneModeEvents(KnowledgeBaseType type) {
SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "rules_none_mode_events");
try {
CorrelationEventsLog eventsLog = engine.getOperations().getVariable(CorrelationEventsLog.class, CorrelationEventsLog.VARIABLE_NAME);
Map<String, String[][]> expected = new LinkedHashMap<>();
expected.put("RuleFNNF", new String[][] { { "1", null, null, "5" } });
expected.put("RuleFNNNL", new String[][] { { "1", null, null, null, "7" } });
expected.put("RuleFNNNLReject", new String[][] {});
expected.put("RuleFNFNL", new String[][] { { "1", null, "2", null, "7" } });
expected.forEach((rule, sequences) -> {
try {
await().atMost(180, TimeUnit.SECONDS).until(() -> eventsLog.getEvents(rule, "1").size() >= sequences.length);
} catch (Exception e) {
logger.error("Unsuccessful waiting for rule {} sequences {}", rule, (Object) sequences);
throw e;
}
});
expected.forEach((rule, sequences) -> TestUtils.assertEventSequences(eventsLog, rule, "1", sequences));
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class RulesTestTemplate method testRulesNoneModeEventsConditions.
public static void testRulesNoneModeEventsConditions(KnowledgeBaseType type) {
SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "rules_none_mode_events_conditions");
try {
CorrelationEventsLog eventsLog = engine.getOperations().getVariable(CorrelationEventsLog.class, CorrelationEventsLog.VARIABLE_NAME);
Map<String, String[][]> expected = new LinkedHashMap<>();
expected.put("RuleFNF", new String[][] { { "1", null, "5" } });
expected.put("RuleFNNFReject", new String[][] {});
expected.forEach((rule, sequences) -> {
try {
await().atMost(180, TimeUnit.SECONDS).until(() -> eventsLog.getEvents(rule, "1").size() >= sequences.length);
} catch (Exception e) {
logger.error("Unsuccessful waiting for rule {} sequences {}", rule, (Object) sequences);
throw e;
}
});
expected.forEach((rule, sequences) -> TestUtils.assertEventSequences(eventsLog, rule, "1", sequences));
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class RulesTestTemplate method testHeartbeat2.
public static void testHeartbeat2(KnowledgeBaseType type) {
SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "rules_heartbeat2");
try {
await().atMost(60, TimeUnit.SECONDS).until(() -> ((AtomicBoolean) engine.getOperations().getVariable("soundTheAlarm")).get());
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class TriggersTestTemplate method testTriggersEventPattern.
public static void testTriggersEventPattern(KnowledgeBaseType type) {
SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "triggers_event_pattern");
try {
await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countA").intValue() >= 2);
await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countAPattern").intValue() >= 5);
assertEquals(2, engine.getOperations().getVariable(Number.class, "countA").intValue());
assertEquals(5, engine.getOperations().getVariable(Number.class, "countAPattern").intValue());
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class TriggersTestTemplate method testHelloWorld.
public static void testHelloWorld(KnowledgeBaseType type) {
SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "hello_world");
try {
TimeUnit.SECONDS.sleep(1);
assertFalse(engine.isError());
} catch (InterruptedException e) {
throw new SpongeException(e);
} finally {
engine.shutdown();
}
}
Aggregations