Search in sources :

Example 71 with SpongeEngine

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

the class MidiPlayFileMain method run.

public void run() {
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/midi/midi_play_file.xml").build();
    engine.startup();
    SpongeUtils.registerShutdownHook(engine);
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 72 with SpongeEngine

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

the class CorrelatorsTestTemplate method testCorrelators.

public static void testCorrelators(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "correlators");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "hardwareFailureScriptFinishCount").intValue() >= 1 && engine.getOperations().getVariable(Number.class, "hardwareFailureJavaFinishCount").intValue() >= 1);
        assertEquals(4, engine.getOperations().getVariable(Number.class, "hardwareFailureScriptCount").intValue());
        assertEquals(4, engine.getOperations().getVariable(Number.class, "hardwareFailureJavaCount").intValue());
        assertEquals(1, engine.getOperations().getVariable(Number.class, "hardwareFailureScriptFinishCount").intValue());
        assertEquals(1, engine.getOperations().getVariable(Number.class, "hardwareFailureJavaFinishCount").intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 73 with SpongeEngine

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

the class CorrelatorsTestTemplate method testCorrelatorsDuration.

public static void testCorrelatorsDuration(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "correlators_duration");
    try {
        await().pollDelay(5, TimeUnit.SECONDS).atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "hardwareFailureScriptCount").intValue() >= 3);
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 74 with SpongeEngine

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

the class EventsTestTemplate method testCron.

public static void testCron(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "events_cron");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "eventCounter").intValue() >= 2);
        TimeUnit.SECONDS.sleep(5);
        assertEquals(2, engine.getOperations().getVariable(Number.class, "eventCounter").intValue());
        assertFalse(engine.isError());
    } catch (InterruptedException ie) {
        throw new SpongeException(ie);
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 75 with SpongeEngine

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

the class EventsTestTemplate method testClonePolicy.

public static void testClonePolicy(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "events_clone_policy");
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> TestUtils.getEvents(engine, "defaultClonePolicy").size() >= 3 && TestUtils.getEvents(engine, "deepClonePolicy").size() >= 3 && TestUtils.getEvents(engine, "shallowClonePolicy").size() >= 3);
        // Default clone policy is set to DEEP in the configuration xml.
        List<Event> defaultClonePolicyEvents = TestUtils.getEvents(engine, "defaultClonePolicy");
        assertEquals("Value 1", getValue(defaultClonePolicyEvents, 0));
        assertEquals("Value 2", getValue(defaultClonePolicyEvents, 1));
        assertEquals("Value 3", getValue(defaultClonePolicyEvents, 2));
        List<Event> deepClonePolicyEvents = TestUtils.getEvents(engine, "deepClonePolicy");
        assertEquals("Value 1", getValue(deepClonePolicyEvents, 0));
        assertEquals("Value 2", getValue(deepClonePolicyEvents, 1));
        assertEquals("Value 3", getValue(deepClonePolicyEvents, 2));
        List<Event> shallowClonePolicyEvents = TestUtils.getEvents(engine, "shallowClonePolicy");
        assertEquals("Value " + defaultClonePolicyEvents.size(), getValue(shallowClonePolicyEvents, 0));
        assertEquals("Value " + defaultClonePolicyEvents.size(), getValue(shallowClonePolicyEvents, 1));
        assertEquals("Value " + defaultClonePolicyEvents.size(), getValue(shallowClonePolicyEvents, 2));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : Event(org.openksavi.sponge.event.Event) 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