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