Search in sources :

Example 71 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 72 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 73 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)

Example 74 with Tester

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

the class ParallelTest method testAdjacentEndParallelUnionSource.

@Test
public void testAdjacentEndParallelUnionSource() 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 = topology.strings(stringArray).union(out0).parallel(of(5), TStream.Routing.HASH_PARTITIONED);
    out2 = out2.transform(randomStringProducer("region2")).endParallel();
    TStream<String> numRegions = out2.multiTransform(uniqueStringCounter(1600, "region"));
    Tester tester = topology.getTester();
    Condition<List<String>> assertFinished = tester.stringContentsUnordered(numRegions, "20", "5");
    Condition<Long> expectedCount = tester.tupleCount(out2, 1600);
    complete(tester, allConditions(assertFinished, expectedCount), 60, TimeUnit.SECONDS);
    assertTrue(expectedCount.getResult().toString(), expectedCount.valid());
    assertTrue(assertFinished.getResult().toString(), assertFinished.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 75 with Tester

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

the class MqttStreamsTest method completeAndValidate.

private void completeAndValidate(String msg, Topology topology, TStream<String> stream, int secTimeout, String... expected) throws Exception {
    Tester tester = topology.getTester();
    Condition<Long> sCount = tester.tupleCount(stream, expected.length);
    Condition<List<String>> sContents = tester.stringContents(stream, expected);
    complete(tester, sCount, secTimeout, TimeUnit.SECONDS);
    assertTrue(msg + " contents:" + sContents, sContents.valid());
    assertTrue("valid:" + sCount, sCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Tester (com.ibm.streamsx.topology.tester.Tester)82 Topology (com.ibm.streamsx.topology.Topology)75 Test (org.junit.Test)74 List (java.util.List)64 TestTopology (com.ibm.streamsx.topology.test.TestTopology)60 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)34 ArrayList (java.util.ArrayList)28 TStream (com.ibm.streamsx.topology.TStream)22 HashMap (java.util.HashMap)22 Map (java.util.Map)15 Condition (com.ibm.streamsx.topology.tester.Condition)14 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)13 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)13 Random (java.util.Random)13 TimeUnit (java.util.concurrent.TimeUnit)13 OutputTuple (com.ibm.streams.operator.OutputTuple)12 StreamSchema (com.ibm.streams.operator.StreamSchema)12 Tuple (com.ibm.streams.operator.Tuple)12 Constants (com.ibm.streamsx.kafka.test.utils.Constants)12 KafkaSPLStreamsUtils (com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils)12