Search in sources :

Example 11 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLJavaPrimitiveTest method testIsolatedVmArgs2.

@Test
public void testIsolatedVmArgs2() throws Exception {
    // isolation only works in DISTRIBUTED
    assumeTrue(getTesterType() == StreamsContext.Type.DISTRIBUTED_TESTER);
    assumeTrue(SC_OK);
    Topology t = new Topology("testIsolatedVmArgs1");
    SPL.addToolkit(t, new File(getTestRoot(), "spl/testtk"));
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    SPLStream spl = SPLStreams.stringToSPLStream(t.strings("hello"));
    // isolate the JavaPrimitive to avoid the restriction/failure
    // demonstrated in testIncompatVmArgs
    spl = spl.isolate();
    Map<String, Object> params = new HashMap<>();
    params.put("vmArg", new String[] { "-DXYZZY", "-DFOOBAR" });
    SPLStream splResult = JavaPrimitive.invokeJavaPrimitive(testjava.NoOpJavaPrimitive.class, spl, SPLSchemas.STRING, params);
    splResult = splResult.isolate();
    TStream<String> result = splResult.toStringStream();
    completeAndValidate(result, 10, "hello");
}
Also used : HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) File(java.io.File) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 12 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLJavaPrimitiveTest method testSimpleInvoke.

@Test
public void testSimpleInvoke() throws Exception {
    Topology t = new Topology("testSimpleInvoke");
    SPL.addToolkit(t, new File(getTestRoot(), "spl/testtk"));
    SPLStream spl = SPLStreams.stringToSPLStream(t.strings("hello"));
    SPLStream splResult = JavaPrimitive.invokeJavaPrimitive(testjava.NoOpJavaPrimitive.class, spl, SPLSchemas.STRING, null);
    TStream<String> result = splResult.toStringStream();
    completeAndValidate(result, 10, "hello");
}
Also used : Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) File(java.io.File) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 13 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream 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 14 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream 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 15 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream 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)

Aggregations

SPLStream (com.ibm.streamsx.topology.spl.SPLStream)57 Topology (com.ibm.streamsx.topology.Topology)39 TestTopology (com.ibm.streamsx.topology.test.TestTopology)36 Test (org.junit.Test)32 Tester (com.ibm.streamsx.topology.tester.Tester)20 List (java.util.List)17 Tuple (com.ibm.streams.operator.Tuple)15 HashMap (java.util.HashMap)15 OutputTuple (com.ibm.streams.operator.OutputTuple)10 File (java.io.File)10 JSONObject (com.ibm.json.java.JSONObject)9 StreamSchema (com.ibm.streams.operator.StreamSchema)9 Message (com.ibm.streamsx.topology.tuple.Message)4 LinkedList (java.util.LinkedList)4 Random (java.util.Random)4 TSink (com.ibm.streamsx.topology.TSink)3 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)3 ArrayList (java.util.ArrayList)3 SPLStreamsTest (com.ibm.streamsx.topology.test.spl.SPLStreamsTest)2 Map (java.util.Map)2