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