Search in sources :

Example 6 with Tester

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());
}
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 7 with Tester

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());
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Tester

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());
}
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 9 with Tester

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

Example 10 with Tester

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

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