Search in sources :

Example 66 with Tester

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

the class SPLOperatorsTest method testSPLOperator.

/**
     * Test we can invoke an SPL operator.
     */
@Test
public void testSPLOperator() throws Exception {
    Topology topology = new Topology("testSPLOperator");
    SPLStream tuples = SPLStreamsTest.testTupleStream(topology);
    // Filter on the vi attribute, passing the value 321.
    Map<String, Object> params = new HashMap<>();
    params.put("attr", tuples.getSchema().getAttribute("vi"));
    params.put("value", 321);
    SPL.addToolkit(tuples, new File(getTestRoot(), "spl/testtk"));
    SPLStream int32Filtered = SPL.invokeOperator("testspl::Int32Filter", tuples, tuples.getSchema(), params);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(int32Filtered, 2);
    Condition<List<Tuple>> expectedTuples = tester.tupleContents(int32Filtered, SPLStreamsTest.TEST_TUPLES[0], SPLStreamsTest.TEST_TUPLES[2]);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
    assertTrue(expectedTuples.toString(), expectedTuples.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) JSONObject(com.ibm.json.java.JSONObject) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) File(java.io.File) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 67 with Tester

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

the class BeaconTest method testBeaconTuples.

@Test
public void testBeaconTuples() throws Exception {
    Topology topology = new Topology("testFixedCount");
    final int count = new Random().nextInt(1000) + 37;
    TStream<BeaconTuple> beacon = BeaconStreams.beacon(topology, count);
    TStream<JSONObject> json = JSONStreams.toJSON(beacon);
    TStream<String> strings = JSONStreams.serialize(json);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(strings, count);
    @SuppressWarnings("serial") Condition<String> contents = tester.stringTupleTester(strings, new Predicate<String>() {

        private transient BeaconTuple lastTuple;

        @Override
        public boolean test(String tuple) {
            JSONObject json;
            try {
                json = (JSONObject) JSON.parse(tuple);
            } catch (NullPointerException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            BeaconTuple bt = new BeaconTuple((Long) json.get("sequence"), (Long) json.get("time"));
            boolean ok;
            if (lastTuple == null) {
                ok = bt.getSequence() == 0;
            } else {
                ok = lastTuple.compareTo(bt) < 0 && lastTuple.getTime() <= bt.getTime() && lastTuple.getSequence() + 1 == bt.getSequence();
            }
            ok = ok && bt.getTime() != 0;
            ok = ok && bt.getKey() == bt.getSequence();
            lastTuple = bt;
            return ok;
        }
    });
    complete(tester, expectedCount, 20, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(contents.toString(), contents.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) IOException(java.io.IOException) Random(java.util.Random) JSONObject(com.ibm.json.java.JSONObject) BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) Test(org.junit.Test)

Example 68 with Tester

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

the class LowLatencyTest method testLowLatencySplit.

@Test
public void testLowLatencySplit() throws Exception {
    // lowLatency().split() is an interesting case because split()
    // has >1 oports.
    final Topology topology = newTopology("testLowLatencySplit");
    int splitWidth = 3;
    String[] strs = { "ch0", "ch1", "ch2" };
    TStream<String> s1 = topology.strings(strs);
    s1 = s1.isolate();
    s1 = s1.lowLatency();
    /////////////////////////////////////
    // assume that if s1.modify and the split().[modify()] are
    // in the same PE, that s1.split() is in the same too
    TStream<String> s2 = s1.modify(unaryGetPEId());
    List<TStream<String>> splits = s1.split(splitWidth, roundRobinSplitter());
    List<TStream<String>> splitChResults = new ArrayList<>();
    for (int i = 0; i < splits.size(); i++) {
        splitChResults.add(splits.get(i).modify(unaryGetPEId()));
    }
    TStream<String> splitChFanin = splitChResults.get(0).union(new HashSet<>(splitChResults.subList(1, splitChResults.size())));
    /////////////////////////////////////
    TStream<String> all = splitChFanin.endLowLatency();
    Tester tester = topology.getTester();
    Condition<Long> uCount = tester.tupleCount(all, strs.length);
    Condition<List<String>> contents = tester.stringContents(all, "");
    Condition<List<String>> s2contents = tester.stringContents(s2, "");
    complete(tester, uCount, 10, TimeUnit.SECONDS);
    Set<String> peIds = new HashSet<>();
    peIds.addAll(contents.getResult());
    peIds.addAll(s2contents.getResult());
    assertEquals("peIds: " + peIds, 1, peIds.size());
}
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) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 69 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 70 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)

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