Search in sources :

Example 21 with Topology

use of com.ibm.streamsx.topology.Topology 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 22 with Topology

use of com.ibm.streamsx.topology.Topology 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)

Example 23 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelPartitioned.

@Test
public void testParallelPartitioned() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testParallelPartition");
    final int count = new Random().nextInt(10) + 37;
    TStream<BeaconTuple> kb = topology.source(keyableBeacon5Counter(count));
    TStream<BeaconTuple> pb = kb.parallel(new Value<Integer>(5), keyBeacon());
    TStream<ChannelAndSequence> cs = pb.transform(channelSeqTransformer());
    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) 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 24 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class PlaceableTest method testColocateLowLatencyRegions.

@SuppressWarnings("unused")
@Test(expected = IllegalStateException.class)
public void testColocateLowLatencyRegions() throws Exception {
    assumeTrue(isMainRun());
    // ensure colocating two low latency regions doesn't break lowLatancy
    // and colocating is achieved.
    Topology t = newTopology("testColocateLowLatencyRegions");
    Tester tester = t.getTester();
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    TStream<String> s1 = t.strings("a").lowLatency().modify(getContainerIdAppend()).modify(getContainerIdAppend());
    s1.endLowLatency();
    TStream<String> s2 = t.strings("A").lowLatency().modify(getContainerIdAppend()).modify(getContainerIdAppend());
    s2.endLowLatency();
    // expect throw ISE: colocate in a low latency region
    s1.colocate(s2);
// once it's supported... (today it breaks the low latency guarantee)
// and adjust isMainRun() too
//        // Given the default fuse-island behavior, expect islands to continue
//        // to be fused, now both in a single container.
//        
//        // Today FAILING in an interesting way.
//        // There are 2 PEs:
//        // - one has just the single colocated s1 and s2 modify ops
//        // - the other has everything else
//        
//        TStream<String> all = s1.union(s2);
//        all.print();
//        Condition<Long> nTuples = tester.tupleCount(all.filter(new AllowAll<String>()), 2);
//        Condition<List<String>> contents = tester.stringContents(
//                all.filter(new AllowAll<String>()), "");
//
//        complete(tester, nTuples, 10, TimeUnit.SECONDS);
//
//        Set<String> ids = getContainerIds(contents.getResult());
//        assertEquals("ids: "+ids, 1, ids.size());
}
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 25 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class JoinTest method testKeyedJoinLast.

@Test
public void testKeyedJoinLast() throws Exception {
    final Topology t = newTopology();
    TStream<String> strings = t.strings("a1", "b1", "c1", "a2", "a3", "c2");
    TStream<String> main = delayedList(t, "a", "b", "c", "d");
    TStream<String> joined = _testKeyedJoinLast(main, strings);
    TStream<String> asString = StringStreams.toString(joined);
    completeAndValidate(asString, 25, "a3", "b1", "c2", "empty");
}
Also used : Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)267 TestTopology (com.ibm.streamsx.topology.test.TestTopology)235 Test (org.junit.Test)213 List (java.util.List)66 Tester (com.ibm.streamsx.topology.tester.Tester)61 ArrayList (java.util.ArrayList)50 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)39 JSONObject (com.ibm.json.java.JSONObject)25 HashMap (java.util.HashMap)21 Message (com.ibm.streamsx.topology.tuple.Message)20 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)20 Random (java.util.Random)19 File (java.io.File)15 Value (com.ibm.streamsx.topology.logic.Value)14 Tuple (com.ibm.streams.operator.Tuple)13 MqttStreams (com.ibm.streamsx.topology.messaging.mqtt.MqttStreams)13 TSink (com.ibm.streamsx.topology.TSink)12 KafkaConsumer (com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer)12 AllowAll (com.ibm.streamsx.topology.test.AllowAll)12 BeaconTuple (com.ibm.streamsx.topology.tuple.BeaconTuple)11