use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class PythonFunctionalOperatorsTest method testSourceWithClass.
@Test
public void testSourceWithClass() throws Exception {
Topology topology = new Topology("testSourceWithClass");
addTestToolkit(topology);
StreamSchema outSchema = Type.Factory.getStreamSchema("tuple<int32 seq>");
int count = new Random().nextInt(200) + 10;
SPLStream pysrc = SPL.invokeSource(topology, "com.ibm.streamsx.topology.pysamples.sources::Range", Collections.singletonMap("count", count), outSchema);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(pysrc, count);
Condition<List<Tuple>> outTuples = tester.tupleContents(pysrc);
// getConfig().put(ContextProperties.TRACING_LEVEL, TraceLevel.DEBUG);
complete(tester, expectedCount, 20, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
List<Tuple> result = outTuples.getResult();
assertEquals(count, result.size());
for (int i = 0; i < count; i++) assertEquals(i, result.get(i).getInt("seq"));
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class SPLStreamsTest method testConversionFromSPL.
@Test
public void testConversionFromSPL() throws Exception {
final Topology topology = new Topology("ConvertSPLStream");
SPLStream splStream = createSPLFlowFromStream(topology, false);
TStream<IntAndString> iands = createStreamFromSPLStream(splStream);
assertEquals(IntAndString.class, iands.getTupleClass());
completeAndValidate(iands, 10, "n:465 s:325", "n:597 s:457", "n:9465 s:9325");
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class SimpleStandaloneTest method testTwoStreams.
@Test
public void testTwoStreams() throws Exception {
Topology topology = new Topology("testTwoStreams");
TStream<String> hw = topology.strings("Hello", "World!", "Test!!");
SPLStream hws = SPLStreams.stringToSPLStream(hw);
TStream<String> hw2 = StringStreams.contains(hw, "e");
SPLStream hw2s = SPLStreams.stringToSPLStream(hw2);
Tester tester = topology.getTester();
StreamCounter<Tuple> counter = tester.splHandler(hws, new StreamCounter<Tuple>());
StreamCollector<LinkedList<Tuple>, Tuple> collector = tester.splHandler(hws, StreamCollector.newLinkedListCollector());
StreamCounter<Tuple> counter2 = tester.splHandler(hw2s, new StreamCounter<Tuple>());
StreamCollector<LinkedList<Tuple>, Tuple> collector2 = tester.splHandler(hw2s, StreamCollector.newLinkedListCollector());
StreamsContextFactory.getStreamsContext(StreamsContext.Type.STANDALONE_TESTER).submit(topology).get();
assertEquals(3, counter.getTupleCount());
assertEquals("Hello", collector.getTuples().get(0).getString(0));
assertEquals("World!", collector.getTuples().get(1).getString(0));
assertEquals("Test!!", collector.getTuples().get(2).getString(0));
assertEquals(2, counter2.getTupleCount());
assertEquals("Hello", collector2.getTuples().get(0).getString(0));
assertEquals("Test!!", collector2.getTuples().get(1).getString(0));
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.health by IBMStreams.
the class JsonPublisher method publish.
public static void publish(TStream<String> jsonInputStream, String topic) {
SPLStream splStream = SPLStreams.convertStream(jsonInputStream, new JsonToSpl(), JSONSchemas.JSON);
splStream.publish(topic);
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class FileStreams method textFileReader.
/**
* Returns a Stream that reads each file named on its input stream,
* outputting a tuple for each line read. All files are assumed to be
* encoded using UTF-8. The lines are output in the order they appear in
* each file, with the first line of a file appearing first.
*
* @param input
* Stream containing files to read.
* @return Stream contains lines from input files.
*/
public static TStream<String> textFileReader(TStream<String> input) {
SPLStream tupleInput = SPLStreams.stringToSPLStream(input);
SPLStream lines = JavaPrimitive.invokeJavaPrimitive(TextFileReader.class, tupleInput, Schemas.STRING, null);
return lines.toStringStream();
}
Aggregations