use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class ParallelTest method testParallelSubmissionParamDefault.
@Test
public void testParallelSubmissionParamDefault() throws Exception {
checkUdpSupported();
Topology topology = newTopology("testParallelSubmissionParamDefault");
final int count = new Random().nextInt(1000) + 37;
String submissionWidthName = "width";
Integer submissionWidth = 5;
TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
TStream<BeaconTuple> pb = fb.parallel(topology.createSubmissionParameter(submissionWidthName, submissionWidth));
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, submissionWidth.toString());
complete(tester, allConditions(regionCount, expectedCount), 10, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(regionCount.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class ParallelTest method testParallelPreFanOut.
@Test
@Ignore("Issue #131")
public void testParallelPreFanOut() throws Exception {
Topology topology = newTopology();
TStream<String> strings = topology.strings("A", "B", "C", "D", "E");
strings.print();
TStream<String> stringsP = strings.parallel(3);
stringsP = stringsP.filter(new AllowAll<String>());
stringsP = stringsP.endParallel();
Tester tester = topology.getTester();
Condition<Long> fiveTuples = tester.tupleCount(stringsP, 5);
Condition<List<String>> contents = tester.stringContentsUnordered(stringsP, "A", "B", "C", "D", "E");
complete(tester, allConditions(fiveTuples, contents), 10, TimeUnit.SECONDS);
assertTrue("contents: " + contents, contents.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class ParallelTest method testAdjacentParallel.
@Test
public void testAdjacentParallel() throws Exception {
checkUdpSupported();
List<String> stringList = getListOfUniqueStrings(800);
String[] stringArray = new String[800];
stringArray = stringList.toArray(stringArray);
Topology topology = newTopology("testAdj");
TStream<String> out0 = topology.strings(stringArray).parallel(of(20), TStream.Routing.HASH_PARTITIONED);
out0 = out0.transform(randomStringProducer("region1")).endParallel();
TStream<String> out2 = out0.parallel(of(5), TStream.Routing.HASH_PARTITIONED);
out2 = out2.transform(randomStringProducer("region2")).endParallel();
TStream<String> numRegions = out2.multiTransform(uniqueStringCounter(800, "region"));
Tester tester = topology.getTester();
Condition<List<String>> assertFinished = tester.stringContentsUnordered(numRegions, "20", "5");
Condition<Long> expectedCount = tester.tupleCount(out2, 800);
complete(tester, allConditions(assertFinished, expectedCount), 60, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(assertFinished.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class ParallelTest method fanoutEndParallelException.
/**
* Currently a fan-out before an endParallel
* is not supported. This is a limitation purely on
* code generation.
*/
@Test(expected = IllegalStateException.class)
public void fanoutEndParallelException() throws Exception {
checkUdpSupported();
Topology topology = newTopology("testFanout");
TStream<String> fanOut = topology.strings("hello").parallel(5).filter(new AllowAll<String>());
fanOut.print();
fanOut.endParallel();
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(fanOut, 1);
complete(tester, expectedCount, 60, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class ParallelTest method testParallelSplit.
@Test
public void testParallelSplit() throws Exception {
// embedded: split works but validation fails because it
// depends on validating the correct parallel channel too,
// and in embedded mode PERuntime.getCurrentContext().getChannel()
// returns -1. issue#126
// until that's addressed...
checkUdpSupported();
// parallel().split() is an interesting case because split()
// has >1 oports.
final Topology topology = newTopology("testParallelSplit");
// Order the tuples based on their expected/required
// delivery path given an n-ch round-robin parallel region
// and our split() behavior
int splitWidth = 3;
int parallelWidth = 2;
String[] strs = { "pch=0 sch=0", "pch=1 sch=0", "pch=0 sch=1", "pch=1 sch=1", "pch=0 sch=2", "pch=1 sch=2", "pch=0 another-sch=2", "pch=1 another-sch=2", "pch=0 another-sch=1", "pch=1 another-sch=1", "pch=0 another-sch=0", "pch=1 another-sch=0" };
String[] strsExpected = { "[pch=0, sch=0] pch=0 sch=0", "[pch=1, sch=0] pch=1 sch=0", "[pch=0, sch=1] pch=0 sch=1", "[pch=1, sch=1] pch=1 sch=1", "[pch=0, sch=2] pch=0 sch=2", "[pch=1, sch=2] pch=1 sch=2", "[pch=0, sch=2] pch=0 another-sch=2", "[pch=1, sch=2] pch=1 another-sch=2", "[pch=0, sch=1] pch=0 another-sch=1", "[pch=1, sch=1] pch=1 another-sch=1", "[pch=0, sch=0] pch=0 another-sch=0", "[pch=1, sch=0] pch=1 another-sch=0" };
TStream<String> s1 = topology.strings(strs);
s1 = s1.parallel(parallelWidth);
/////////////////////////////////////
List<TStream<String>> splits = s1.split(splitWidth, myStringSplitter());
assertEquals("list size", splitWidth, splits.size());
List<TStream<String>> splitChResults = new ArrayList<>();
for (int i = 0; i < splits.size(); i++) {
splitChResults.add(splits.get(i).modify(parallelSplitModifier(i)));
}
TStream<String> splitChFanin = splitChResults.get(0).union(new HashSet<>(splitChResults.subList(1, splitChResults.size())));
// workaround: avoid union().endParallel() bug issue#127
splitChFanin = splitChFanin.filter(new AllowAll<String>());
/////////////////////////////////////
TStream<String> all = splitChFanin.endParallel();
all.print();
Tester tester = topology.getTester();
TStream<String> dupAll = all.filter(new AllowAll<String>());
Condition<Long> uCount = tester.tupleCount(dupAll, strsExpected.length);
Condition<List<String>> contents = tester.stringContentsUnordered(dupAll, strsExpected);
complete(tester, allConditions(uCount, contents), 10, TimeUnit.SECONDS);
assertTrue("contents: " + contents, contents.valid());
}
Aggregations