Search in sources :

Example 61 with Tester

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());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) AllowAll(com.ibm.streamsx.topology.test.AllowAll) ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 62 with Tester

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());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Random(java.util.Random) BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 63 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class ParallelTest method testUnionUnparallel.

@Test
public void testUnionUnparallel() throws Exception {
    Topology topology = newTopology();
    TStream<String> strings = topology.strings("A", "B", "C", "D", "E");
    TStream<String> stringsP = strings.parallel(3);
    TStream<String> stringsP_AB = stringsP.filter(allowAB());
    TStream<String> stringsP_CDE = stringsP.filter(allowCDE());
    stringsP = stringsP_AB.union(stringsP_CDE).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());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 64 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelWidthSupplier.

@Test
public void testParallelWidthSupplier() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testParallelWidthValue");
    final int count = new Random().nextInt(1000) + 37;
    String submissionWidthName = "width";
    final Integer submissionWidth = 5;
    TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
    TStream<BeaconTuple> pb = fb.parallel(() -> 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());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Random(java.util.Random) BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 65 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class ParallelTest method testObjectHashPartition.

@Test
public void testObjectHashPartition() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testObjectHashPartition");
    final int count = new Random().nextInt(10) + 37;
    TStream<String> kb = topology.source(stringTuple5Counter(count));
    TStream<String> pb = kb.parallel(Value.of(5), TStream.Routing.HASH_PARTITIONED);
    TStream<ChannelAndSequence> cs = pb.transform(stringTupleChannelSeqTransformer());
    TStream<ChannelAndSequence> joined = cs.endParallel();
    TStream<String> valid_count = joined.transform(partitionCounter(count));
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(valid_count, 1);
    Condition<List<String>> validCount = tester.stringContents(valid_count, "5");
    complete(tester, allConditions(expectedCount, validCount), 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(validCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

Tester (com.ibm.streamsx.topology.tester.Tester)68 Topology (com.ibm.streamsx.topology.Topology)61 TestTopology (com.ibm.streamsx.topology.test.TestTopology)60 Test (org.junit.Test)60 List (java.util.List)50 ArrayList (java.util.ArrayList)28 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)20 Random (java.util.Random)13 Tuple (com.ibm.streams.operator.Tuple)12 HashMap (java.util.HashMap)10 TStream (com.ibm.streamsx.topology.TStream)9 BeaconTuple (com.ibm.streamsx.topology.tuple.BeaconTuple)9 JSONObject (com.ibm.json.java.JSONObject)8 AllowAll (com.ibm.streamsx.topology.test.AllowAll)8 HashSet (java.util.HashSet)8 OutputTuple (com.ibm.streams.operator.OutputTuple)6 StreamSchema (com.ibm.streams.operator.StreamSchema)6 LinkedList (java.util.LinkedList)6 File (java.io.File)4 JSONArray (com.ibm.json.java.JSONArray)3