Search in sources :

Example 51 with SpongeEngine

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

the class ConfigurationTest method testEngineParameters.

@Test
public void testEngineParameters() throws InterruptedException {
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/core/configuration/engine_parameters.xml").build();
    engine.startup();
    try {
        assertEquals("EngineParametersTest", engine.getName());
        assertEquals(21, engine.getConfigurationManager().getMainProcessingUnitThreadCount());
        assertEquals(engine.getConfigurationManager().getMainProcessingUnitThreadCount(), engine.getConfigurationManager().getAsyncEventSetProcessorExecutorThreadCount());
        assertEquals(EventClonePolicy.DEEP, engine.getConfigurationManager().getEventClonePolicy());
        assertEquals(false, engine.getConfigurationManager().getAutoEnable());
        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 52 with SpongeEngine

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

the class CoreCorrelatorsTest method testCorrelatorsEventPattern.

@Test
public void testCorrelatorsEventPattern() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/correlators_event_pattern.py").build();
    engine.startup();
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "nameCount").intValue() >= 3 && engine.getOperations().getVariable(Number.class, "patternCount").intValue() >= 7);
        assertEquals(3, engine.getOperations().getVariable(Number.class, "nameCount").intValue());
        assertEquals(7, engine.getOperations().getVariable(Number.class, "patternCount").intValue());
        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 53 with SpongeEngine

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

the class CoreFiltersTest method testFiltersEventPattern.

@Test
public void testFiltersEventPattern() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/filters_event_pattern.py").build();
    engine.startup();
    try {
        await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "nameCount").intValue() >= 2 && engine.getOperations().getVariable(Number.class, "patternCount").intValue() >= 3 && engine.getOperations().getVariable(Number.class, "acceptedCount").intValue() >= 5);
        assertEquals(2, engine.getOperations().getVariable(Number.class, "nameCount").intValue());
        assertEquals(3, engine.getOperations().getVariable(Number.class, "patternCount").intValue());
        assertEquals(5, engine.getOperations().getVariable(Number.class, "acceptedCount").intValue());
        assertEquals(0, engine.getOperations().getVariable(Number.class, "notAcceptedCount").intValue());
        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 54 with SpongeEngine

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

the class CoreRulesTest method testRulesImmediateNoDuration.

@Test
public void testRulesImmediateNoDuration() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/rules_immediate_no_duration.py").build();
    engine.getConfigurationManager().setAutoEnable(false);
    engine.startup();
    try {
        doTestRulesImmediate(engine, createCommonExpectedSequences());
        ScriptKnowledgeBaseInterpreter interpreter = SpongeUtils.getScriptInterpreter(engine, TestUtils.DEFAULT_KB);
        evalEnableRuleWithException(interpreter, "RuleFFL");
        evalEnableRuleWithException(interpreter, "RuleFFN");
        evalEnableRuleWithException(interpreter, "RuleFLL");
        evalEnableRuleWithException(interpreter, "RuleFLN");
        evalEnableRuleWithException(interpreter, "RuleFAL");
        evalEnableRuleWithException(interpreter, "RuleFNL");
        evalEnableRuleWithException(interpreter, "RuleFAN");
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : ScriptKnowledgeBaseInterpreter(org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 55 with SpongeEngine

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

the class CoreRulesTest method testRulesImmediateDuration.

@Test
public void testRulesImmediateDuration() {
    SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/rules_immediate_duration.py").build();
    engine.startup();
    try {
        Map<String, String[][]> expected = new LinkedHashMap<>(createCommonExpectedSequences());
        expected.put("RuleFFL", new String[][] { { "1", "2", "7" } });
        expected.put("RuleFFN", new String[][] { { "1", "2", null } });
        expected.put("RuleFLL", new String[][] { { "1", "5", "7" } });
        expected.put("RuleFLN", new String[][] { { "1", "5", null } });
        expected.put("RuleFAL", new String[][] { { "1", "2", "7" }, { "1", "3", "7" }, { "1", "5", "7" } });
        expected.put("RuleFNL", new String[][] { { "1", null, "7" } });
        expected.put("RuleFAN", new String[][] { { "1", "2", null }, { "1", "3", null }, { "1", "5", null } });
        doTestRulesImmediate(engine, expected);
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

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