Search in sources :

Example 11 with Tester

use of com.ibm.streamsx.topology.tester.Tester 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 12 with Tester

use of com.ibm.streamsx.topology.tester.Tester 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 13 with Tester

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

the class KafkaStreamsTest 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)

Example 14 with Tester

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

the class SubscribeSPLDictTest method testSubscribeSPLDictMap.

@Test
public void testSubscribeSPLDictMap() throws Exception {
    Topology topology = new Topology("testSubscribeMap");
    // Publish a stream with all the SPL types supported by Python including sets
    SPLStream tuples = PythonFunctionalOperatorsTest.testTupleStream(topology, true);
    tuples = addStartupDelay(tuples);
    tuples.publish("pytest/spl/map");
    SPLStream viaSPL = SPL.invokeOperator("spl.relational::Functor", tuples, tuples.getSchema(), null);
    // Python that subscribes to the SPL tuple stream and then republishes as Json.
    includePythonApp(topology, "spl_map_json.py", "spl_map_json::spl_map_json");
    TStream<JSONObject> viaPythonJson = topology.subscribe("pytest/spl/map/result", JSONObject.class);
    SPLStream viaPythonJsonSpl = JSONStreams.toSPL(viaPythonJson.isolate());
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(viaPythonJsonSpl, TUPLE_COUNT);
    Condition<Long> expectedCountSpl = tester.tupleCount(viaSPL, TUPLE_COUNT);
    Condition<List<Tuple>> viaSPLResult = tester.tupleContents(viaSPL);
    Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPythonJsonSpl);
    complete(tester, allConditions(expectedCount, expectedCountSpl), 60, TimeUnit.SECONDS);
    System.out.println(expectedCount.getResult());
    System.out.println(expectedCountSpl.getResult());
    assertTrue(expectedCount.valid());
    assertTrue(expectedCountSpl.valid());
    List<Tuple> splResults = viaSPLResult.getResult();
    List<Tuple> pyJsonResults = viaPythonResult.getResult();
    assertEquals(TUPLE_COUNT, splResults.size());
    assertEquals(TUPLE_COUNT, pyJsonResults.size());
    for (int i = 0; i < TUPLE_COUNT; i++) {
        Tuple spl = splResults.get(i);
        JSONObject json = (JSONObject) JSON.parse(pyJsonResults.get(i).getString("jsonString"));
        System.out.println(spl);
        System.out.println(pyJsonResults.get(i).getString("jsonString"));
        assertEquals(spl.getBoolean("b"), ((Boolean) json.get("b")).booleanValue());
        assertEquals(spl.getInt("i8"), ((Number) json.get("i8")).intValue());
        assertEquals(spl.getInt("i16"), ((Number) json.get("i16")).intValue());
        assertEquals(spl.getInt("i32"), ((Number) json.get("i32")).intValue());
        assertEquals(spl.getLong("i64"), ((Number) json.get("i64")).longValue());
        assertEquals(spl.getString("r"), json.get("r").toString());
        assertEquals(spl.getDouble("f32"), ((Number) json.get("f32")).doubleValue(), 0.1);
        assertEquals(spl.getDouble("f64"), ((Number) json.get("f64")).doubleValue(), 0.1);
        {
            List<?> ex = spl.getList("li32");
            JSONArray pya = (JSONArray) json.get("li32");
            assertEquals(ex.size(), pya.size());
            for (int j = 0; j < ex.size(); j++) {
                assertEquals(ex.get(j), ((Number) pya.get(j)).intValue());
            }
        }
        {
            Set<?> ex = spl.getSet("si32");
            JSONArray pya = (JSONArray) json.get("si32");
            assertEquals(ex.size(), pya.size());
            setAssertHelper(ex, pya);
        }
    }
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Set(java.util.Set) TreeSet(java.util.TreeSet) JSONArray(com.ibm.json.java.JSONArray) Topology(com.ibm.streamsx.topology.Topology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) JSONObject(com.ibm.json.java.JSONObject) List(java.util.List) Tuple(com.ibm.streams.operator.Tuple) PythonFunctionalOperatorsTest(com.ibm.streamsx.topology.test.splpy.PythonFunctionalOperatorsTest) Test(org.junit.Test)

Example 15 with Tester

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

the class VwapTest method testVwap.

@Test
public void testVwap() throws Exception {
    // Invokes an SPL operator so cannot run in embedded.       
    assumeSPLOk();
    TStream<Bargain> bargains = Vwap.createVwapTopology();
    bargains = Vwap.realBargains(bargains);
    Topology topology = bargains.topology();
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.atLeastTupleCount(bargains, 2200);
    complete(tester, expectedCount, 120, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Bargain(vwap.Bargain) 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)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