use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class SPLOperatorsTest method testSPLOperator.
/**
* Test we can invoke an SPL operator.
*/
@Test
public void testSPLOperator() throws Exception {
Topology topology = new Topology("testSPLOperator");
SPLStream tuples = SPLStreamsTest.testTupleStream(topology);
// Filter on the vi attribute, passing the value 321.
Map<String, Object> params = new HashMap<>();
params.put("attr", tuples.getSchema().getAttribute("vi"));
params.put("value", 321);
SPL.addToolkit(tuples, new File(getTestRoot(), "spl/testtk"));
SPLStream int32Filtered = SPL.invokeOperator("testspl::Int32Filter", tuples, tuples.getSchema(), params);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(int32Filtered, 2);
Condition<List<Tuple>> expectedTuples = tester.tupleContents(int32Filtered, SPLStreamsTest.TEST_TUPLES[0], SPLStreamsTest.TEST_TUPLES[2]);
complete(tester, expectedCount, 10, TimeUnit.SECONDS);
assertTrue(expectedCount.toString(), expectedCount.valid());
assertTrue(expectedTuples.toString(), expectedTuples.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class BeaconTest method testBeaconTuples.
@Test
public void testBeaconTuples() throws Exception {
Topology topology = new Topology("testFixedCount");
final int count = new Random().nextInt(1000) + 37;
TStream<BeaconTuple> beacon = BeaconStreams.beacon(topology, count);
TStream<JSONObject> json = JSONStreams.toJSON(beacon);
TStream<String> strings = JSONStreams.serialize(json);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(strings, count);
@SuppressWarnings("serial") Condition<String> contents = tester.stringTupleTester(strings, new Predicate<String>() {
private transient BeaconTuple lastTuple;
@Override
public boolean test(String tuple) {
JSONObject json;
try {
json = (JSONObject) JSON.parse(tuple);
} catch (NullPointerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
BeaconTuple bt = new BeaconTuple((Long) json.get("sequence"), (Long) json.get("time"));
boolean ok;
if (lastTuple == null) {
ok = bt.getSequence() == 0;
} else {
ok = lastTuple.compareTo(bt) < 0 && lastTuple.getTime() <= bt.getTime() && lastTuple.getSequence() + 1 == bt.getSequence();
}
ok = ok && bt.getTime() != 0;
ok = ok && bt.getKey() == bt.getSequence();
lastTuple = bt;
return ok;
}
});
complete(tester, expectedCount, 20, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(contents.toString(), contents.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class LowLatencyTest method testLowLatencySplit.
@Test
public void testLowLatencySplit() throws Exception {
// lowLatency().split() is an interesting case because split()
// has >1 oports.
final Topology topology = newTopology("testLowLatencySplit");
int splitWidth = 3;
String[] strs = { "ch0", "ch1", "ch2" };
TStream<String> s1 = topology.strings(strs);
s1 = s1.isolate();
s1 = s1.lowLatency();
/////////////////////////////////////
// assume that if s1.modify and the split().[modify()] are
// in the same PE, that s1.split() is in the same too
TStream<String> s2 = s1.modify(unaryGetPEId());
List<TStream<String>> splits = s1.split(splitWidth, roundRobinSplitter());
List<TStream<String>> splitChResults = new ArrayList<>();
for (int i = 0; i < splits.size(); i++) {
splitChResults.add(splits.get(i).modify(unaryGetPEId()));
}
TStream<String> splitChFanin = splitChResults.get(0).union(new HashSet<>(splitChResults.subList(1, splitChResults.size())));
/////////////////////////////////////
TStream<String> all = splitChFanin.endLowLatency();
Tester tester = topology.getTester();
Condition<Long> uCount = tester.tupleCount(all, strs.length);
Condition<List<String>> contents = tester.stringContents(all, "");
Condition<List<String>> s2contents = tester.stringContents(s2, "");
complete(tester, uCount, 10, TimeUnit.SECONDS);
Set<String> peIds = new HashSet<>();
peIds.addAll(contents.getResult());
peIds.addAll(s2contents.getResult());
assertEquals("peIds: " + peIds, 1, peIds.size());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class LowLatencyTest method nestedTest.
@Test
public void nestedTest() throws Exception {
// ensure nested low latency yields all fns in the same container
final Topology topology = newTopology("nestedTest");
final Tester tester = topology.getTester();
// getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
String[] s1Strs = { "a" };
TStream<String> s1 = topology.strings(s1Strs);
TStream<String> s2 = s1.isolate().lowLatency().modify(getContainerIdAppend()).lowLatency().modify(getContainerIdAppend()).endLowLatency().modify(getContainerIdAppend()).endLowLatency();
// NOTE, this works in the sense that all end up in the same container,
// but currently only because of the default fuse-island behavior.
// There are two issues with the json:
// a) the 3rd modify is missing a lowLatencyTag
// b) the 2nd modify has a different tag than the first.
// logically it must net out to being in the same container,
// so its just easiest if they're the same tag.
// It's not clear that having them be different is an absolute wrong,
// it's just that it doesn't add any value and complicates things.
// s2.print();
Condition<Long> uCount = tester.tupleCount(s2.filter(new AllowAll<String>()), 1);
Condition<List<String>> contents = tester.stringContents(s2.filter(new AllowAll<String>()), "");
complete(tester, uCount, 10, TimeUnit.SECONDS);
Set<String> ids = getContainerIds(contents.getResult());
assertEquals("ids: " + ids, 1, ids.size());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class ParallelTest method testParallelNonPartitioned.
@Test
public void testParallelNonPartitioned() throws Exception {
checkUdpSupported();
Topology topology = newTopology("testParallel");
final int count = new Random().nextInt(1000) + 37;
TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
TStream<BeaconTuple> pb = fb.parallel(5);
TStream<Integer> is = pb.transform(randomHashProducer());
TStream<Integer> joined = is.endParallel();
TStream<String> numRegions = joined.transform(uniqueIdentifierMap(count));
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(numRegions, 1);
Condition<List<String>> regionCount = tester.stringContents(numRegions, "5");
complete(tester, allConditions(regionCount, expectedCount), 10, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(regionCount.valid());
}
Aggregations