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));
}
}
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);
}
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();
}
};
}
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();
}
};
}
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;
}
Aggregations