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();
}
}
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();
}
}
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);
}
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();
}
}
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();
}
}
Aggregations