Search in sources :

Example 1 with Tuple

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

the class FunctionWindow method initialize.

@Override
public void initialize(OperatorContext context) throws Exception {
    super.initialize(context);
    StreamWindow<Tuple> window = getInput(0).getStreamWindow();
    createWindowListener(window);
    if (window.isPartitioned()) {
        if (getKeyGetter() == null)
            throw new IllegalStateException("Missing keyGetter function");
        SPLMapping<Object> input0Mapping = getInputMapping(this, 0);
        Function<Object, Object> functionKeyGetter = getLogicObject(getKeyGetter());
        window.registerPartitioner(new KeyPartitioner(input0Mapping, functionKeyGetter));
    }
}
Also used : KeyPartitioner(com.ibm.streamsx.topology.internal.functional.window.KeyPartitioner) FunctionalHelper.getLogicObject(com.ibm.streamsx.topology.internal.functional.FunctionalHelper.getLogicObject) Tuple(com.ibm.streams.operator.Tuple)

Example 2 with Tuple

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

the class TestTupleInjector method tuple.

@Override
public void tuple(byte[] tupleData) throws Exception {
    if (tupleData.length == 0) {
        mark(Punctuation.FINAL_MARKER);
        return;
    }
    Tuple tuple = encoding.decodeTuple(ByteBuffer.wrap(tupleData));
    injectPort.submit(tuple);
}
Also used : Tuple(com.ibm.streams.operator.Tuple) OutputTuple(com.ibm.streams.operator.OutputTuple)

Example 3 with Tuple

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

the class TupleCollection method stringContentsUnordered.

@Override
public Condition<List<String>> stringContentsUnordered(TStream<String> stream, String... values) {
    final List<String> sortedValues = Arrays.asList(values);
    Collections.sort(sortedValues);
    final StreamCollector<LinkedList<Tuple>, Tuple> tuples = StreamCollector.newLinkedListCollector();
    addHandler(stream, tuples);
    return new Condition<List<String>>() {

        @Override
        public List<String> getResult() {
            List<String> strings = new ArrayList<>(tuples.getTupleCount());
            synchronized (tuples.getTuples()) {
                for (Tuple tuple : tuples.getTuples()) {
                    strings.add(tuple.getString(0));
                }
            }
            return strings;
        }

        @Override
        public boolean valid() {
            List<String> strings = getResult();
            if (strings.size() != sortedValues.size())
                return false;
            Collections.sort(strings);
            return sortedValues.equals(strings);
        }

        @Override
        public String toString() {
            return "Received Tuples: " + getResult();
        }
    };
}
Also used : Condition(com.ibm.streamsx.topology.tester.Condition) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Example 4 with Tuple

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

the class TupleCollection method stringContents.

@Override
public Condition<List<String>> stringContents(TStream<String> stream, final String... values) {
    stream = stream.asType(String.class);
    final StreamCollector<LinkedList<Tuple>, Tuple> tuples = StreamCollector.newLinkedListCollector();
    addHandler(stream, tuples);
    return new Condition<List<String>>() {

        @Override
        public List<String> getResult() {
            List<String> strings = new ArrayList<>(tuples.getTupleCount());
            synchronized (tuples.getTuples()) {
                for (Tuple tuple : tuples.getTuples()) {
                    strings.add(tuple.getString(0));
                }
            }
            return strings;
        }

        @Override
        public boolean valid() {
            if (tuples.getTupleCount() != values.length)
                return false;
            List<Tuple> sc = tuples.getTuples();
            for (int i = 0; i < values.length; i++) {
                if (!sc.get(i).getString(0).equals(values[i]))
                    return false;
            }
            return true;
        }

        @Override
        public String toString() {
            return "Received Tuples: " + getResult();
        }
    };
}
Also used : Condition(com.ibm.streamsx.topology.tester.Condition) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Example 5 with Tuple

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

the class JSONStreamsTest method checkJsonOutput.

private JSONArtifact checkJsonOutput(JSONArtifact expected, TStream<String> jsonString) throws Exception, IOException {
    assertEquals(String.class, jsonString.getTupleClass());
    assertEquals(String.class, jsonString.getTupleType());
    SPLStream splS = SPLStreams.stringToSPLStream(jsonString);
    MostRecent<Tuple> mr = jsonString.topology().getTester().splHandler(splS, new MostRecent<Tuple>());
    Condition<Long> singleTuple = jsonString.topology().getTester().tupleCount(splS, 1);
    complete(jsonString.topology().getTester(), singleTuple, 10, TimeUnit.SECONDS);
    JSONArtifact rv = JSON.parse(mr.getMostRecentTuple().getString(0));
    assertEquals(expected, rv);
    return rv;
}
Also used : JSONArtifact(com.ibm.json.java.JSONArtifact) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Tuple(com.ibm.streams.operator.Tuple)

Aggregations

Tuple (com.ibm.streams.operator.Tuple)25 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)15 OutputTuple (com.ibm.streams.operator.OutputTuple)13 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 List (java.util.List)9 LinkedList (java.util.LinkedList)8 StreamSchema (com.ibm.streams.operator.StreamSchema)5 Random (java.util.Random)3 Condition (com.ibm.streamsx.topology.tester.Condition)2 ArrayList (java.util.ArrayList)2 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