Search in sources :

Example 76 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class FiltersTestTemplate method testFilter.

public static void testFilter(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "filters");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> TestUtils.getEventCounter(engine, "blue") >= 1);
        TimeUnit.SECONDS.sleep(1);
        assertEquals(0, TestUtils.getEventCounter(engine, "red"));
        assertFalse(engine.isError());
    } catch (InterruptedException e) {
        throw SpongeUtils.wrapException(e);
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 77 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class FiltersTestTemplate method testDeduplication.

public static void testDeduplication(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "filters_deduplication");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> TestUtils.getEventCounter(engine, "e1-red") >= 1 && TestUtils.getEventCounter(engine, "e1-blue") >= 1 && TestUtils.getEventCounter(engine, "e2-red") >= 2 && TestUtils.getEventCounter(engine, "e2-blue") >= 2);
        assertEquals(1, TestUtils.getEventCounter(engine, "e1-red"));
        assertEquals(1, TestUtils.getEventCounter(engine, "e1-blue"));
        assertEquals(2, TestUtils.getEventCounter(engine, "e2-red"));
        assertEquals(2, TestUtils.getEventCounter(engine, "e2-blue"));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 78 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class KnowledgeBaseTestTemplate method testLoad.

public static void testLoad(KnowledgeBaseType type) {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, ScriptTestUtils.getScriptKnowledgeBaseFileName(type, "knowledge_base_load")).build();
    engine.getConfigurationManager().setAutoEnable(false);
    engine.startup();
    try {
        await().atMost(60, TimeUnit.SECONDS).until(() -> TestUtils.getEventCounter(engine, "Trigger1, file3") >= 20);
        assertTrue(TestUtils.getEventCounter(engine, "Trigger1, file1") > 1);
        assertTrue(TestUtils.getEventCounter(engine, "Trigger2, file1") > 1);
        assertTrue(TestUtils.getEventCounter(engine, "Trigger1, file2") > 1);
        assertTrue(TestUtils.getEventCounter(engine, "Trigger2, file2") > 1);
        assertEquals(0, TestUtils.getEventCounter(engine, "Trigger3, file3"));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 79 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class KnowledgeBaseTestTemplate method testAutoEnable.

public static void testAutoEnable(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "knowledge_base_auto_enable");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "counter").intValue() >= 5);
        assertEquals(5, engine.getOperations().getVariable(Number.class, "counter").intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 80 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class KnowledgeBaseTestTemplate method testScriptOverriding.

public static void testScriptOverriding(KnowledgeBaseType type) {
    SpongeEngine engine = DefaultSpongeEngine.builder().config(ScriptTestUtils.getConfigFileName(type, "knowledge_base_script_overriding")).build();
    engine.getConfigurationManager().setAutoEnable(false);
    engine.startup();
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "receivedEventA2").intValue() == 2);
        assertEquals(0, engine.getOperations().getVariable(Number.class, "receivedEventA1").intValue());
        assertEquals(0, engine.getOperations().getVariable(Number.class, "functionA1").intValue());
        assertEquals(2, engine.getOperations().getVariable(Number.class, "functionA2").intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) 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