Search in sources :

Example 26 with SpongeEngine

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();
    }
}
Also used : CorrelationEventsLog(org.openksavi.sponge.test.util.CorrelationEventsLog) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with SpongeEngine

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();
    }
}
Also used : CorrelationEventsLog(org.openksavi.sponge.test.util.CorrelationEventsLog) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with SpongeEngine

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();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 29 with SpongeEngine

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();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 30 with SpongeEngine

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();
    }
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Aggregations

SpongeEngine (org.openksavi.sponge.engine.SpongeEngine)91 DefaultSpongeEngine (org.openksavi.sponge.core.engine.DefaultSpongeEngine)55 Test (org.junit.Test)49 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 StandaloneEngineMain (org.openksavi.sponge.standalone.StandaloneEngineMain)6 SpringSpongeEngine (org.openksavi.sponge.spring.SpringSpongeEngine)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 CamelContext (org.apache.camel.CamelContext)4 SpongeException (org.openksavi.sponge.SpongeException)4 CorrelationEventsLog (org.openksavi.sponge.test.util.CorrelationEventsLog)4 LinkedHashMap (java.util.LinkedHashMap)3 ProducerTemplate (org.apache.camel.ProducerTemplate)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1