Search in sources :

Example 61 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class EndParallelTest method testInvalidEndParallel.

@Test
public void testInvalidEndParallel() throws Exception {
    Topology topology = newTopology("endParallel");
    TStream<String> stream = topology.constants(Arrays.asList("Boom!"));
    // endParallel() on a stream that's not parallel
    stream.endParallel();
    // should not generate invalid SPL
    this.getConfig().put(com.ibm.streamsx.topology.context.ContextProperties.KEEP_ARTIFACTS, Boolean.TRUE);
    StreamsContextFactory.getStreamsContext(StreamsContext.Type.STANDALONE_TESTER).submit(topology).get();
}
Also used : Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 62 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class SPLOperatorsTest method _testSCoptions.

private void _testSCoptions(Object options, String e1, String e2) throws Exception {
    Topology topology = new Topology("testSCoptions");
    SPLStream single = SPLStreams.stringToSPLStream(topology.constants(Collections.singletonList("A")));
    SPL.addToolkit(topology, new File(getTestRoot(), "spl/testtk"));
    TStream<String> output = SPL.invokeOperator("SCO", "testspl::ScOptionTester", single, single.getSchema(), Collections.emptyMap()).toStringStream();
    if (options != null)
        this.getConfig().put(ContextProperties.SC_OPTIONS, options);
    Tester tester = topology.getTester();
    Condition<Long> optC = tester.tupleCount(output, 2);
    Condition<List<String>> optV = tester.stringContents(output, e1, e2);
    complete(tester, optC, 10, TimeUnit.SECONDS);
    assertTrue(optC.toString(), optC.valid());
    assertTrue(optV.toString(), optV.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) RString(com.ibm.streams.operator.types.RString) File(java.io.File) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Example 63 with Topology

use of com.ibm.streamsx.topology.Topology 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"));
    SPL.addToolkitDependency(tuples, "com.ibm.streamsx.topology.testing.testtk", "0.9.9");
    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) RString(com.ibm.streams.operator.types.RString) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) JsonObject(com.google.gson.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 64 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testConversionToSPLWithSkip.

@Test
public void testConversionToSPLWithSkip() throws Exception {
    final Topology topology = new Topology("ConvertSPLStream");
    SPLStream splStream = createSPLFlowFromStream(topology, true);
    TStream<String> tupleString = splStream.toTupleString();
    completeAndValidate(tupleString, 10, "{ii=418,ss=\"325\"}", "{ii=9418,ss=\"9325\"}");
}
Also used : 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 65 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testParameterizedConversionToSPL.

@Test
public void testParameterizedConversionToSPL() throws Exception {
    final Topology topology = new Topology();
    List<List<String>> data = new ArrayList<>();
    data.add(Collections.singletonList("fix"));
    data.add(Arrays.asList(new String[] { "bug", "164" }));
    TStream<List<String>> s = topology.constants(data);
    TStream<String> tupleString = convertListToSPL(s).toTupleString();
    completeAndValidate(tupleString, 10, "{lrs=[\"fix\"]}", "{lrs=[\"bug\",\"164\"]}");
}
Also used : 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)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)372 TestTopology (com.ibm.streamsx.topology.test.TestTopology)315 Test (org.junit.Test)301 List (java.util.List)116 Tester (com.ibm.streamsx.topology.tester.Tester)115 ArrayList (java.util.ArrayList)70 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)68 HashMap (java.util.HashMap)49 TStream (com.ibm.streamsx.topology.TStream)42 Condition (com.ibm.streamsx.topology.tester.Condition)28 File (java.io.File)27 TimeUnit (java.util.concurrent.TimeUnit)27 StreamSchema (com.ibm.streams.operator.StreamSchema)26 Random (java.util.Random)26 JSONObject (com.ibm.json.java.JSONObject)23 HashSet (java.util.HashSet)23 RString (com.ibm.streams.operator.types.RString)21 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)21 Message (com.ibm.streamsx.topology.tuple.Message)20 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)20