Search in sources :

Example 21 with Tester

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

the class PythonFunctionalOperatorsTest method testSourceWithClass.

@Test
public void testSourceWithClass() throws Exception {
    Topology topology = new Topology("testSourceWithClass");
    addTestToolkit(topology);
    StreamSchema outSchema = Type.Factory.getStreamSchema("tuple<int32 seq>");
    int count = new Random().nextInt(200) + 10;
    SPLStream pysrc = SPL.invokeSource(topology, "com.ibm.streamsx.topology.pysamples.sources::Range", Collections.singletonMap("count", count), outSchema);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(pysrc, count);
    Condition<List<Tuple>> outTuples = tester.tupleContents(pysrc);
    // getConfig().put(ContextProperties.TRACING_LEVEL, TraceLevel.DEBUG);
    complete(tester, expectedCount, 20, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    List<Tuple> result = outTuples.getResult();
    assertEquals(count, result.size());
    for (int i = 0; i < count; i++) assertEquals(i, result.get(i).getInt("seq"));
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Random(java.util.Random) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) StreamSchema(com.ibm.streams.operator.StreamSchema) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple) Test(org.junit.Test)

Example 22 with Tester

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

the class SimpleStandaloneTest method testTwoStreams.

@Test
public void testTwoStreams() throws Exception {
    Topology topology = new Topology("testTwoStreams");
    TStream<String> hw = topology.strings("Hello", "World!", "Test!!");
    SPLStream hws = SPLStreams.stringToSPLStream(hw);
    TStream<String> hw2 = StringStreams.contains(hw, "e");
    SPLStream hw2s = SPLStreams.stringToSPLStream(hw2);
    Tester tester = topology.getTester();
    StreamCounter<Tuple> counter = tester.splHandler(hws, new StreamCounter<Tuple>());
    StreamCollector<LinkedList<Tuple>, Tuple> collector = tester.splHandler(hws, StreamCollector.newLinkedListCollector());
    StreamCounter<Tuple> counter2 = tester.splHandler(hw2s, new StreamCounter<Tuple>());
    StreamCollector<LinkedList<Tuple>, Tuple> collector2 = tester.splHandler(hw2s, StreamCollector.newLinkedListCollector());
    StreamsContextFactory.getStreamsContext(StreamsContext.Type.STANDALONE_TESTER).submit(topology).get();
    assertEquals(3, counter.getTupleCount());
    assertEquals("Hello", collector.getTuples().get(0).getString(0));
    assertEquals("World!", collector.getTuples().get(1).getString(0));
    assertEquals("Test!!", collector.getTuples().get(2).getString(0));
    assertEquals(2, counter2.getTupleCount());
    assertEquals("Hello", collector2.getTuples().get(0).getString(0));
    assertEquals("Test!!", collector2.getTuples().get(1).getString(0));
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Tuple(com.ibm.streams.operator.Tuple) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 23 with Tester

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

the class FunctionalSubmissionParamsTest method OthersTest.

@Test
@Ignore("Suddenly started failing on jenkins streamsx.topology - but only there (expected 100 got 0). Get the build working again.")
public void OthersTest() throws Exception {
    Topology topology = newTopology("OthersTest");
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    // FunctionFilter op is based on FunctionFunctor and the
    // latter is what knows about submission params.
    // Hence, given the implementation, this test should cover
    // all sub classes (modify,transform,split,sink,window,aggregate...).
    //
    // That really accounts for all functional
    // operators except FunctionSource and FunctionPeriodicSource and
    // we have tests for those.
    //
    // But we really should verify anyway...
    Supplier<Integer> someInt = topology.createSubmissionParameter("someInt", Integer.class);
    Supplier<Integer> someIntD = topology.createSubmissionParameter("someIntD", 2);
    List<Integer> data = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5 });
    TStream<Integer> s = topology.constants(data);
    // The test's functional logic asserts it receives the expected SP value.
    // Its the main form of validation for the test.
    // TStream.modify
    TStream<Integer> modified = s.modify(unaryFn(someInt, 1));
    TStream<Integer> modifiedD = s.modify(unaryFn(someIntD, 2));
    // TStream.transform
    TStream<Integer> xformed = s.transform(functionFn(someInt, 1));
    TStream<Integer> xformedD = s.transform(functionFn(someIntD, 2));
    // TStream.multiTransform
    TStream<Integer> multiXformed = s.multiTransform(functionIterableFn(someInt, 1));
    TStream<Integer> multiXformedD = s.multiTransform(functionIterableFn(someIntD, 2));
    // TStream.join
    TStream<Integer> joined = s.join(s.last(1), biFunctionListFn(someInt, 1));
    TStream<Integer> joinedD = s.join(s.last(1), biFunctionListFn(someIntD, 2));
    TStream<Integer> lastJoined = s.joinLast(s, biFunctionFn(someInt, 1));
    TStream<Integer> lastJoinedD = s.joinLast(s, biFunctionFn(someIntD, 2));
    // TStream.sink
    s.sink(sinkerFn(someInt, 1));
    s.sink(sinkerFn(someIntD, 2));
    // TStream.split
    List<TStream<Integer>> split = s.split(2, toIntFn(someInt, 1));
    TStream<Integer> unionedSplit = split.get(0).union(split.get(1));
    List<TStream<Integer>> splitD = s.split(2, toIntFn(someIntD, 2));
    TStream<Integer> unionedSplitD = splitD.get(0).union(splitD.get(1));
    // TStream.window
    TWindow<Integer, ?> win = s.window(s.last(1).key(functionFn(someInt, 1)));
    TStream<Integer> winAgg = win.aggregate(functionListFn(someIntD, 2));
    TWindow<Integer, ?> winD = s.window(s.last(1).key(functionFn(someInt, 1)));
    TStream<Integer> winAggD = winD.aggregate(functionListFn(someIntD, 2));
    // TWindow.aggregate
    TStream<Integer> agg = s.last(1).aggregate(functionListFn(someInt, 1));
    TStream<Integer> aggD = s.last(1).aggregate(functionListFn(someIntD, 2));
    s.last(1).aggregate(functionListFn(someInt, 1), 1, TimeUnit.MILLISECONDS);
    s.last(1).aggregate(functionListFn(someIntD, 2), 1, TimeUnit.MILLISECONDS);
    // TWindow.key
    TStream<Integer> kagg = s.last(1).key(functionFn(someInt, 1)).aggregate(functionListFn(someIntD, 2));
    TStream<Integer> kaggD = s.last(1).key(functionFn(someInt, 1)).aggregate(functionListFn(someIntD, 2));
    Map<String, Object> params = new HashMap<>();
    params.put("someInt", 1);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    ////////////////////
    Set<TStream<Integer>> all = new HashSet<>(Arrays.asList(modified, modifiedD, xformed, xformedD, multiXformed, multiXformedD, joined, joinedD, lastJoined, lastJoinedD, unionedSplit, unionedSplitD, winAgg, winAggD, agg, aggD, kagg, kaggD));
    TStream<Integer> union = modified.union(all);
    // tester sees 0 tuples when they are really there so...
    union = union.filter(new AllowAll<Integer>());
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(union, all.size() * 5);
    complete(tester, expectedCount, 15, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) 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) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with Tester

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

