Search in sources :

Example 56 with SpongeEngine

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

the class CoreUnorderedRulesTest method testUnorderedRulesEvents.

@Test
public void testUnorderedRulesEvents() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/unordered_rules_events.py").build();
    engine.startup();
    try {
        doTestUnorderedRulesEvents(engine, 180);
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 57 with SpongeEngine

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

the class CoreUnorderedRulesTest method testUnorderedRulesInstances.

@Test
public void testUnorderedRulesInstances() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/unordered_rules_instances.py").build();
    engine.startup();
    try {
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countAB").intValue() >= engine.getOperations().getVariable(Number.class, "max").intValue() * 2 - 1);
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countA").intValue() >= engine.getOperations().getVariable(Number.class, "max").intValue() - 1);
        assertEquals(engine.getOperations().getVariable(Number.class, "max").intValue() * 2 - 1, engine.getOperations().getVariable(Number.class, "countAB").intValue());
        assertEquals(engine.getOperations().getVariable(Number.class, "max").intValue() - 1, engine.getOperations().getVariable(Number.class, "countA").intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 58 with SpongeEngine

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

the class EngineBuilderTest method createAndStartupEngine.

private SpongeEngine createAndStartupEngine() {
    EchoPlugin plugin = new EchoPlugin();
    plugin.setName("testPlugin");
    plugin.setEcho("Echo text!");
    // @formatter:off
    SpongeEngine engine = DefaultSpongeEngine.builder().systemProperty("system.property", "1").property("test.property", "TEST").plugin(plugin).knowledgeBase(new TestKnowledgeBase("testJavaKb")).build();
    // @formatter:on
    engine.getConfigurationManager().setMainProcessingUnitThreadCount(2);
    engine.getConfigurationManager().setEventClonePolicy(EventClonePolicy.DEEP);
    engine.startup();
    return engine;
}
Also used : EchoPlugin(org.openksavi.sponge.examples.EchoPlugin) TestKnowledgeBase(org.openksavi.sponge.examples.TestKnowledgeBase) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 59 with SpongeEngine

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

the class EventPatternTest method testEventPattern.

@Test
public void testEventPattern() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/event_pattern.py").build();
    engine.startup();
    try {
        await().pollDelay(5, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "count").intValue() >= 6);
        assertEquals(6, engine.getOperations().getVariable(Number.class, "count").intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 60 with SpongeEngine

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

the class FibonacciTest method testFibonacci.

@Test
public void testFibonacci() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/fibonacci.py").build();
    engine.startup();
    try {
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable("f(maxIndex)") != null);
        Number fmax = engine.getOperations().getVariable(Number.class, "f(maxIndex)");
        assertEquals(new BigInteger("354224848179261915075"), fmax);
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : BigInteger(java.math.BigInteger) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

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