Search in sources :

Example 16 with Tester

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

the class SPLOperatorsTest method testSPLOperatorMultipleOuptuts.

/**
     * Test we can invoke an SPL operator.
     */
@Test
public void testSPLOperatorMultipleOuptuts() throws Exception {
    Topology topology = new Topology();
    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"));
    List<SPLStream> outputs = SPL.invokeOperator(topology, "testSPLOperatorMultipleOuptuts", "testspl::Int32FilterPF", Collections.singletonList(tuples), Collections.nCopies(2, tuples.getSchema()), params);
    SPLStream int32Filtered = outputs.get(0);
    SPLStream int32Dropped = outputs.get(1);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(int32Dropped, 2);
    Condition<List<Tuple>> expectedTuples = tester.tupleContents(int32Filtered, SPLStreamsTest.TEST_TUPLES[0], SPLStreamsTest.TEST_TUPLES[2]);
    Condition<List<Tuple>> droppedTuples = tester.tupleContents(int32Dropped, SPLStreamsTest.TEST_TUPLES[1], SPLStreamsTest.TEST_TUPLES[3]);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
    assertTrue(expectedTuples.toString(), expectedTuples.valid());
    assertTrue(droppedTuples.toString(), droppedTuples.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) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) JSONObject(com.ibm.json.java.JSONObject) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 17 with Tester

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

the class PythonFunctionalOperatorsKwargsTest method testFilterOptionalOutput.

@Test
public void testFilterOptionalOutput() throws Exception {
    Topology topology = new Topology("testFilterOptionalOutput");
    SPLStream tuples = sampleFilterStream(topology);
    PythonFunctionalOperatorsTest.addTestToolkit(tuples);
    List<SPLStream> filtered = SPL.invokeOperator(topology, "CFOpt", "com.ibm.streamsx.topology.pysamples.kwargs::ContainsFilter", Collections.singletonList(tuples), Collections.nCopies(2, tuples.getSchema()), Collections.singletonMap("term", "23"));
    SPLStream pass = filtered.get(0);
    SPLStream failed = filtered.get(1);
    Tester tester = topology.getTester();
    Condition<Long> expectedPassCount = tester.tupleCount(pass, 2);
    Condition<Long> expectedFailedCount = tester.tupleCount(failed, 2);
    Condition<List<Tuple>> passResult = tester.tupleContents(pass);
    Condition<List<Tuple>> failedResult = tester.tupleContents(failed);
    getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    complete(tester, expectedPassCount.and(expectedFailedCount), 10, TimeUnit.SECONDS);
    assertEquals(TEST_TUPLES[1], passResult.getResult().get(0));
    assertEquals(TEST_TUPLES[3], passResult.getResult().get(1));
    assertEquals(TEST_TUPLES[0], failedResult.getResult().get(0));
    assertEquals(TEST_TUPLES[2], failedResult.getResult().get(1));
}
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)

Example 18 with Tester

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

the class PythonFunctionalOperatorsKwargsTest method testMap.

@Test
public void testMap() throws Exception {
    Topology topology = new Topology("testMap");
    SPLStream tuples = sampleFilterStream(topology);
    PythonFunctionalOperatorsTest.addTestToolkit(tuples);
    SPLStream mapped = SPL.invokeOperator("Mp", "com.ibm.streamsx.topology.pytest.pymap::OffByOne", tuples, tuples.getSchema(), null);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(mapped, 3);
    Condition<List<Tuple>> result = tester.tupleContents(mapped, TEST_TUPLES[0], TEST_TUPLES[1], TEST_TUPLES[2]);
    getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(result.getResult().toString(), result.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) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 19 with Tester

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

the class PythonFunctionalOperatorsKwargsTest method testFilter.

@Test
public void testFilter() throws Exception {
    Topology topology = new Topology("testFilter");
    SPLStream tuples = sampleFilterStream(topology);
    PythonFunctionalOperatorsTest.addTestToolkit(tuples);
    SPLStream pass = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.kwargs::ContainsFilter", tuples, tuples.getSchema(), Collections.singletonMap("term", "23"));
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(pass, 2);
    Condition<List<Tuple>> passResult = tester.tupleContents(pass);
    this.getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertEquals(TEST_TUPLES[1], passResult.getResult().get(0));
    assertEquals(TEST_TUPLES[3], passResult.getResult().get(1));
    assertTrue(expectedCount.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) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 20 with Tester

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

the class SPLStreamsTest method testTuples.

@Test
public void testTuples() throws Exception {
    Topology topology = new Topology("testTuples");
    SPLStream tuples = testTupleStream(topology);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(tuples, TEST_TUPLES.length);
    Condition<List<Tuple>> expectedTuples = tester.tupleContents(tuples, TEST_TUPLES);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(expectedTuples.toString(), expectedTuples.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) 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