Search in sources :

Example 56 with Topology

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

the class PublishSubscribeTest method testFilterOnBlob.

@Test(expected = IllegalArgumentException.class)
public void testFilterOnBlob() throws Exception {
    final Topology t = new Topology();
    TStream<Blob> blobs = t.constants(Collections.<Blob>emptyList()).asType(Blob.class);
    blobs.publish("sometopic", true);
}
Also used : Blob(com.ibm.streams.operator.types.Blob) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 57 with Topology

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

the class PublishSubscribeUDPTest method testObjectPublishBothSubscribeNonUDP.

@Test
public void testObjectPublishBothSubscribeNonUDP() throws Exception {
    String topic = uniqueTopic("testObjectPublishBothSubscribeNonUDP");
    Random r = new Random();
    List<BigDecimal> data = new ArrayList<>(20);
    for (int i = 0; i < 20; i++) data.add(new BigDecimal(r.nextDouble() * 100.0));
    final Topology t = new Topology();
    TStream<BigDecimal> source = t.constants(data);
    source = addStartupDelay(source).asType(BigDecimal.class);
    source = source.parallel(4);
    source.publish(topic);
    List<BigDecimal> data2 = new ArrayList<>(10);
    for (int i = 0; i < 10; i++) data2.add(new BigDecimal(r.nextDouble() * 100.0));
    TStream<BigDecimal> source2 = t.constants(data2);
    source2 = addStartupDelay(source2);
    source2.asType(BigDecimal.class).publish(topic);
    TStream<BigDecimal> subscribe = t.subscribe(topic, BigDecimal.class);
    TStream<String> strings = StringStreams.toString(subscribe);
    List<String> expected = new ArrayList<>();
    for (BigDecimal d : data) expected.add(d.toString());
    for (BigDecimal d : data2) expected.add(d.toString());
    completeAndValidateUnordered(strings, 40, expected.toArray(new String[0]));
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 58 with Topology

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

the class PublishSubscribeUDPTest method testPublishUDPSubscribeUDP.

private void testPublishUDPSubscribeUDP(int pwidth, int swidth) throws Exception {
    String topic = uniqueTopic("testPublishUDPSubscribeUDP/" + pwidth);
    String[] data = new String[100];
    for (int i = 0; i < data.length; i++) {
        data[i] = "SubUDP" + i;
    }
    final Topology t = new Topology();
    SPL.addToolkit(t, new File(getTestRoot(), "spl/testtk"));
    TStream<String> source = t.strings(data);
    source = addStartupDelay(source);
    if (pwidth > 0)
        source = source.parallel(pwidth);
    source.publish(topic);
    Map<String, Object> params = new HashMap<>();
    params.put("width", swidth);
    params.put("topic", topic);
    SPLStream subscribe = SPL.invokeSource(t, "testspl::UDPStringSub", params, SPLSchemas.STRING);
    completeAndValidateUnordered(subscribe.toStringStream(), 30, data);
}
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)

Example 59 with Topology

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

the class PublishSubscribeUDPTest method testPublishUDPSubscribeNonUDP.

private void testPublishUDPSubscribeNonUDP(int width) throws Exception {
    String topic = uniqueTopic("testPublishUDPSubscribeNonUDP/" + width);
    final Topology t = new Topology();
    TStream<String> source = t.strings("325", "457", "9325", "hello", "udp");
    source = addStartupDelay(source);
    if (width > 0)
        source = source.parallel(width);
    source.publish(topic);
    TStream<String> subscribe = t.subscribe(topic, String.class);
    completeAndValidateUnordered(subscribe, 20, "325", "457", "9325", "hello", "udp");
}
Also used : Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology)

Example 60 with Topology

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

the class VwapTest method testVwap.

@Test
public void testVwap() throws Exception {
    // Invokes an SPL operator so cannot run in embedded.
    assumeSPLOk();
    TStream<Bargain> bargains = Vwap.createVwapTopology();
    bargains = Vwap.realBargains(bargains);
    Topology topology = bargains.topology();
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.atLeastTupleCount(bargains, 2200);
    complete(tester, expectedCount, 120, TimeUnit.SECONDS);
    assertTrue(expectedCount.toString(), expectedCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Bargain(vwap.Bargain) 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