Search in sources :

Example 81 with SpongeEngine

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

the class KnowledgeBaseTestTemplate method testConcurrency.

public static void testConcurrency(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "knowledge_base_concurrency");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> "A1".equals(getConcurrencyTestValue(engine)));
        await().atMost(10, TimeUnit.SECONDS).until(() -> "B1".equals(getConcurrencyTestValue(engine)));
        await().atMost(10, TimeUnit.SECONDS).until(() -> "A2".equals(getConcurrencyTestValue(engine)));
        await().atMost(10, TimeUnit.SECONDS).until(() -> "B2".equals(getConcurrencyTestValue(engine)));
        await().atMost(10, TimeUnit.SECONDS).until(() -> "C1".equals(getConcurrencyTestValue(engine)));
        await().atMost(10, TimeUnit.SECONDS).until(() -> "C2".equals(getConcurrencyTestValue(engine)));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 82 with SpongeEngine

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

the class KnowledgeBaseTestTemplate method testLibrary.

@SuppressWarnings("unchecked")
public static void testLibrary(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "knowledge_base_library");
    try {
        await().pollDelay(5, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS).until(() -> ((Map<String, String>) engine.getOperations().getVariable("hostStatus")).size() >= 2);
        Map<String, String> hostStatus = (Map<String, String>) engine.getOperations().getVariable("hostStatus");
        assertEquals("ERROR", hostStatus.get("www.wikipedia.org.unknown"));
        assertTrue(Integer.decode(hostStatus.get("www.wikipedia.org").trim()).intValue() > 0);
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Map(java.util.Map)

Example 83 with SpongeEngine

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

the class PluginsTestTemplate method testKbPlugin.

public static void testKbPlugin(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "plugins_kb");
    try {
        await().pollDelay(1, TimeUnit.SECONDS).atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable("valueAfter") != null);
        assertEquals("Value A", engine.getOperations().getVariable("valueBefore"));
        assertEquals("Value B", engine.getOperations().getVariable("valueAfter"));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 84 with SpongeEngine

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

the class RulesTestTemplate method testHeartbeat.

public static void testHeartbeat(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "rules_heartbeat");
    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 85 with SpongeEngine

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

the class RulesTestTemplate method testRulesInstances.

public static void testRulesInstances(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.buildWithKnowledgeBase(type, "rules_instances");
    engine.getDefaultParameters().setAsyncEventSetProcessorProcessingPartitionSize(10);
    engine.startup();
    try {
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countA").intValue() >= engine.getOperations().getVariable(Number.class, "max").intValue() - 1);
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countB").intValue() >= engine.getOperations().getVariable(Number.class, "max").intValue() - 1);
        assertEquals(engine.getOperations().getVariable(Number.class, "max").intValue() - 1, engine.getOperations().getVariable(Number.class, "countA").intValue());
        assertEquals(engine.getOperations().getVariable(Number.class, "max").intValue() - 1, engine.getOperations().getVariable(Number.class, "countB").intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : 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