Search in sources :

Example 6 with SpongeEngine

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

the class EventOverloadTest method testEventOverload.

@Test
public void testEventOverload() {
    EngineBuilder<DefaultSpongeEngine> builder = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/event_overload.py");
    builder.getEngineDefaultParameters().setMainEventQueueCapacity(2);
    builder.getEngineDefaultParameters().setDecomposedQueueCapacity(2);
    SpongeEngine engine = builder.build();
    // Caution: this test depends on the exact configuration values as they are specified below.
    engine.getConfigurationManager().setMainProcessingUnitThreadCount(1);
    engine.getConfigurationManager().setEventQueueCapacity(5);
    // engine.getConfigurationManager().setEventSetProcessorDefaultSynchronous(false);
    engine.startup();
    try {
        await().atMost(120, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable("testStatus") != null);
        assertTrue(engine.getOperations().getVariable("testStatus") instanceof QueueFullException);
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) QueueFullException(org.openksavi.sponge.engine.QueueFullException) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 7 with SpongeEngine

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

the class KnowledgeBaseOnRunTest method testOnRunReturnsFalse.

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

Example 8 with SpongeEngine

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

the class ProcessingEventsSynchronizationTest method testProcessingEventsSynchronizationDecomposedQueue.

@Test
public void testProcessingEventsSynchronizationDecomposedQueue() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/processing_events_sync.py").build();
    doTestProcessingEventsSynchronization(engine);
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 9 with SpongeEngine

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

the class ReloadDurationTest method testReloadDuration.

@Test
public void testReloadDuration() throws InterruptedException {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/reload_duration.py").build();
    engine.startup();
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "endTest").get());
        assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "ruleAFired").get());
        assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "ruleBFired").get());
        assertTrue(engine.getOperations().getVariable(AtomicBoolean.class, "ruleCFired").get());
        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 10 with SpongeEngine

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

the class ShutdownTest method testShutdown.

private void testShutdown(int sizes) {
    EngineBuilder<DefaultSpongeEngine> builder = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/shutdown.py");
    // Caution: this test depends on the exact configuration values as they are specified below.
    builder.getEngineDefaultParameters().setEventQueueCapacity(1000);
    builder.getEngineDefaultParameters().setExecutorShutdownTimeout(60000);
    int eventsToBeProcessed = 0;
    // One event waits in the FilerProcessingUnit for putting into the Main Event Queue.
    eventsToBeProcessed++;
    // Some events wait in the Main Event Queue.
    builder.getEngineDefaultParameters().setMainEventQueueCapacity(sizes);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getMainEventQueueCapacity();
    // One event waits in the Main Processing Unit for putting into the Decomposed Queue.
    eventsToBeProcessed++;
    // Some events wait in the Decomposed Queue.
    builder.getEngineDefaultParameters().setDecomposedQueueCapacity(sizes);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getDecomposedQueueCapacity();
    // One event waits in the DecomposedQueueReaderWorker for putting into the WorkerThreadPool executor queue.
    eventsToBeProcessed++;
    // Some events wait in the the WorkerThreadPool executor queue.
    builder.getEngineDefaultParameters().setMainProcessingUnitWorkerExecutorQueueSize(sizes);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getMainProcessingUnitWorkerExecutorQueueSize();
    // Some events are being processed in the WorkerThreadPool. Note that for this test assertions there should be only one thread here.
    builder.getEngineDefaultParameters().setMainProcessingUnitThreadCount(1);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getMainProcessingUnitThreadCount();
    SpongeEngine engine = builder.build();
    engine.startup();
    try {
        TimeUnit.SECONDS.sleep(2);
        engine.shutdown();
        final int finalEventsToBeProcessed = eventsToBeProcessed;
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "finishedEvents").intValue() >= finalEventsToBeProcessed);
        assertEquals(eventsToBeProcessed, engine.getOperations().getVariable(Number.class, "finishedEvents").intValue());
        assertEquals(engine.getOperations().getVariable(Number.class, "sentEvents").intValue() - finalEventsToBeProcessed, engine.getEventQueueManager().getInputEventQueue().getSize());
        assertEquals(0, engine.getEventQueueManager().getMainEventQueue().getSize());
        DecomposedQueueMainProcessingUnit mainProcessingUnit = (DecomposedQueueMainProcessingUnit) engine.getProcessingUnitManager().getMainProcessingUnit();
        assertEquals(0, mainProcessingUnit.getDecomposedQueue().getSize());
        assertFalse(engine.isError());
    } catch (InterruptedException e) {
        fail(e.toString());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) DecomposedQueueMainProcessingUnit(org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit) 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