Search in sources :

Example 16 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class PythonFunctionalOperatorsKwargsTest method testFilter.

@Test
public void testFilter() throws Exception {
    Topology topology = new Topology("testFilter");
    SPLStream tuples = sampleFilterStream(topology);
    PythonFunctionalOperatorsTest.addTestToolkit(tuples);
    SPLStream pass = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.kwargs::ContainsFilter", tuples, tuples.getSchema(), Collections.singletonMap("term", "23"));
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(pass, 2);
    Condition<List<Tuple>> passResult = tester.tupleContents(pass);
    this.getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertEquals(TEST_TUPLES[1], passResult.getResult().get(0));
    assertEquals(TEST_TUPLES[3], passResult.getResult().get(1));
    assertTrue(expectedCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) 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 17 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method createSPLFlowFromStream.

@SuppressWarnings("serial")
private static SPLStream createSPLFlowFromStream(final Topology topology, final boolean skipSecond) {
    TStream<String> source = topology.strings("325", "457", "9325");
    TStream<IntAndString> iands = source.transform(new Function<String, IntAndString>() {

        @Override
        public IntAndString apply(String v1) {
            IntAndString is = new IntAndString();
            is.s = v1;
            is.n = Integer.valueOf(v1) + 93;
            return is;
        }
    });
    StreamSchema schema = Type.Factory.getStreamSchema("tuple<int32 ii, rstring ss>");
    SPLStream splStream = SPLStreams.convertStream(iands, new BiFunction<IntAndString, OutputTuple, OutputTuple>() {

        @Override
        public OutputTuple apply(IntAndString v1, OutputTuple v2) {
            if (skipSecond & v1.n == 550)
                return null;
            v2.setString("ss", v1.s);
            v2.setInt("ii", v1.n);
            return v2;
        }
    }, schema);
    assertSPLStream(splStream, schema);
    return splStream;
}
Also used : StreamSchema(com.ibm.streams.operator.StreamSchema) OutputTuple(com.ibm.streams.operator.OutputTuple) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Example 18 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testTuples.

@Test
public void testTuples() throws Exception {
    Topology topology = new Topology("testTuples");
    SPLStream tuples = testTupleStream(topology);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(tuples, TEST_TUPLES.length);
    Condition<List<Tuple>> expectedTuples = tester.tupleContents(tuples, TEST_TUPLES);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(expectedTuples.toString(), expectedTuples.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List) 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 19 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testConversionFromSPLToStringAttribute.

@Test
public void testConversionFromSPLToStringAttribute() throws Exception {
    final Topology topology = new Topology();
    SPLStream splStream = testTupleStream(topology);
    TStream<String> strings = SPLStreams.toStringStream(splStream, "vl");
    assertEquals(String.class, strings.getTupleClass());
    completeAndValidate(strings, 10, "34535", "43675232", "654932", "82343");
}
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 20 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testConversionToSPLWithSkip.

@Test
public void testConversionToSPLWithSkip() throws Exception {
    final Topology topology = new Topology("ConvertSPLStream");
    SPLStream splStream = createSPLFlowFromStream(topology, true);
    TStream<String> tupleString = splStream.toTupleString();
    completeAndValidate(tupleString, 10, "{ii=418,ss=\"325\"}", "{ii=9418,ss=\"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)

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