Search in sources :

Example 26 with Tester

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

the class IsolateTest method unionIsolateTest.

@Test
public void unionIsolateTest() throws Exception {
    assumeTrue(SC_OK);
    assumeTrue(isMainRun());
    Topology topology = newTopology("unionIsolateTest");
    TStream<String> s1 = topology.strings("1");
    TStream<String> s2 = topology.strings("2");
    TStream<String> s3 = topology.strings("3");
    TStream<String> s4 = topology.strings("4");
    Set<TStream<String>> l = new HashSet<>();
    l.add(s1);
    l.add(s2);
    l.add(s3);
    l.add(s4);
    TStream<String> n = s1.union(l).isolate();
    n.print();
    n.print();
    n.print();
    n.print();
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(n, 4);
    Condition<List<String>> expectedContent = tester.stringContentsUnordered(n, "1", "2", "3", "4");
    StreamsContextFactory.getStreamsContext(StreamsContext.Type.TOOLKIT).submit(topology).get();
// assertTrue(expectedCount.valid());
// assertTrue(expectedContent.valid());
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Tester

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

the class IsolateTest method simpleIsolationTest.

@Test
public void simpleIsolationTest() throws Exception {
    assumeTrue(SC_OK);
    assumeTrue(getTesterType() == StreamsContext.Type.DISTRIBUTED_TESTER);
    Topology topology = newTopology("simpleIsolationTest");
    // Construct topology
    TStream<String> ss = topology.strings("hello");
    TStream<String> ss1 = ss.transform(getContainerId()).isolate();
    TStream<String> ss2 = ss.isolate().transform(getContainerId()).isolate();
    Tester tester = topology.getTester();
    Condition<List<String>> condss1 = tester.stringContents(ss1, "");
    Condition<List<String>> condss2 = tester.stringContents(ss2, "");
    Condition<Long> condss1Cnt = tester.tupleCount(ss1, 1);
    Condition<Long> condss2Cnt = tester.tupleCount(ss2, 1);
    Condition<Long> endCond = new MultiLongCondition(Arrays.asList(condss1Cnt, condss2Cnt));
    complete(topology.getTester(), endCond, 15, TimeUnit.SECONDS);
    Integer result1 = Integer.parseInt(condss1.getResult().get(0));
    Integer result2 = Integer.parseInt(condss2.getResult().get(0));
    Set<Integer> m = new HashSet<>();
    m.add(result1);
    m.add(result2);
    assertEquals(2, m.size());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with Tester

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

the class StreamTest method testUnion.

@Test
public void testUnion() throws Exception {
    final Topology topology = newTopology("Union");
    TStream<String> s1 = topology.strings("A1", "B1", "C1", "D1");
    TStream<String> s2 = topology.strings("A2", "B2", "C2", "D2");
    List<String> l3 = new ArrayList<>();
    l3.add("A3");
    l3.add("B3");
    TStream<String> s3 = topology.constants(l3);
    List<String> l4 = new ArrayList<>();
    l4.add("A4");
    l4.add("B4");
    TStream<String> s4 = topology.constants(l4);
    assertNotSame(s1, s2);
    TStream<String> su = s1.union(s2);
    assertNotSame(su, s1);
    assertNotSame(su, s2);
    // Merge with two different schema types
    // but the primary has the correct direct type.
    su = su.union(s3);
    assertEquals(String.class, su.getTupleClass());
    assertEquals(String.class, su.getTupleType());
    // Merge with two different schema types
    // but the primary has the generic type
    assertNull(s4.getTupleClass());
    su = s4.union(su);
    assertEquals(String.class, su.getTupleClass());
    assertEquals(String.class, su.getTupleType());
    // TODO - testing doesn't work against union streams in embedded.
    su = su.filter(new AllowAll<String>());
    Tester tester = topology.getTester();
    Condition<Long> suCount = tester.tupleCount(su, 12);
    Condition<List<String>> suContents = tester.stringContentsUnordered(su, "A1", "B1", "C1", "D1", "A2", "B2", "C2", "D2", "A3", "B3", "A4", "B4");
    //assertTrue(complete(tester, suCount, 10, TimeUnit.SECONDS));
    complete(tester, suCount, 10, TimeUnit.SECONDS);
    assertTrue("SU:" + suContents, suContents.valid());
    assertTrue("SU:" + suCount, suCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) AllowAll(com.ibm.streamsx.topology.test.AllowAll) ArrayList(java.util.ArrayList) 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 29 with Tester

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

the class StreamTest method testFunctionContextNonDistributed.

@Test
public void testFunctionContextNonDistributed() throws Exception {
    assumeTrue(getTesterType() != Type.DISTRIBUTED_TESTER);
    Topology t = newTopology();
    TStream<Map<String, Object>> values = BeaconStreams.single(t).transform(new ExtractFunctionContext());
    TStream<String> strings = StringStreams.toString(CollectionStreams.flattenMap(values));
    Tester tester = t.getTester();
    Condition<Long> spCount = tester.tupleCount(strings, 9);
    Condition<List<String>> spContents = tester.stringContents(strings, "channel=-1", "domainId=" + System.getProperty("user.name"), "id=0", "instanceId=" + System.getProperty("user.name"), "jobId=0", "jobName=NOTNULL", "maxChannels=0", "noAppConfig={}", "relaunchCount=0");
    complete(tester, spCount, 60, TimeUnit.SECONDS);
    // assertTrue("SU:" + suContents, suContents.valid());
    assertTrue("SP:" + spCount, spCount.valid());
    assertTrue("SPContents:" + spContents, spContents.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) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 30 with Tester

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

the class WindowTest method testPeriodicAggregateLastSeconds.

/**
     * Test a periodic aggregation.
     */
@Test
public void testPeriodicAggregateLastSeconds() throws Exception {
    final Topology t = newTopology();
    TStream<String> source = t.periodicSource(new PeriodicStrings(), 100, TimeUnit.MILLISECONDS);
    TStream<JSONObject> aggregate = source.last(3, TimeUnit.SECONDS).aggregate(new AggregateStrings(), 1, TimeUnit.SECONDS);
    TStream<String> strings = JSONStreams.serialize(aggregate);
    Tester tester = t.getTester();
    Condition<List<String>> contents = tester.stringContents(strings);
    // 10 tuples per second, aggregate every second, so 15 seconds is around 15 tuples.
    Condition<Long> ending = tester.atLeastTupleCount(strings, 15);
    complete(tester, ending, 30, TimeUnit.SECONDS);
    assertTrue(ending.valid());
    long startTs = 0;
    for (String output : contents.getResult()) {
        JSONObject agg = JSONObject.parse(output);
        JSONArray items = (JSONArray) agg.get("items");
        long ts = (Long) agg.get("ts");
        // Should see around 30 tuples per window, once we
        // pass the first three seconds.
        assertTrue("Number of tuples in window:" + items.size(), items.size() <= 45);
        if (agg.containsKey("delta")) {
            long delta = (Long) agg.get("delta");
            assertTrue(delta >= 0);
            assertTrue("timeBetweenAggs: " + delta, delta > 800 && delta < 1200);
            if (startTs == 0) {
                startTs = ts;
            } else {
                long diff = ts - startTs;
                if (diff > 3000)
                    assertTrue("Number of tuples in window:" + items.size(), items.size() >= 25);
            }
        }
    }
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) JSONArray(com.ibm.json.java.JSONArray) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) JSONObject(com.ibm.json.java.JSONObject) 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