Search in sources :

Example 31 with Tester

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

the class WindowTest method testPeriodicAggregateLastMicroseconds.

/**
     * Test a periodic aggregation with microsecond aggregation.
     * Basically a test that the application runs, hard to test
     * for specific results for such a short window.
     */
@Test
@Ignore("Java SPL not supporting small window sizes")
public void testPeriodicAggregateLastMicroseconds() throws Exception {
    // Embedded doesn't support window sizes < 1ms (see issue #211)
    assumeTrue(!isEmbedded());
    final Topology t = newTopology();
    TStream<String> source = t.periodicSource(new PeriodicStrings(), 10, TimeUnit.MILLISECONDS);
    TStream<JSONObject> aggregate = source.last(3, TimeUnit.MICROSECONDS).aggregate(new AggregateStrings(), 10, TimeUnit.MICROSECONDS);
    TStream<String> strings = JSONStreams.serialize(aggregate);
    Tester tester = t.getTester();
    // Aggregate 10 microseconds, so 2 seconds is around 200,000 tuples.
    Condition<Long> ending = tester.atLeastTupleCount(strings, 200_000);
    complete(tester, ending, 30, TimeUnit.SECONDS);
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with Tester

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

the class SimpleEmbeddedTest method testSimple.

@Test
public void testSimple() throws Exception {
    Topology topology = new Topology("testSimple");
    TStream<String> hw = topology.strings("Hello", "World!", "Test!!");
    SPLStream hws = SPLStreams.stringToSPLStream(hw);
    Tester tester = topology.getTester();
    StreamCounter<Tuple> counter = tester.splHandler(hws, new StreamCounter<Tuple>());
    StreamCollector<LinkedList<Tuple>, Tuple> collector = tester.splHandler(hws, StreamCollector.newLinkedListCollector());
    StreamsContextFactory.getStreamsContext(StreamsContext.Type.EMBEDDED_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));
}
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 33 with Tester

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

the class PublishSubscribeUDPTest method completeAndValidateUnordered.

public void completeAndValidateUnordered(TStream<String> output, int seconds, String... contents) throws Exception {
    Tester tester = output.topology().getTester();
    Condition<List<String>> expectedContents = tester.stringContentsUnordered(output, contents);
    tester.complete(getTesterContext(), getConfig(), expectedContents, seconds + getStartupDelay(), TimeUnit.SECONDS);
    assertTrue(expectedContents.toString(), expectedContents.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with Tester

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

the class BeaconTest method testLongFixedCount.

@Test
public void testLongFixedCount() throws Exception {
    Topology topology = new Topology("testLongFixedCount");
    final int count = 7;
    TStream<Long> fb = BeaconStreams.longBeacon(topology, count);
    TStream<String> fs = StringStreams.toString(fb);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(fs, count);
    Condition<List<String>> expectedContents = tester.stringContents(fs, "0", "1", "2", "3", "4", "5", "6");
    complete(tester, expectedCount, 20, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(expectedContents.valid());
}
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) Test(org.junit.Test)

Example 35 with Tester

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

the class PythonFunctionalOperatorsTest method testPositionalSampleNoop.

@Test
public void testPositionalSampleNoop() throws Exception {
    Topology topology = new Topology("testPositionalSampleNoop");
    addTestToolkit(topology);
    SPLStream tuples = testTupleStream(topology);
    SPLStream viaSPL = SPL.invokeOperator("spl.relational::Functor", tuples, tuples.getSchema(), null);
    SPLStream viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.positional::Noop", tuples, tuples.getSchema(), null);
    // Only supported for Python 3.5 and Streams 4.2 and later
    if ((getVersion().getVersion() > 4) || (getVersion().getVersion() == 4 && getVersion().getRelease() >= 2)) {
        viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pytest.pyec::TestOperatorContext", viaPython, viaPython.getSchema(), null);
        viaPython = SPL.invokeOperator("com.ibm.streamsx.topology.pytest.pyec::PyTestMetrics", viaPython, viaPython.getSchema(), null);
    }
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(viaPython, TUPLE_COUNT);
    Condition<List<Tuple>> viaSPLResult = tester.tupleContents(viaSPL);
    Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPython);
    complete(tester, expectedCount, 60, TimeUnit.SECONDS);
    assertTrue(expectedCount.getResult().toString(), expectedCount.valid());
    assertEquals(viaSPLResult.getResult(), viaPythonResult.getResult());
}
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) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) 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