Search in sources :

Example 1 with DefaultSpongeEngine

use of org.openksavi.sponge.core.engine.DefaultSpongeEngine 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 2 with DefaultSpongeEngine

use of org.openksavi.sponge.core.engine.DefaultSpongeEngine 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)

Example 3 with DefaultSpongeEngine

use of org.openksavi.sponge.core.engine.DefaultSpongeEngine in project sponge by softelnet.

the class PriorityEventQueueTest method beforeTest.

@Before
public void beforeTest() {
    engine = new DefaultSpongeEngine();
    engine.init();
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) Before(org.junit.Before)

Aggregations

DefaultSpongeEngine (org.openksavi.sponge.core.engine.DefaultSpongeEngine)3 SpongeEngine (org.openksavi.sponge.engine.SpongeEngine)2 Before (org.junit.Before)1 Test (org.junit.Test)1 DecomposedQueueMainProcessingUnit (org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit)1 QueueFullException (org.openksavi.sponge.engine.QueueFullException)1