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;
}
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;
}
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;
}
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;
}
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);
}
}
}
}
Aggregations