Search in sources :

Example 31 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class PublishSubscribeTest method testPublishStringToSPL.

// Test a exported String Java stream can be subscribed to by a SPL stream.
@Test
public void testPublishStringToSPL() throws Exception {
    TStream<String> source = source();
    // Check autonomous works in that it produces working SPL code.
    source = source.autonomous();
    assertEquals(String.class, source.getTupleClass());
    assertEquals(String.class, source.getTupleType());
    source.publish("testPublishStringSPL");
    SPLStream subscribe = SPLStreams.subscribe(source.topology(), "testPublishStringSPL", SPLSchemas.STRING);
    checkSubscribedAsStrings(subscribe.toStringStream());
}
Also used : SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 32 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class PublishSubscribeUDPTest method testPublishUDPSubscribeUDP.

private void testPublishUDPSubscribeUDP(int pwidth, int swidth) throws Exception {
    String topic = "testPublishUDPSubscribeUDP/" + pwidth;
    String[] data = new String[100];
    for (int i = 0; i < data.length; i++) {
        data[i] = "SubUDP" + i;
    }
    final Topology t = new Topology();
    SPL.addToolkit(t, new File(getTestRoot(), "spl/testtk"));
    TStream<String> source = t.strings(data);
    if (pwidth > 0)
        source = source.parallel(pwidth);
    source = addStartupDelay(source);
    source.publish(topic);
    Map<String, Object> params = new HashMap<>();
    params.put("width", swidth);
    params.put("topic", topic);
    SPLStream subscribe = SPL.invokeSource(t, "testspl::UDPStringSub", params, Schemas.STRING);
    completeAndValidateUnordered(subscribe.toStringStream(), 30, data);
}
Also used : HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) File(java.io.File) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Example 33 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class PythonFunctionalOperatorsTest method testPositionalSampleNoop.

@Test
public void testPositionalSampleNoop() throws Exception {
    Topology topology = new Topology("testPositionalSampleNoop");
    addTestToolkit(topology);
    SPLStream tuples = testTupleStream(topology);
    SPLStream viaSPL = SPL.invokeOperator("spl.relational::Functor", tuples, tuples.getSchema(), null);
    SPLStream viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.positional::Noop", tuples, tuples.getSchema(), null);
    // Only supported for Python 3.5 and Streams 4.2 and later
    if ((getVersion().getVersion() > 4) || (getVersion().getVersion() == 4 && getVersion().getRelease() >= 2)) {
        viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pytest.pyec::TestOperatorContext", viaPython, viaPython.getSchema(), null);
        viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pytest.pyec::PyTestMetrics", viaPython, viaPython.getSchema(), null);
    }
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(viaPython, TUPLE_COUNT);
    Condition<List<Tuple>> viaSPLResult = tester.tupleContents(viaSPL);
    Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPython);
    complete(tester, expectedCount, 60, TimeUnit.SECONDS);
    assertTrue(expectedCount.getResult().toString(), expectedCount.valid());
    assertEquals(viaSPLResult.getResult(), viaPythonResult.getResult());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 34 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class PythonFunctionalOperatorsTest method testPositionalSampleSimpleFilter.

@Test
public void testPositionalSampleSimpleFilter() throws Exception {
    Topology topology = new Topology("testPositionalSampleSimpleFilter");
    SPLStream tuples = sampleFilterStream(topology);
    addTestToolkit(tuples);
    SPLStream viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.positional::SimpleFilter", tuples, tuples.getSchema(), null);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(viaPython, 2);
    // first attribute is the sum of the first and second input attributes
    // others are copied across from in to out.
    Tuple r1 = TEST_SCHEMA_SF.getTuple(new Object[] { 32, (short) 25, 34535L });
    Tuple r2 = TEST_SCHEMA_SF.getTuple(new Object[] { 5, (short) 3, 654932L });
    Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPython, r1, r2);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
    assertTrue(viaPythonResult.toString(), viaPythonResult.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple) Test(org.junit.Test)

Example 35 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.health by IBMStreams.

the class OruR01Ingest method run.

@Override
public void run() {
    Topology topology = new Topology("OruR01Ingest");
    ObxToSplMapper mapper = new ObxToSplMapper();
    addDependencies(topology);
    TStream<Message> messages = topology.endlessSource(new HapiMessageSupplier(getPort()));
    // transform message to Observation object
    TStream<Observation> observationStream = messages.multiTransform(message -> {
        return mapper.messageToModel(message);
    });
    StreamSchema schema = Type.Factory.getStreamSchema(Observation.OBSERVATION_SCHEMA_SPL);
    @SuppressWarnings("serial") SPLStream splObservations = SPLStreams.convertStream(observationStream, new BiFunction<Observation, OutputTuple, OutputTuple>() {

        @Override
        public OutputTuple apply(Observation observation, OutputTuple outTuple) {
            return mapper.modelToSpl(observation, outTuple);
        }
    }, schema);
    splObservations.print();
    splObservations.publish(getTopic());
    try {
        StreamsContextFactory.getStreamsContext(StreamsContext.Type.DISTRIBUTED).submit(topology);
    } catch (Exception e) {
        TRACE.error("Unable to submit topology", e);
    }
}
Also used : Message(ca.uhn.hl7v2.model.Message) Topology(com.ibm.streamsx.topology.Topology) HapiMessageSupplier(com.ibm.streamsx.health.hapi.internal.HapiMessageSupplier) StreamSchema(com.ibm.streams.operator.StreamSchema) OutputTuple(com.ibm.streams.operator.OutputTuple) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) ObxToSplMapper(com.ibm.streamsx.health.hapi.mapper.ObxToSplMapper) Observation(com.ibm.streamsx.health.hapi.model.Observation)

Aggregations

SPLStream (com.ibm.streamsx.topology.spl.SPLStream)57 Topology (com.ibm.streamsx.topology.Topology)39 TestTopology (com.ibm.streamsx.topology.test.TestTopology)36 Test (org.junit.Test)32 Tester (com.ibm.streamsx.topology.tester.Tester)20 List (java.util.List)17 Tuple (com.ibm.streams.operator.Tuple)15 HashMap (java.util.HashMap)15 OutputTuple (com.ibm.streams.operator.OutputTuple)10 File (java.io.File)10 JSONObject (com.ibm.json.java.JSONObject)9 StreamSchema (com.ibm.streams.operator.StreamSchema)9 Message (com.ibm.streamsx.topology.tuple.Message)4 LinkedList (java.util.LinkedList)4 Random (java.util.Random)4 TSink (com.ibm.streamsx.topology.TSink)3 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)3 ArrayList (java.util.ArrayList)3 SPLStreamsTest (com.ibm.streamsx.topology.test.spl.SPLStreamsTest)2 Map (java.util.Map)2