Search in sources :

Example 66 with Topology

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

Example 67 with Topology

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

the class InvokerTest method testParallelHashSerializersWithVirtuals.

@Test
public void testParallelHashSerializersWithVirtuals() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology();
    SPL.addToolkit(topology, new File(getTestRoot(), "spl/testtk"));
    JsonObject sname = new JsonObject();
    sname.addProperty("name", "S1");
    TStream<Byte> s = Invoker.invokeSource(topology, JavaFunctionalOps.SOURCE_KIND, sname, new ByteData(), Byte.class, new ByteSerializer(), null);
    JsonObject sname2 = new JsonObject();
    sname2.addProperty("name", "S2");
    TStream<Byte> s2 = Invoker.invokeSource(topology, JavaFunctionalOps.SOURCE_KIND, sname2, new ByteData(), Byte.class, new ByteSerializer(), null);
    s = s.union(s2);
    s = s.isolate();
    s = s.autonomous();
    s = s.lowLatency();
    JsonObject llname = new JsonObject();
    llname.addProperty("name", "LL");
    @SuppressWarnings("unchecked") TStream<Byte> ll = (TStream<Byte>) Invoker.invokePipe("testjava::MyPipe", s, llname, new ByteAdder(3), Byte.class, new ByteSerializer(), new ByteSerializer(), null);
    s = ll.endLowLatency();
    s = s.parallel(() -> 3, Routing.HASH_PARTITIONED);
    JsonObject pname = new JsonObject();
    pname.addProperty("name", "P");
    @SuppressWarnings("unchecked") TStream<Byte> sp = (TStream<Byte>) Invoker.invokePipe("testjava::MyPipe", s, pname, new ByteAdder(29), Byte.class, new ByteSerializer(), new ByteSerializer(), null);
    sp = sp.endParallel();
    JsonObject fname = new JsonObject();
    fname.addProperty("name", "F");
    @SuppressWarnings("unchecked") TStream<Byte> fsp = (TStream<Byte>) Invoker.invokePipe("testjava::MyPipe", sp, pname, new ByteAdder(0), Byte.class, new ByteSerializer(), null, null);
    TStream<String> ss = StringStreams.toString(fsp);
    Tester tester = topology.getTester();
    Condition<List<String>> contents = tester.stringContentsUnordered(ss, "33", "49", "125", "-11", "33", "49", "125", "-11");
    Condition<Long> count = tester.tupleCount(ss, 8);
    complete(topology.getTester(), count, 10, TimeUnit.SECONDS);
    assertTrue(count.valid());
    assertTrue(contents.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) JsonObject(com.google.gson.JsonObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) TStream(com.ibm.streamsx.topology.TStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 68 with Topology

use of com.ibm.streamsx.topology.Topology 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 69 with Topology

use of com.ibm.streamsx.topology.Topology 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 70 with Topology

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

the class SPLParallelTest method testRoundRobin.

@Test
public void testRoundRobin() throws Exception {
    Topology topology = newTopology();
    TStream<String> values = topology.strings("UDP-RR", "@parallel-RR", "Done-RR");
    StreamSchema schema = com.ibm.streams.operator.Type.Factory.getStreamSchema("tuple<rstring x>");
    SPLStream vs = SPLStreams.convertStream(values, (s, o) -> {
        o.setString(0, s);
        return o;
    }, schema);
    vs = vs.parallel(() -> 3, Routing.ROUND_ROBIN);
    SPLStream r = vs.filter(new AllowAll<>()).endParallel();
    TStream<String> rs = SPLStreams.toStringStream(r);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(r, 3);
    Condition<List<String>> content = tester.stringContentsUnordered(rs, "UDP-RR", "@parallel-RR", "Done-RR");
    assertTrue(complete(tester, expectedCount, 20, TimeUnit.SECONDS));
    assertTrue(content.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) AllowAll(com.ibm.streamsx.topology.test.AllowAll) LinkedList(java.util.LinkedList) 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) 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