use of com.ibm.streamsx.topology.test.AllowAll 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.test.AllowAll 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());
}
use of com.ibm.streamsx.topology.test.AllowAll in project streamsx.topology by IBMStreams.
the class FunctionalSubmissionParamsTest method OthersTest.
@Test
@Ignore("Suddenly started failing on jenkins streamsx.topology - but only there (expected 100 got 0). Get the build working again.")
public void OthersTest() throws Exception {
Topology topology = newTopology("OthersTest");
// getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
// FunctionFilter op is based on FunctionFunctor and the
// latter is what knows about submission params.
// Hence, given the implementation, this test should cover
// all sub classes (modify,transform,split,sink,window,aggregate...).
//
// That really accounts for all functional
// operators except FunctionSource and FunctionPeriodicSource and
// we have tests for those.
//
// But we really should verify anyway...
Supplier<Integer> someInt = topology.createSubmissionParameter("someInt", Integer.class);
Supplier<Integer> someIntD = topology.createSubmissionParameter("someIntD", 2);
List<Integer> data = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5 });
TStream<Integer> s = topology.constants(data);
// The test's functional logic asserts it receives the expected SP value.
// Its the main form of validation for the test.
// TStream.modify
TStream<Integer> modified = s.modify(unaryFn(someInt, 1));
TStream<Integer> modifiedD = s.modify(unaryFn(someIntD, 2));
// TStream.transform
TStream<Integer> xformed = s.transform(functionFn(someInt, 1));
TStream<Integer> xformedD = s.transform(functionFn(someIntD, 2));
// TStream.multiTransform
TStream<Integer> multiXformed = s.multiTransform(functionIterableFn(someInt, 1));
TStream<Integer> multiXformedD = s.multiTransform(functionIterableFn(someIntD, 2));
// TStream.join
TStream<Integer> joined = s.join(s.last(1), biFunctionListFn(someInt, 1));
TStream<Integer> joinedD = s.join(s.last(1), biFunctionListFn(someIntD, 2));
TStream<Integer> lastJoined = s.joinLast(s, biFunctionFn(someInt, 1));
TStream<Integer> lastJoinedD = s.joinLast(s, biFunctionFn(someIntD, 2));
// TStream.sink
s.sink(sinkerFn(someInt, 1));
s.sink(sinkerFn(someIntD, 2));
// TStream.split
List<TStream<Integer>> split = s.split(2, toIntFn(someInt, 1));
TStream<Integer> unionedSplit = split.get(0).union(split.get(1));
List<TStream<Integer>> splitD = s.split(2, toIntFn(someIntD, 2));
TStream<Integer> unionedSplitD = splitD.get(0).union(splitD.get(1));
// TStream.window
TWindow<Integer, ?> win = s.window(s.last(1).key(functionFn(someInt, 1)));
TStream<Integer> winAgg = win.aggregate(functionListFn(someIntD, 2));
TWindow<Integer, ?> winD = s.window(s.last(1).key(functionFn(someInt, 1)));
TStream<Integer> winAggD = winD.aggregate(functionListFn(someIntD, 2));
// TWindow.aggregate
TStream<Integer> agg = s.last(1).aggregate(functionListFn(someInt, 1));
TStream<Integer> aggD = s.last(1).aggregate(functionListFn(someIntD, 2));
s.last(1).aggregate(functionListFn(someInt, 1), 1, TimeUnit.MILLISECONDS);
s.last(1).aggregate(functionListFn(someIntD, 2), 1, TimeUnit.MILLISECONDS);
// TWindow.key
TStream<Integer> kagg = s.last(1).key(functionFn(someInt, 1)).aggregate(functionListFn(someIntD, 2));
TStream<Integer> kaggD = s.last(1).key(functionFn(someInt, 1)).aggregate(functionListFn(someIntD, 2));
Map<String, Object> params = new HashMap<>();
params.put("someInt", 1);
getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
////////////////////
Set<TStream<Integer>> all = new HashSet<>(Arrays.asList(modified, modifiedD, xformed, xformedD, multiXformed, multiXformedD, joined, joinedD, lastJoined, lastJoinedD, unionedSplit, unionedSplitD, winAgg, winAggD, agg, aggD, kagg, kaggD));
TStream<Integer> union = modified.union(all);
// tester sees 0 tuples when they are really there so...
union = union.filter(new AllowAll<Integer>());
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(union, all.size() * 5);
complete(tester, expectedCount, 15, TimeUnit.SECONDS);
assertTrue(expectedCount.toString(), expectedCount.valid());
}
use of com.ibm.streamsx.topology.test.AllowAll in project streamsx.topology by IBMStreams.
the class StreamTest method testUnion.
@Test
public void testUnion() throws Exception {
final Topology topology = newTopology("Union");
TStream<String> s1 = topology.strings("A1", "B1", "C1", "D1");
TStream<String> s2 = topology.strings("A2", "B2", "C2", "D2");
List<String> l3 = new ArrayList<>();
l3.add("A3");
l3.add("B3");
TStream<String> s3 = topology.constants(l3);
List<String> l4 = new ArrayList<>();
l4.add("A4");
l4.add("B4");
TStream<String> s4 = topology.constants(l4);
assertNotSame(s1, s2);
TStream<String> su = s1.union(s2);
assertNotSame(su, s1);
assertNotSame(su, s2);
// Merge with two different schema types
// but the primary has the correct direct type.
su = su.union(s3);
assertEquals(String.class, su.getTupleClass());
assertEquals(String.class, su.getTupleType());
// Merge with two different schema types
// but the primary has the generic type
assertNull(s4.getTupleClass());
su = s4.union(su);
assertEquals(String.class, su.getTupleClass());
assertEquals(String.class, su.getTupleType());
// TODO - testing doesn't work against union streams in embedded.
su = su.filter(new AllowAll<String>());
Tester tester = topology.getTester();
Condition<Long> suCount = tester.tupleCount(su, 12);
Condition<List<String>> suContents = tester.stringContentsUnordered(su, "A1", "B1", "C1", "D1", "A2", "B2", "C2", "D2", "A3", "B3", "A4", "B4");
//assertTrue(complete(tester, suCount, 10, TimeUnit.SECONDS));
complete(tester, suCount, 10, TimeUnit.SECONDS);
assertTrue("SU:" + suContents, suContents.valid());
assertTrue("SU:" + suCount, suCount.valid());
}
use of com.ibm.streamsx.topology.test.AllowAll in project streamsx.topology by IBMStreams.
the class PlaceableTest method testSimpleDistributedColocate.
/**
* Test with a distributed execution with explicit
* colocation of two functions end up on the same container.
*/
@Test
public void testSimpleDistributedColocate() throws Exception {
assumeTrue(SC_OK);
assumeTrue(getTesterType() == StreamsContext.Type.DISTRIBUTED_TESTER);
Topology t = newTopology();
TStream<String> sa = t.strings("a");
TStream<String> sb = t.strings("b");
sa = sa.transform(IsolateTest.getContainerId());
sb = sb.transform(IsolateTest.getContainerId());
sa.colocate(sb);
sa = sa.isolate().filter(new AllowAll<String>());
sb = sb.isolate().filter(new AllowAll<String>());
sa = sa.union(sb);
Condition<List<String>> pes = t.getTester().stringContents(sa, "");
Condition<Long> tc = t.getTester().tupleCount(sa, 2);
complete(t.getTester(), tc, 10, TimeUnit.SECONDS);
Set<String> singlePe = new HashSet<>(pes.getResult());
assertTrue(pes.getResult().toString(), singlePe.size() == 1);
}
Aggregations