Search in sources :

Example 31 with SpongeEngine

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

the class TriggersTestTemplate method testTriggers.

public static void testTriggers(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "triggers");
    try {
        await().pollDelay(1, TimeUnit.SECONDS).atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedEventA").get());
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "receivedEventBCount").intValue() > 2);
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "receivedEventTestJavaCount").intValue() == 1);
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 32 with SpongeEngine

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

the class UnorderedRulesTestTemplate method testUnorderedRules.

@Test
public static void testUnorderedRules(KnowledgeBaseType type) {
    SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "unordered_rules");
    try {
        await().atMost(60, TimeUnit.SECONDS).pollDelay(5, TimeUnit.SECONDS).until(() -> ((Number) engine.getOperations().getVariable("hardwareFailureScriptCount")).intValue() >= 6);
        await().atMost(30, TimeUnit.SECONDS).until(() -> ((Number) engine.getOperations().getVariable("sameSourceFirstFireCount")).intValue() >= 5);
        await().atMost(30, TimeUnit.SECONDS).until(() -> ((Number) engine.getOperations().getVariable("hardwareFailureJavaCount")).intValue() >= 6);
        assertEquals(6, ((Number) engine.getOperations().getVariable("hardwareFailureScriptCount")).intValue());
        assertEquals(5, ((Number) engine.getOperations().getVariable("sameSourceFirstFireCount")).intValue());
        assertEquals(6, ((Number) engine.getOperations().getVariable("hardwareFailureJavaCount")).intValue());
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 33 with SpongeEngine

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

the class StandaloneTest method testCamelRssNews.

@Test
public void testCamelRssNews() throws InterruptedException {
    StandaloneEngineMain engineMain = null;
    try {
        engineMain = StandaloneTestUtils.startupStandaloneEngineMain("-c", "examples/standalone/camel_rss_news/config/config.xml");
        SpongeEngine engine = engineMain.getEngine();
        await().atMost(TIMEOUT, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable("stoppedSources", null) != null && engine.getOperations().getVariable(AtomicBoolean.class, "stoppedSources").get() && engine.getOperations().getVariable(AtomicBoolean.class, "alarmSounded").get());
        TimeUnit.SECONDS.sleep(SLEEP);
        assertFalse(engine.isError());
    } finally {
        StandaloneTestUtils.shutdownStandaloneEngineMain(engineMain);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StandaloneEngineMain(org.openksavi.sponge.standalone.StandaloneEngineMain) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 34 with SpongeEngine

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

the class StandaloneTest method testCamelTemplate.

@Test
public void testCamelTemplate() throws InterruptedException {
    StandaloneEngineMain engineMain = null;
    try {
        engineMain = StandaloneTestUtils.startupStandaloneEngineMain("-c", "examples/standalone/camel_template/config.xml");
        SpongeEngine engine = engineMain.getEngine();
        await().atMost(TIMEOUT, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable("alarmSounded", null) != null && engine.getOperations().getVariable(AtomicBoolean.class, "alarmSounded").get());
        TimeUnit.SECONDS.sleep(SLEEP);
        assertFalse(engine.isError());
    } finally {
        StandaloneTestUtils.shutdownStandaloneEngineMain(engineMain);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StandaloneEngineMain(org.openksavi.sponge.standalone.StandaloneEngineMain) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 35 with SpongeEngine

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

the class BaseScriptKnowledgeBaseInterpreter method load.

@Override
public final void load(String fileName, Charset charset, boolean required) {
    synchronized (interpteterSynchro) {
        invalidateCache();
        SpongeEngine engine = getEngineOperations().getEngine();
        try (Reader reader = engine.getKnowledgeBaseFileProvider().getReader(engine, fileName, charset)) {
            if (reader != null) {
                doLoad(reader, fileName);
            } else {
                if (required) {
                    throw new ConfigException("Knowledge base file " + fileName + " not found");
                } else {
                    logger.warn("Knowledge base file " + fileName + " not found but is set as optional.");
                }
            }
        } catch (IOException e) {
            throw SpongeUtils.wrapException("load", e);
        }
    }
}
Also used : Reader(java.io.Reader) ConfigException(org.openksavi.sponge.config.ConfigException) IOException(java.io.IOException) 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