Search in sources :

Example 46 with SPLStream

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));
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Tuple(com.ibm.streams.operator.Tuple) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 47 with SPLStream

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());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) StreamSchema(com.ibm.streams.operator.StreamSchema) Factory.getStreamSchema(com.ibm.streams.operator.Type.Factory.getStreamSchema) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Random(java.util.Random) BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 48 with SPLStream

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";
}
Also used : TSink(com.ibm.streamsx.topology.TSink) HashMap(java.util.HashMap) SPLWindow(com.ibm.streamsx.topology.spl.SPLWindow) JSONObject(com.ibm.json.java.JSONObject) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Example 49 with SPLStream

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);
}
Also used : JSONObject(com.ibm.json.java.JSONObject) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Example 50 with SPLStream

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();
}
Also used : SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Aggregations

SPLStream (com.ibm.streamsx.topology.spl.SPLStream)86 Topology (com.ibm.streamsx.topology.Topology)66 Test (org.junit.Test)56 TestTopology (com.ibm.streamsx.topology.test.TestTopology)49 Tester (com.ibm.streamsx.topology.tester.Tester)40 List (java.util.List)38 HashMap (java.util.HashMap)33 StreamSchema (com.ibm.streams.operator.StreamSchema)25 OutputTuple (com.ibm.streams.operator.OutputTuple)20 Tuple (com.ibm.streams.operator.Tuple)19 Map (java.util.Map)17 TStream (com.ibm.streamsx.topology.TStream)15 SPL (com.ibm.streamsx.topology.spl.SPL)14 Condition (com.ibm.streamsx.topology.tester.Condition)14 TimeUnit (java.util.concurrent.TimeUnit)14 Constants (com.ibm.streamsx.kafka.test.utils.Constants)12 KafkaSPLStreamsUtils (com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils)12 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)12 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)12 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)12