use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testStreamCorrectTypes.
private void testStreamCorrectTypes(JsonObject object) {
object.stream().forEach(entry -> {
String key = entry.getKey();
Object val = entry.getValue();
assertEquals("object1", key);
assertTrue("Expecting JsonObject, found: " + val.getClass().getCanonicalName(), val instanceof JsonObject);
});
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testCreateFromMapNestedMap.
@Test
public void testCreateFromMapNestedMap() {
Map<String, Object> map = new HashMap<>();
Map<String, Object> nestedMap = new HashMap<>();
nestedMap.put("foo", "bar");
map.put("nested", nestedMap);
JsonObject obj = new JsonObject(map);
JsonObject nestedRetrieved = obj.getJsonObject("nested");
assertEquals("bar", nestedRetrieved.getString("foo"));
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testCreateFromMap.
@Test
public void testCreateFromMap() {
Map<String, Object> map = new HashMap<>();
map.put("foo", "bar");
map.put("quux", 123);
JsonObject obj = new JsonObject(map);
assertEquals("bar", obj.getString("foo"));
assertEquals(Integer.valueOf(123), obj.getInteger("quux"));
assertSame(map, obj.getMap());
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testMergeInDepth2.
@Test
public void testMergeInDepth2() {
JsonObject obj1 = new JsonObject("{ \"foo\": \"bar\", \"flurb\": { \"eek\": \"foo\", \"bar\": \"flurb\"}}");
JsonObject obj2 = new JsonObject("{ \"flurb\": { \"bar\": \"flurb1\" }}");
obj1.mergeIn(obj2, 2);
assertEquals(2, obj1.size());
assertEquals(2, obj1.getJsonObject("flurb").size());
assertEquals("foo", obj1.getJsonObject("flurb").getString("eek"));
assertEquals("flurb1", obj1.getJsonObject("flurb").getString("bar"));
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class VertxOptionsTest method testJsonOptions.
@Test
public void testJsonOptions() {
VertxOptions options = new VertxOptions(new JsonObject());
assertEquals(0, options.getClusterPort());
assertEquals(-1, options.getClusterPublicPort());
assertEquals(20000, options.getClusterPingInterval());
assertEquals(20000, options.getClusterPingReplyInterval());
assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
assertEquals(20, options.getInternalBlockingPoolSize());
assertEquals(20, options.getWorkerPoolSize());
assertEquals(1000, options.getBlockedThreadCheckInterval());
assertEquals("localhost", options.getClusterHost());
assertNull(options.getClusterPublicHost());
assertEquals(null, options.getClusterManager());
assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
assertFalse(options.isHAEnabled());
assertEquals(1, options.getQuorumSize());
assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
assertNotNull(options.getMetricsOptions());
assertEquals(5000000000l, options.getWarningExceptionTime());
int clusterPort = TestUtils.randomPortInt();
int clusterPublicPort = TestUtils.randomPortInt();
int eventLoopPoolSize = TestUtils.randomPositiveInt();
int internalBlockingPoolSize = TestUtils.randomPositiveInt();
int workerPoolSize = TestUtils.randomPositiveInt();
int blockedThreadCheckInterval = TestUtils.randomPositiveInt();
String clusterHost = TestUtils.randomAlphaString(100);
String clusterPublicHost = TestUtils.randomAlphaString(100);
long clusterPingInterval = TestUtils.randomPositiveLong();
long clusterPingReplyInterval = TestUtils.randomPositiveLong();
int maxEventLoopExecuteTime = TestUtils.randomPositiveInt();
int maxWorkerExecuteTime = TestUtils.randomPositiveInt();
int proxyOperationTimeout = TestUtils.randomPositiveInt();
long warningExceptionTime = TestUtils.randomPositiveLong();
Random rand = new Random();
boolean haEnabled = rand.nextBoolean();
int quorumSize = TestUtils.randomShort() + 1;
String haGroup = TestUtils.randomAlphaString(100);
boolean metricsEnabled = rand.nextBoolean();
boolean jmxEnabled = rand.nextBoolean();
String jmxDomain = TestUtils.randomAlphaString(100);
options = new VertxOptions(new JsonObject().put("clusterPort", clusterPort).put("clusterPublicPort", clusterPublicPort).put("eventLoopPoolSize", eventLoopPoolSize).put("internalBlockingPoolSize", internalBlockingPoolSize).put("workerPoolSize", workerPoolSize).put("blockedThreadCheckInterval", blockedThreadCheckInterval).put("clusterHost", clusterHost).put("clusterPublicHost", clusterPublicHost).put("clusterPingInterval", clusterPingInterval).put("clusterPingReplyInterval", clusterPingReplyInterval).put("maxEventLoopExecuteTime", maxEventLoopExecuteTime).put("maxWorkerExecuteTime", maxWorkerExecuteTime).put("proxyOperationTimeout", proxyOperationTimeout).put("haEnabled", haEnabled).put("quorumSize", quorumSize).put("haGroup", haGroup).put("warningExceptionTime", warningExceptionTime).put("metricsOptions", new JsonObject().put("enabled", metricsEnabled).put("jmxEnabled", jmxEnabled).put("jmxDomain", jmxDomain)));
assertEquals(clusterPort, options.getClusterPort());
assertEquals(clusterPublicPort, options.getClusterPublicPort());
assertEquals(clusterPublicHost, options.getClusterPublicHost());
assertEquals(clusterPingInterval, options.getClusterPingInterval());
assertEquals(clusterPingReplyInterval, options.getClusterPingReplyInterval());
assertEquals(eventLoopPoolSize, options.getEventLoopPoolSize());
assertEquals(internalBlockingPoolSize, options.getInternalBlockingPoolSize());
assertEquals(workerPoolSize, options.getWorkerPoolSize());
assertEquals(blockedThreadCheckInterval, options.getBlockedThreadCheckInterval());
assertEquals(clusterHost, options.getClusterHost());
assertEquals(null, options.getClusterManager());
assertEquals(maxEventLoopExecuteTime, options.getMaxEventLoopExecuteTime());
assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
assertEquals(haEnabled, options.isHAEnabled());
assertEquals(quorumSize, options.getQuorumSize());
assertEquals(haGroup, options.getHAGroup());
MetricsOptions metricsOptions = options.getMetricsOptions();
assertEquals(metricsEnabled, metricsOptions.isEnabled());
assertEquals(warningExceptionTime, options.getWarningExceptionTime());
}
Aggregations