the class FunctionalSubmissionParamsTest method SourceTest.

@Test
public void SourceTest() throws Exception {
    Topology topology = newTopology("SourceTest");
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    Supplier<Integer> someInt = topology.createSubmissionParameter("someInt", Integer.class);
    Supplier<Integer> someIntD = topology.createSubmissionParameter("someIntD", 20);
    // The test's functional logic asserts it receives the expected SP value.
    TStream<Integer> s = topology.source(sourceIterableSupplier(someInt, 10));
    TStream<Integer> sD = topology.source(sourceIterableSupplier(someIntD, 20));
    Map<String, Object> params = new HashMap<>();
    params.put("someInt", 10);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    ////////////////////
    TStream<Integer> union = s.union(sD);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount1 = tester.tupleCount(s, 5);
    Condition<Long> expectedCount2 = tester.tupleCount(sD, 5);
    Condition<Long> expectedCount3 = tester.tupleCount(union, 10);
    complete(tester, expectedCount3, 15, TimeUnit.SECONDS);
    assertTrue(expectedCount1.toString(), expectedCount1.valid());
    assertTrue(expectedCount2.toString(), expectedCount2.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 25 with Tester

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

the class FunctionalSubmissionParamsTest method FilterTest.

@Test
public void FilterTest() throws Exception {
    Topology topology = newTopology("FilterTest");
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    Supplier<Integer> threshold = topology.createSubmissionParameter("threshold", Integer.class);
    Supplier<Integer> defaultedThreshold = topology.createSubmissionParameter("defaultedThreshold", 2);
    List<Integer> data = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5 });
    TStream<Integer> s = topology.constants(data);
    TStream<Integer> defaultFiltered = s.filter(thresholdFilter(defaultedThreshold));
    TStream<Integer> filtered = s.filter(thresholdFilter(threshold));
    Map<String, Object> params = new HashMap<>();
    params.put("threshold", 3);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    ////////////////////
    TStream<Integer> union = filtered.union(defaultFiltered);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount1 = tester.tupleCount(filtered, 2);
    Condition<Long> expectedCount2 = tester.tupleCount(defaultFiltered, 3);
    Condition<Long> expectedCount3 = tester.tupleCount(union, 5);
    complete(tester, expectedCount3, 15, TimeUnit.SECONDS);
    assertTrue(expectedCount1.toString(), expectedCount1.valid());
    assertTrue(expectedCount2.toString(), expectedCount2.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) 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