Search in sources :

Example 61 with SpongeEngine

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

the class KnowledgeBaseOnRunTest method testOnRunReturnsTrue.

@Test
public void testOnRunReturnsTrue() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/knowledge_base_on_run_returns_true.py").build();
    engine.startup();
    try {
        await().atMost(20, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "trigger").get());
        assertTrue(engine.getOperations().getVariable(AtomicBoolean.class, "onRun").get());
        assertFalse(engine.isError());
        assertTrue(engine.isRunning());
        assertFalse(engine.isTerminated());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 62 with SpongeEngine

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

the class KnowledgeBaseOnRunTest method testOnRunNotPresent.

@Test
public void testOnRunNotPresent() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/knowledge_base_on_run_not_present.py").build();
    engine.startup();
    try {
        await().atMost(20, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "trigger").get());
        assertFalse(engine.isError());
        assertTrue(engine.isRunning());
        assertFalse(engine.isTerminated());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 63 with SpongeEngine

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

the class SyncAsyncEventSetProcessorsTest method testAsyncEventSetProcessors.

@Test
public void testAsyncEventSetProcessors() throws InterruptedException {
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/core/sync_async_event_set_processors.xml").build();
    engine.startup();
    assertTrue(engine.getConfigurationManager().getEventSetProcessorDefaultSynchronous());
    doTestAsyncEventSetProcessors(engine);
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 64 with SpongeEngine

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

the class SystemEventsTest method testSystemEvents.

@Test
public void testSystemEvents() {
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/core/system_events.xml").build();
    engine.startup();
    try {
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "countA").intValue() >= 5 && engine.getOperations().getVariable(Number.class, "countB").intValue() >= 1 && engine.getOperations().getVariable(List.class, "listC").size() >= 7);
        assertEquals(5, engine.getOperations().getVariable(Number.class, "countA").intValue());
        assertEquals(1, engine.getOperations().getVariable(Number.class, "countB").intValue());
        assertEquals(Lists.newArrayList("startup", "x", "e", "e", "e", "e", "e"), engine.getOperations().getVariable(List.class, "listC"));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : List(java.util.List) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 65 with SpongeEngine

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