Search in sources :

Example 6 with JSONArray

use of com.ibm.json.java.JSONArray in project streamsx.topology by IBMStreams.

the class BInputPort method complete.

/**
     * Add this port information and its connections to output ports, by name.
     */
@Override
public JSONObject complete() {
    final JSONObject json = json();
    BUtils.addPortInfo(json, port);
    JSONArray conns = new JSONArray();
    for (StreamConnection c : port().getConnections()) {
        conns.add(c.getOutput().getName());
    }
    json.put("connections", conns);
    return json;
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) StreamConnection(com.ibm.streams.flow.declare.StreamConnection)

Example 7 with JSONArray

use of com.ibm.json.java.JSONArray in project streamsx.topology by IBMStreams.

the class BOperator method complete.

@Override
public JSONObject complete() {
    JSONObject json = super.complete();
    if (regions != null) {
        JSONArray ra = new JSONArray();
        ra.addAll(regions);
        json.put("regions", ra);
    }
    return json;
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray)

Example 8 with JSONArray

use of com.ibm.json.java.JSONArray in project streamsx.topology by IBMStreams.

the class BOutputPort method complete.

@Override
public JSONObject complete() {
    final JSONObject json = json();
    BUtils.addPortInfo(json, port);
    JSONArray conns = new JSONArray();
    for (StreamConnection c : port().getConnections()) {
        conns.add(c.getInput().getName());
    }
    json.put("connections", conns);
    return json;
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) StreamConnection(com.ibm.streams.flow.declare.StreamConnection)

Example 9 with JSONArray

use of com.ibm.json.java.JSONArray in project streamsx.topology by IBMStreams.

the class BOperatorInvocation method complete.

@Override
public JSONObject complete() {
    final JSONObject json = super.complete();
    if (outputs != null) {
        JSONArray oa = new JSONArray(outputs.size());
        for (BOutputPort output : outputs) {
            oa.add(output.complete());
        }
        json.put("outputs", oa);
    }
    if (inputs != null) {
        JSONArray ia = new JSONArray(inputs.size());
        for (BInputPort input : inputs) {
            ia.add(input.complete());
        }
        json.put("inputs", ia);
    }
    return json;
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray)

Example 10 with JSONArray

use of com.ibm.json.java.JSONArray in project streamsx.topology by IBMStreams.

the class WindowTest method testPeriodicAggregateLastSeconds.

/**
     * Test a periodic aggregation.
     */
@Test
public void testPeriodicAggregateLastSeconds() throws Exception {
    final Topology t = newTopology();
    TStream<String> source = t.periodicSource(new PeriodicStrings(), 100, TimeUnit.MILLISECONDS);
    TStream<JSONObject> aggregate = source.last(3, TimeUnit.SECONDS).aggregate(new AggregateStrings(), 1, TimeUnit.SECONDS);
    TStream<String> strings = JSONStreams.serialize(aggregate);
    Tester tester = t.getTester();
    Condition<List<String>> contents = tester.stringContents(strings);
    // 10 tuples per second, aggregate every second, so 15 seconds is around 15 tuples.
    Condition<Long> ending = tester.atLeastTupleCount(strings, 15);
    complete(tester, ending, 30, TimeUnit.SECONDS);
    assertTrue(ending.valid());
    long startTs = 0;
    for (String output : contents.getResult()) {
        JSONObject agg = JSONObject.parse(output);
        JSONArray items = (JSONArray) agg.get("items");
        long ts = (Long) agg.get("ts");
        // Should see around 30 tuples per window, once we
        // pass the first three seconds.
        assertTrue("Number of tuples in window:" + items.size(), items.size() <= 45);
        if (agg.containsKey("delta")) {
            long delta = (Long) agg.get("delta");
            assertTrue(delta >= 0);
            assertTrue("timeBetweenAggs: " + delta, delta > 800 && delta < 1200);
            if (startTs == 0) {
                startTs = ts;
            } else {
                long diff = ts - startTs;
                if (diff > 3000)
                    assertTrue("Number of tuples in window:" + items.size(), items.size() >= 25);
            }
        }
    }
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) JSONArray(com.ibm.json.java.JSONArray) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) JSONObject(com.ibm.json.java.JSONObject) List(java.util.List) Test(org.junit.Test)

Aggregations

JSONArray (com.ibm.json.java.JSONArray)20 JSONObject (com.ibm.json.java.JSONObject)19 Topology (com.ibm.streamsx.topology.Topology)7 Test (org.junit.Test)7 TestTopology (com.ibm.streamsx.topology.test.TestTopology)6 Tester (com.ibm.streamsx.topology.tester.Tester)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 StreamConnection (com.ibm.streams.flow.declare.StreamConnection)2 StreamSchema (com.ibm.streams.operator.StreamSchema)2 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)2 JsonObject (com.google.gson.JsonObject)1 OrderedJSONObject (com.ibm.json.java.OrderedJSONObject)1 Attribute (com.ibm.streams.operator.Attribute)1 Tuple (com.ibm.streams.operator.Tuple)1 BInputPort (com.ibm.streamsx.topology.builder.BInputPort)1 BOperator (com.ibm.streamsx.topology.builder.BOperator)1 BOutput (com.ibm.streamsx.topology.builder.BOutput)1 Supplier (com.ibm.streamsx.topology.function.Supplier)1 KeyFunctionHasher (com.ibm.streamsx.topology.internal.logic.KeyFunctionHasher)1