Search in sources :

Example 1 with TCPTestClient

use of com.ibm.streamsx.topology.internal.tester.tcp.TCPTestClient in project streamsx.topology by IBMStreams.

the class TesterSink method processPunctuation.

@Override
public void processPunctuation(StreamingInput<Tuple> port, Punctuation mark) throws Exception {
    super.processPunctuation(port, mark);
    if (mark == Punctuation.FINAL_MARKER) {
        int portIndex = port.getPortNumber();
        TestTuple finalTupleMarker = new TestTuple(portIndex, new byte[0]);
        TCPTestClient client = clients[portIndex];
        client.writeTuple(finalTupleMarker).await();
    }
}
Also used : TCPTestClient(com.ibm.streamsx.topology.internal.tester.tcp.TCPTestClient) TestTuple(com.ibm.streamsx.topology.internal.tester.tcp.TestTuple)

Example 2 with TCPTestClient

use of com.ibm.streamsx.topology.internal.tester.tcp.TCPTestClient in project streamsx.topology by IBMStreams.

the class TesterSink method processBatch.

@Override
protected boolean processBatch(Queue<BatchedTuple> batch) throws Exception {
    List<WriteFuture> futures = new ArrayList<>(batch.size());
    for (BatchedTuple bt : batch) {
        int portIndex = bt.getStream().getPortNumber();
        TCPTestClient client = clients[portIndex];
        BinaryEncoding be = encoders[portIndex];
        byte[] tupleData = new byte[(int) be.getEncodedSize(bt.getTuple())];
        be.encodeTuple(bt.getTuple(), ByteBuffer.wrap(tupleData));
        TestTuple tt = new TestTuple(portIndex, tupleData);
        futures.add(client.writeTuple(tt));
    }
    for (WriteFuture future : futures) {
        future.await();
    }
    return false;
}
Also used : TCPTestClient(com.ibm.streamsx.topology.internal.tester.tcp.TCPTestClient) WriteFuture(org.apache.mina.core.future.WriteFuture) TestTuple(com.ibm.streamsx.topology.internal.tester.tcp.TestTuple) ArrayList(java.util.ArrayList) BinaryEncoding(com.ibm.streams.operator.encoding.BinaryEncoding)

Example 3 with TCPTestClient

use of com.ibm.streamsx.topology.internal.tester.tcp.TCPTestClient 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.tcp.TCPTestClient) InetSocketAddress(java.net.InetSocketAddress) Tuple(com.ibm.streams.operator.Tuple) TestTuple(com.ibm.streamsx.topology.internal.tester.tcp.TestTuple)

Aggregations

TCPTestClient (com.ibm.streamsx.topology.internal.tester.tcp.TCPTestClient)3 TestTuple (com.ibm.streamsx.topology.internal.tester.tcp.TestTuple)3 Tuple (com.ibm.streams.operator.Tuple)1 BinaryEncoding (com.ibm.streams.operator.encoding.BinaryEncoding)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 WriteFuture (org.apache.mina.core.future.WriteFuture)1