Search in sources :

Example 11 with Tuple

use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.

the class SimpleEmbeddedTest method testSimple.

@Test
public void testSimple() throws Exception {
    Topology topology = new Topology("testSimple");
    TStream<String> hw = topology.strings("Hello", "World!", "Test!!");
    SPLStream hws = SPLStreams.stringToSPLStream(hw);
    Tester tester = topology.getTester();
    StreamCounter<Tuple> counter = tester.splHandler(hws, new StreamCounter<Tuple>());
    StreamCollector<LinkedList<Tuple>, Tuple> collector = tester.splHandler(hws, StreamCollector.newLinkedListCollector());
    StreamsContextFactory.getStreamsContext(StreamsContext.Type.EMBEDDED_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));
}
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 12 with Tuple

use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.

the class PythonFunctionalOperatorsTest method testPositionalSampleSimpleFilter.

@Test
public void testPositionalSampleSimpleFilter() throws Exception {
    Topology topology = new Topology("testPositionalSampleSimpleFilter");
    SPLStream tuples = sampleFilterStream(topology);
    addTestToolkit(tuples);
    SPLStream viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.positional::SimpleFilter", tuples, tuples.getSchema(), null);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(viaPython, 2);
    // first attribute is the sum of the first and second input attributes
    // others are copied across from in to out.
    Tuple r1 = TEST_SCHEMA_SF.getTuple(new Object[] { 32, (short) 25, 34535L });
    Tuple r2 = TEST_SCHEMA_SF.getTuple(new Object[] { 5, (short) 3, 654932L });
    Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPython, r1, r2);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
    assertTrue(viaPythonResult.toString(), viaPythonResult.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) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple) Test(org.junit.Test)

Example 13 with Tuple

use of com.ibm.streams.operator.Tuple in project streamsx.kafka by IBMStreams.

the class KafkaSPLStreamsUtils method union.

public static SPLStream union(List<SPLStream> streams, StreamSchema schema) {
    if (streams.size() == 0)
        throw new IllegalArgumentException("At least one stream must be provided.");
    if (streams.size() == 1) {
        return streams.get(0);
    } else {
        SPLStream stream1 = streams.get(0);
        Set<TStream<Tuple>> streamSet = new HashSet<TStream<Tuple>>(streams);
        streamSet.remove(stream1);
        return SPLStreams.convertStream(stream1.union(streamSet), getTupleStreamConvert(), schema);
    }
}
Also used : TStream(com.ibm.streamsx.topology.TStream) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Tuple(com.ibm.streams.operator.Tuple) OutputTuple(com.ibm.streams.operator.OutputTuple) HashSet(java.util.HashSet)

Example 14 with Tuple

use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.

the class TesterSink method initialize.

@Override
public void initialize(OperatorContext context) throws Exception {
    super.initialize(context);
    setBatchSize(1);
    setPreserveOrder(true);
    InetSocketAddress addr = new InetSocketAddress(getHost(), getPort());
    clients = new TCPTestClient[context.getNumberOfStreamingInputs()];
    encoders = new BinaryEncoding[context.getNumberOfStreamingInputs()];
    for (StreamingInput<Tuple> input : context.getStreamingInputs()) {
        TCPTestClient client = new TCPTestClient(addr);
        client.connect();
        clients[input.getPortNumber()] = client;
        encoders[input.getPortNumber()] = input.getStreamSchema().newNativeBinaryEncoding();
    }
}
Also used : TCPTestClient(com.ibm.streamsx.topology.internal.tester.TCPTestClient) InetSocketAddress(java.net.InetSocketAddress) Tuple(com.ibm.streams.operator.Tuple) TestTuple(com.ibm.streamsx.topology.internal.tester.TestTuple)

Example 15 with Tuple

use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.

the class TupleCollection method setupEmbeddedTestHandlers.

public void setupEmbeddedTestHandlers(JavaTestableGraph tg) throws Exception {
    for (TStream<?> stream : handlers.keySet()) {
        Set<StreamHandler<Tuple>> streamHandlers = handlers.get(stream);
        for (StreamHandler<Tuple> streamHandler : streamHandlers) {
            BOutput output = stream.output();
            if (output instanceof BOutputPort) {
                BOutputPort outputPort = (BOutputPort) output;
                tg.registerStreamHandler(outputPort.port(), streamHandler);
            }
        // tg.registerStreamHandler(stream.getPort(), streamHandler);
        }
    }
}
Also used : BOutput(com.ibm.streamsx.topology.builder.BOutput) StreamHandler(com.ibm.streams.flow.handlers.StreamHandler) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Aggregations

Tuple (com.ibm.streams.operator.Tuple)27 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)16 OutputTuple (com.ibm.streams.operator.OutputTuple)15 Topology (com.ibm.streamsx.topology.Topology)13 TestTopology (com.ibm.streamsx.topology.test.TestTopology)12 Tester (com.ibm.streamsx.topology.tester.Tester)12 Test (org.junit.Test)12 LinkedList (java.util.LinkedList)9 List (java.util.List)9 StreamSchema (com.ibm.streams.operator.StreamSchema)5 Condition (com.ibm.streamsx.topology.tester.Condition)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 JSONArray (com.ibm.json.java.JSONArray)1 JSONArtifact (com.ibm.json.java.JSONArtifact)1 JSONObject (com.ibm.json.java.JSONObject)1 StreamHandler (com.ibm.streams.flow.handlers.StreamHandler)1 Attribute (com.ibm.streams.operator.Attribute)1 TupleType (com.ibm.streams.operator.meta.TupleType)1 RString (com.ibm.streams.operator.types.RString)1