use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SPLValue method toJSON.
public JSONObject toJSON() {
// meet the requirements of BOperatorInvocation.setParameter()
/*
* The Value object is
* <pre><code>
* object {
* type : "__spl_value"
* value : object {
* value : any. non-null. type appropriate for metaType
* metaType : com.ibm.streams.operator.Type.MetaType.name() string
* }
* }
* </code></pre>
*/
JSONObject jo = new JSONObject();
JSONObject jv = new JSONObject();
jo.put("type", "__spl_value");
jo.put("value", jv);
jv.put("metaType", metaType.name());
jv.put("value", value);
return jo;
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class PlaceableTest method getColocate.
private static String getColocate(BOperator bop) {
JSONObject placement = JOperatorConfig.getJSONItem(bop.json(), PLACEMENT);
if (placement == null)
return null;
Object ido = placement.get(PLACEMENT_EXPLICIT_COLOCATE_ID);
if (ido == null)
return null;
return ido.toString();
}
use of com.ibm.json.java.JSONObject 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);
}
}
}
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class WindowTest method testPeriodicAggregateLastMicroseconds.
/**
* Test a periodic aggregation with microsecond aggregation.
* Basically a test that the application runs, hard to test
* for specific results for such a short window.
*/
@Test
@Ignore("Java SPL not supporting small window sizes")
public void testPeriodicAggregateLastMicroseconds() throws Exception {
// Embedded doesn't support window sizes < 1ms (see issue #211)
assumeTrue(!isEmbedded());
final Topology t = newTopology();
TStream<String> source = t.periodicSource(new PeriodicStrings(), 10, TimeUnit.MILLISECONDS);
TStream<JSONObject> aggregate = source.last(3, TimeUnit.MICROSECONDS).aggregate(new AggregateStrings(), 10, TimeUnit.MICROSECONDS);
TStream<String> strings = JSONStreams.serialize(aggregate);
Tester tester = t.getTester();
// Aggregate 10 microseconds, so 2 seconds is around 200,000 tuples.
Condition<Long> ending = tester.atLeastTupleCount(strings, 200_000);
complete(tester, ending, 30, TimeUnit.SECONDS);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class PublishSubscribeJsonPythonTest method testPublishJsonMap.
/**
* Json Subscribe feeding a map
*/
@Test
public void testPublishJsonMap() throws Exception {
Random r = new Random();
final Topology t = new Topology();
JSONObject j1 = new JSONObject();
j1.put("a", r.nextLong());
j1.put("b", "Hello:" + r.nextInt(200));
JSONObject j2 = new JSONObject();
j2.put("a", r.nextLong());
j2.put("b", "Goodbye:" + r.nextInt(200));
JSONObject j3 = new JSONObject();
j3.put("a", r.nextLong());
j3.put("b", "So long:" + r.nextInt(200));
String s1 = "R" + j1.get("a") + "X" + j1.get("b") + "X" + (((Long) j1.get("a")) + 235L);
String s2 = "R" + j2.get("a") + "X" + j2.get("b") + "X" + (((Long) j2.get("a")) + 235L);
String s3 = "R" + j3.get("a") + "X" + j3.get("b") + "X" + (((Long) j3.get("a")) + 235L);
includePythonApp(t, "json_map_json.py", "json_map_json::json_map_json");
TStream<JSONObject> source = t.constants(Arrays.asList(j1, j2, j3));
source = addStartupDelay(source).asType(JSONObject.class);
source.publish("pytest/json/map");
TStream<JSONObject> subscribe = t.subscribe("pytest/json/map/result", JSONObject.class);
TStream<String> asString = subscribe.transform(j -> "R" + j.get("a") + "X" + j.get("b") + "X" + j.get("c"));
completeAndValidate(asString, 30, s1, s2, s3);
}
Aggregations