use of org.openksavi.sponge.test.util.CorrelationEventsLog in project sponge by softelnet.
the class SyncAsyncEventSetProcessorsTest method doTestAsyncEventSetProcessors.
private void doTestAsyncEventSetProcessors(SpongeEngine engine) throws InterruptedException {
try {
CorrelationEventsLog eventsLog = engine.getOperations().getVariable(CorrelationEventsLog.class, CorrelationEventsLog.VARIABLE_NAME);
await().pollDelay(1, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS).until(() -> eventsLog.getEvents("RuleFFF", "1").size() >= 1 && eventsLog.getEvents("RuleFFL", "1").size() >= 1);
TestUtils.assertEventSequences(eventsLog, "RuleFFF", "1", new String[][] { { "1", "2", "5" } });
TestUtils.assertEventSequences(eventsLog, "RuleFFL", "1", new String[][] { { "1", "2", "7" } });
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.test.util.CorrelationEventsLog in project sponge by softelnet.
the class LoadTest method testRulesLoad.
@Test
public void testRulesLoad() {
SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/performance/rules_load.py").build();
engine.startup();
CorrelationEventsLog eventsLog = engine.getOperations().getVariable(CorrelationEventsLog.class, CorrelationEventsLog.VARIABLE_NAME);
try {
int maxIterations = 50;
for (int i = 0; i < maxIterations; i++) {
logger.info("Iteration {}", i + 1);
eventsLog.clear();
engine.getOperations().event("sendEvents").send();
RulesTestTemplate.doTestRulesEvents(PythonConstants.TYPE, engine, 3600);
}
logger.info("Event performance is: {}", String.format("%.2f events/s", engine.getStatisticsManager().getEventPerformance()));
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.test.util.CorrelationEventsLog in project sponge by softelnet.
the class RulesTestTemplate method doTestRulesEvents.
public static void doTestRulesEvents(KnowledgeBaseType type, SpongeEngine engine, long timeout) {
CorrelationEventsLog eventsLog = engine.getOperations().getVariable(CorrelationEventsLog.class, CorrelationEventsLog.VARIABLE_NAME);
Map<String, String[][]> expected = new LinkedHashMap<>();
expected.put("RuleF", new String[][] { { "1" } });
expected.put("RuleFFF", new String[][] { { "1", "2", "5" } });
expected.put("RuleFFFDuration", new String[][] { { "1", "2", "5" } });
expected.put("RuleFFL", new String[][] { { "1", "2", "7" } });
expected.put("RuleFFA", new String[][] { { "1", "2", "5" }, { "1", "2", "6" }, { "1", "2", "7" } });
expected.put("RuleFFN", new String[][] { { "1", "2", null } });
expected.put("RuleFLF", new String[][] { { "1", "4", "5" } });
expected.put("RuleFLL", new String[][] { { "1", "4", "7" } });
expected.put("RuleFLA", new String[][] { { "1", "4", "5" }, { "1", "4", "6" }, { "1", "4", "7" } });
expected.put("RuleFLN", new String[][] { { "1", "4", null } });
expected.put("RuleFAF", new String[][] { { "1", "2", "5" }, { "1", "3", "5" }, { "1", "4", "5" } });
expected.put("RuleFAL", new String[][] { { "1", "2", "7" }, { "1", "3", "7" }, { "1", "4", "7" } });
// @formatter:off
expected.put("RuleFAA", new String[][] { { "1", "2", "5" }, { "1", "3", "5" }, { "1", "4", "5" }, { "1", "2", "6" }, { "1", "3", "6" }, { "1", "4", "6" }, { "1", "2", "7" }, { "1", "3", "7" }, { "1", "4", "7" } });
// @formatter:on
expected.put("RuleFNF", new String[][] { { "1", null, "5" } });
expected.put("RuleFNFReject", new String[][] {});
expected.put("RuleFNL", new String[][] { { "1", null, "7" } });
expected.put("RuleFNA", new String[][] { { "1", null, "5" }, { "1", null, "6" }, { "1", null, "7" } });
expected.put("RuleFAN", new String[][] { { "1", "2", null }, { "1", "3", null }, { "1", "4", null } });
try {
TimeUnit.SECONDS.sleep(20);
} catch (InterruptedException e) {
throw SpongeUtils.wrapException(e);
}
expected.forEach((rule, sequences) -> {
try {
await().atMost(timeout, 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());
}
use of org.openksavi.sponge.test.util.CorrelationEventsLog in project sponge by softelnet.
the class RulesTestTemplate method testRulesSyncAsync.
public static void testRulesSyncAsync(KnowledgeBaseType type, SpongeEngine engine) {
try {
CorrelationEventsLog eventsLog = engine.getOperations().getVariable(CorrelationEventsLog.class, CorrelationEventsLog.VARIABLE_NAME);
Map<String, String[][]> expected = new LinkedHashMap<>();
expected.put("RuleFFF", new String[][] { { "1", "2", "5" } });
expected.put("RuleFFL", new String[][] { { "1", "2", "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();
}
}
Aggregations