use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class SpringAutoStartupTest method testSpringAutoStartupTrue.
@Test
public void testSpringAutoStartupTrue() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfigAutoStartupTrue.class);
ctx.start();
try {
SpongeEngine engine = ctx.getBean(SpongeEngine.class);
assertTrue(engine.isRunning());
assertFalse(engine.isError());
} finally {
ctx.close();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class SpringTest method testSpring.
@Test
public void testSpring() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfig.class);
ctx.start();
try {
SpongeEngine engine = ctx.getBean(SpongeEngine.class);
await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(String.class, "springBeanValue") != null);
assertEquals(BEAN_VALUE, engine.getOperations().getVariable(String.class, "springBeanValue"));
assertFalse(engine.isError());
} finally {
ctx.close();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class MidiGenerateSoundMain method run.
public void run() {
SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/midi/midi_generate_sound.py").plugin(new MidiPlugin()).build();
engine.startup();
SpongeUtils.registerShutdownHook(engine);
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class UtilsTest method testCalculateInitialDynamicThreadPoolSize.
@Test
public void testCalculateInitialDynamicThreadPoolSize() {
SpongeEngine engine = DefaultSpongeEngine.builder().build();
engine.getDefaultParameters().setInitialDynamicThreadPoolSizeRatio(0.3);
Assert.assertEquals(3, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 10));
Assert.assertEquals(1, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 3));
Assert.assertEquals(2, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 5));
Assert.assertEquals(1, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 2));
Assert.assertEquals(1, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 1));
Assert.assertEquals(5, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 15));
Assert.assertEquals(6, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 20));
Assert.assertEquals(2, SpongeUtils.calculateInitialDynamicThreadPoolSize(engine, 8));
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class SimpleCamelNoSpringTest method testCamelProducer.
@Test
public void testCamelProducer() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer.py").build();
registry.put("spongeEngine", engine);
CamelContext camel = new DefaultCamelContext(registry);
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() {
// @formatter:off
from("direct:start").routeId("spongeProducer").to("sponge:spongeEngine");
// @formatter:on
}
});
camel.start();
try {
ProducerTemplate producerTemplate = camel.createProducerTemplate();
producerTemplate.sendBody("direct:start", "Send me to the Sponge");
await().atMost(10, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());
} finally {
camel.stop();
}
}
Aggregations