Search in sources :

Example 41 with SpongeEngine

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();
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringSpongeEngine(org.openksavi.sponge.spring.SpringSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 42 with SpongeEngine

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();
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringSpongeEngine(org.openksavi.sponge.spring.SpringSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 43 with SpongeEngine

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);
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 44 with SpongeEngine

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));
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 45 with SpongeEngine

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();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) 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