use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class PublishSubscribeTest method testFilterOnJson.
@Test(expected = IllegalArgumentException.class)
public void testFilterOnJson() throws Exception {
final Topology t = new Topology();
TStream<JSONObject> json = t.constants(Collections.<JSONObject>emptyList()).asType(JSONObject.class);
;
json.publish("sometopic", true);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SPLOperatorsTest method pvToStr.
private String pvToStr(JSONObject jo) {
// A Client of the API shouldn't find itself in
// a place to need this. It's just an artifact of
// the way these tests are composed plus lack of a
// public form of valueToString(SPL.createValue(...)).
String type = (String) jo.get("type");
if (!"__spl_value".equals(type))
throw new IllegalArgumentException("jo " + jo);
JSONObject value = (JSONObject) jo.get("value");
String metaType = (String) value.get("metaType");
Object v = value.get("value");
if (metaType.startsWith("UINT"))
return SPLGenerator.unsignedString(v);
else
return v.toString();
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class BeaconTest method testBeaconTuples.
@Test
public void testBeaconTuples() throws Exception {
Topology topology = new Topology("testFixedCount");
final int count = new Random().nextInt(1000) + 37;
TStream<BeaconTuple> beacon = BeaconStreams.beacon(topology, count);
TStream<JSONObject> json = JSONStreams.toJSON(beacon);
TStream<String> strings = JSONStreams.serialize(json);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(strings, count);
@SuppressWarnings("serial") Condition<String> contents = tester.stringTupleTester(strings, new Predicate<String>() {
private transient BeaconTuple lastTuple;
@Override
public boolean test(String tuple) {
JSONObject json;
try {
json = (JSONObject) JSON.parse(tuple);
} catch (NullPointerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
BeaconTuple bt = new BeaconTuple((Long) json.get("sequence"), (Long) json.get("time"));
boolean ok;
if (lastTuple == null) {
ok = bt.getSequence() == 0;
} else {
ok = lastTuple.compareTo(bt) < 0 && lastTuple.getTime() <= bt.getTime() && lastTuple.getSequence() + 1 == bt.getSequence();
}
ok = ok && bt.getTime() != 0;
ok = ok && bt.getKey() == bt.getSequence();
lastTuple = bt;
return ok;
}
});
complete(tester, expectedCount, 20, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(contents.toString(), contents.valid());
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class PlacementInfo method disallowColocateIsolatedOpWithParent.
/** throw if s1.isolate().filter().colocate(s1) */
private void disallowColocateIsolatedOpWithParent(Placeable<?> first, Placeable<?>... toFuse) {
JSONObject graph = first.builder().complete();
JSONObject colocateOp = first.operator().complete();
Set<JsonObject> parents = GraphUtilities.getUpstream(JSON4JUtilities.gson(colocateOp), JSON4JUtilities.gson(graph));
if (!parents.isEmpty()) {
JsonObject isolate = parents.iterator().next();
String kind = jstring(isolate, "kind");
if (!ISOLATE.kind().equals(kind))
return;
parents = GraphUtilities.getUpstream(isolate, JSON4JUtilities.gson(graph));
if (parents.isEmpty())
return;
JsonObject isolateParentOp = parents.iterator().next();
for (Placeable<?> placeable : toFuse) {
JSONObject tgtOp = placeable.operator().complete();
if (tgtOp.get("name").equals(jstring(isolateParentOp, "name")))
throw new IllegalStateException("Illegal to colocate an isolated stream with its parent.");
}
}
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class PlacementInfo method updatePlacementJSON.
/**
* Update an element's placement configuration.
*/
private void updatePlacementJSON(Placeable<?> element) {
JSONObject placement = JOperatorConfig.createJSONItem(element.operator().json(), PLACEMENT);
placement.put(PLACEMENT_EXPLICIT_COLOCATE_ID, fusingIds.get(element));
Set<String> elementResourceTags = resourceTags.get(element);
if (elementResourceTags != null && !elementResourceTags.isEmpty()) {
JSONArray listOfTags = new JSONArray();
listOfTags.addAll(elementResourceTags);
placement.put(PLACEMENT_RESOURCE_TAGS, listOfTags);
}
}
Aggregations