Search in sources :

Example 36 with SpongeEngine

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

the class Py4JTest method testPy4JPythonServer.

@Test
public void testPy4JPythonServer() throws Exception {
    String rootDir = "examples/py4j/python_server";
    SpongeEngine engine = DefaultSpongeEngine.builder().config(rootDir + "/py4j_python_server_sponge_hello_world.xml").build();
    engine.startup();
    Process process = null;
    try {
        Pair<Process, String> scriptResult = startCPython(engine, rootDir + "/py4j_python_server_python_hello_world.py", false);
        process = scriptResult.getLeft();
        // Wait for the Python process to start.
        TimeUnit.SECONDS.sleep(2);
        assertEquals("TEST", engine.getOperations().call("PythonUpperCase", "test"));
        assertFalse(engine.isError());
    } finally {
        if (process != null) {
            process.destroy();
        }
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 37 with SpongeEngine

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

the class Py4JTest method testPy4JJavaServer.

@Test
public void testPy4JJavaServer() throws Exception {
    String rootDir = "examples/py4j/java_server";
    SpongeEngine engine = DefaultSpongeEngine.builder().config(rootDir + "/py4j_java_server_sponge_hello_world.xml").build();
    engine.startup();
    try {
        Pair<Process, String> scriptResult = startCPython(engine, rootDir + "/py4j_java_server_python_hello_world.py", true);
        Process process = scriptResult.getLeft();
        String outputText = scriptResult.getRight();
        process.waitFor(60, TimeUnit.SECONDS);
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "eventCounter").intValue() > 0);
        assertEquals(String.format("Connected to %s\nTriggers count: %d, first: %s", engine.getDescription(), engine.getTriggers().size(), engine.getTriggers().get(0).getName()), outputText);
        assertEquals(1, engine.getOperations().getVariable(Number.class, "eventCounter").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 38 with SpongeEngine

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

the class ReactiveXTest method testReactiveX.

@Test
public void testReactiveX() throws Exception {
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/reactivex/reactivex.xml").knowledgeBase(new ReactiveXTestKnowledgeBase()).build();
    engine.startup();
    await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "eventCounter").intValue() >= 3);
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 39 with SpongeEngine

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

the class GrovePiBlinkLedMain method run.

public void run() {
    LoggingUtils.initLoggingBridge();
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/rpi-grovepi/grovepi_led_blink.xml").build();
    engine.startup();
    SpongeUtils.registerShutdownHook(engine);
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 40 with SpongeEngine

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

the class SpringAutoStartupTest method testSpringAutoStartupFalse.

@Test
public void testSpringAutoStartupFalse() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfigAutoStartupFalse.class);
    ctx.start();
    try {
        SpongeEngine engine = ctx.getBean(SpongeEngine.class);
        assertFalse(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)

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