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.topology by IBMStreams.
the class ParallelTest method testParallelSubmissionParamInner.
@Test
public void testParallelSubmissionParamInner() throws Exception {
checkUdpSupported();
Topology topology = newTopology("testParallelSubmissionParamInner");
final int count = new Random().nextInt(1000) + 37;
String submissionWidthName = "width";
Integer submissionWidth = 5;
String submissionAppendName = "append";
boolean submissionAppend = true;
String submissionFlushName = "flush";
Integer submissionFlush = 1;
String submissionThresholdName = "threshold";
String submissionDefaultedThresholdName = "defaultedTreshold";
Integer submissionThreshold = -1;
// getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
Supplier<Integer> threshold = topology.createSubmissionParameter(submissionThresholdName, Integer.class);
Supplier<Integer> defaultedThreshold = topology.createSubmissionParameter(submissionDefaultedThresholdName, submissionThreshold);
TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
TStream<BeaconTuple> pb = fb.parallel(topology.createSubmissionParameter(submissionWidthName, Integer.class));
TStream<Integer> is = pb.transform(randomHashProducer());
// submission param use within a parallel region
StreamSchema schema = getStreamSchema("tuple<int32 i>");
SPLStream splStream = SPLStreams.convertStream(is, cvtMsgFunc(), schema);
File tmpFile = File.createTempFile("parallelTest", null);
tmpFile.deleteOnExit();
Map<String, Object> splParams = new HashMap<>();
splParams.put("file", tmpFile.getAbsolutePath());
splParams.put("append", topology.createSubmissionParameter(submissionAppendName, submissionAppend));
splParams.put("flush", SPL.createSubmissionParameter(topology, submissionFlushName, SPL.createValue(0, Type.MetaType.UINT32), false));
SPL.invokeSink("spl.adapter::FileSink", splStream, splParams);
// use a submission parameter in "inner" functional logic
is = is.filter(thresholdFilter(threshold));
is = is.filter(thresholdFilter(defaultedThreshold));
// avoid another parallel impl limitation noted in issue#173
is = is.filter(passthru());
TStream<Integer> joined = is.endParallel();
TStream<String> numRegions = joined.transform(uniqueIdentifierMap(count));
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(numRegions, 1);
Condition<List<String>> regionCount = tester.stringContents(numRegions, submissionWidth.toString());
Map<String, Object> params = new HashMap<>();
params.put(submissionWidthName, submissionWidth);
params.put(submissionFlushName, submissionFlush);
params.put(submissionThresholdName, submissionThreshold);
getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
complete(tester, allConditions(expectedCount, regionCount), 10, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(regionCount.valid());
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class RestServer method viewerSpl.
private String viewerSpl(TWindow<Tuple, ?> window, String context, String name) {
assert window.getStream() instanceof SPLStream;
SPLWindow splWindow = SPLStreams.triggerCount(window, 1);
Map<String, Object> params = new HashMap<>();
params.put("port", port);
params.put("context", context);
params.put("contextResourceBase", "opt/html/" + context);
TSink tv = SPL.invokeSink(name, "com.ibm.streamsx.inet.rest::HTTPTupleView", splWindow, params);
if (firstInvocation == null)
firstInvocation = tv;
else
firstInvocation.colocate(tv);
// so currently it's always port 0.
return name + "/ports/input/0";
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class RestServer method viewerJSONable.
private String viewerJSONable(TWindow<? extends JSONAble, ?> window, String context, String name) {
TStream<JSONObject> jsonStream = JSONStreams.toJSON(window.getStream());
SPLStream splStream = JSONStreams.toSPL(jsonStream);
return viewerSpl(splStream.window(window), context, name);
}
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, SPLSchemas.STRING, null);
return lines.toStringStream();
}
Aggregations