Search in sources :

Example 21 with SPLStream

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

Example 22 with SPLStream

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");
}
Also used : 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 23 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 24 with SPLStream

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

Example 25 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, Schemas.STRING, null);
    return lines.toStringStream();
}
Also used : SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Aggregations

SPLStream (com.ibm.streamsx.topology.spl.SPLStream)72 Topology (com.ibm.streamsx.topology.Topology)53 Test (org.junit.Test)46 TestTopology (com.ibm.streamsx.topology.test.TestTopology)36 Tester (com.ibm.streamsx.topology.tester.Tester)34 List (java.util.List)31 HashMap (java.util.HashMap)27 OutputTuple (com.ibm.streams.operator.OutputTuple)17 Tuple (com.ibm.streams.operator.Tuple)16 StreamSchema (com.ibm.streams.operator.StreamSchema)15 TStream (com.ibm.streamsx.topology.TStream)15 Map (java.util.Map)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 SPL (com.ibm.streamsx.topology.spl.SPL)12 SPLStreams (com.ibm.streamsx.topology.spl.SPLStreams)12 Condition (com.ibm.streamsx.topology.tester.Condition)12