use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class IsolateTest method unionIsolateTest.
@Test
public void unionIsolateTest() throws Exception {
assumeTrue(SC_OK);
assumeTrue(isMainRun());
Topology topology = newTopology("unionIsolateTest");
TStream<String> s1 = topology.strings("1");
TStream<String> s2 = topology.strings("2");
TStream<String> s3 = topology.strings("3");
TStream<String> s4 = topology.strings("4");
Set<TStream<String>> l = new HashSet<>();
l.add(s1);
l.add(s2);
l.add(s3);
l.add(s4);
TStream<String> n = s1.union(l).isolate();
n.print();
n.print();
n.print();
n.print();
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(n, 4);
Condition<List<String>> expectedContent = tester.stringContentsUnordered(n, "1", "2", "3", "4");
StreamsContextFactory.getStreamsContext(StreamsContext.Type.TOOLKIT).submit(topology).get();
// assertTrue(expectedCount.valid());
// assertTrue(expectedContent.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class IsolateTest method simpleIsolationTest.
@Test
public void simpleIsolationTest() throws Exception {
assumeTrue(SC_OK);
assumeTrue(getTesterType() == StreamsContext.Type.DISTRIBUTED_TESTER);
Topology topology = newTopology("simpleIsolationTest");
// Construct topology
TStream<String> ss = topology.strings("hello");
TStream<String> ss1 = ss.transform(getContainerId()).isolate();
TStream<String> ss2 = ss.isolate().transform(getContainerId()).isolate();
Tester tester = topology.getTester();
Condition<List<String>> condss1 = tester.stringContents(ss1, "");
Condition<List<String>> condss2 = tester.stringContents(ss2, "");
Condition<Long> condss1Cnt = tester.tupleCount(ss1, 1);
Condition<Long> condss2Cnt = tester.tupleCount(ss2, 1);
Condition<Long> endCond = new MultiLongCondition(Arrays.asList(condss1Cnt, condss2Cnt));
complete(topology.getTester(), endCond, 15, TimeUnit.SECONDS);
Integer result1 = Integer.parseInt(condss1.getResult().get(0));
Integer result2 = Integer.parseInt(condss2.getResult().get(0));
Set<Integer> m = new HashSet<>();
m.add(result1);
m.add(result2);
assertEquals(2, m.size());
}
use of com.ibm.streamsx.topology.tester.Tester 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.tester.Tester in project streamsx.topology by IBMStreams.
the class StreamTest method testFunctionContextNonDistributed.
@Test
public void testFunctionContextNonDistributed() throws Exception {
assumeTrue(getTesterType() != Type.DISTRIBUTED_TESTER);
Topology t = newTopology();
TStream<Map<String, Object>> values = BeaconStreams.single(t).transform(new ExtractFunctionContext());
TStream<String> strings = StringStreams.toString(CollectionStreams.flattenMap(values));
Tester tester = t.getTester();
Condition<Long> spCount = tester.tupleCount(strings, 9);
Condition<List<String>> spContents = tester.stringContents(strings, "channel=-1", "domainId=" + System.getProperty("user.name"), "id=0", "instanceId=" + System.getProperty("user.name"), "jobId=0", "jobName=NOTNULL", "maxChannels=0", "noAppConfig={}", "relaunchCount=0");
complete(tester, spCount, 60, TimeUnit.SECONDS);
// assertTrue("SU:" + suContents, suContents.valid());
assertTrue("SP:" + spCount, spCount.valid());
assertTrue("SPContents:" + spContents, spContents.valid());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.
the class WindowTest method testPeriodicAggregateLastSeconds.
/**
* Test a periodic aggregation.
*/
@Test
public void testPeriodicAggregateLastSeconds() throws Exception {
final Topology t = newTopology();
TStream<String> source = t.periodicSource(new PeriodicStrings(), 100, TimeUnit.MILLISECONDS);
TStream<JSONObject> aggregate = source.last(3, TimeUnit.SECONDS).aggregate(new AggregateStrings(), 1, TimeUnit.SECONDS);
TStream<String> strings = JSONStreams.serialize(aggregate);
Tester tester = t.getTester();
Condition<List<String>> contents = tester.stringContents(strings);
// 10 tuples per second, aggregate every second, so 15 seconds is around 15 tuples.
Condition<Long> ending = tester.atLeastTupleCount(strings, 15);
complete(tester, ending, 30, TimeUnit.SECONDS);
assertTrue(ending.valid());
long startTs = 0;
for (String output : contents.getResult()) {
JSONObject agg = JSONObject.parse(output);
JSONArray items = (JSONArray) agg.get("items");
long ts = (Long) agg.get("ts");
// Should see around 30 tuples per window, once we
// pass the first three seconds.
assertTrue("Number of tuples in window:" + items.size(), items.size() <= 45);
if (agg.containsKey("delta")) {
long delta = (Long) agg.get("delta");
assertTrue(delta >= 0);
assertTrue("timeBetweenAggs: " + delta, delta > 800 && delta < 1200);
if (startTs == 0) {
startTs = ts;
} else {
long diff = ts - startTs;
if (diff > 3000)
assertTrue("Number of tuples in window:" + items.size(), items.size() >= 25);
}
}
}
}
Aggregations