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