public StreamPriority(JsonObject json) { this.weight = json.getInteger("weight", (int)DEFAULT_WEIGHT).shortValue(); this.dependency = json.getInteger("dependency", DEFAULT_DEPENDENCY); this.exclusive = json.getBoolean("exclusive", DEFAULT_EXCLUSIVE); }
/** * Create a delivery options from JSON * * @param json the JSON */ public DeliveryOptions(JsonObject json) { this.timeout = json.getLong("timeout", DEFAULT_TIMEOUT); this.codecName = json.getString("codecName", null); JsonObject hdrs = json.getJsonObject("headers", null); if (hdrs != null) { headers = new CaseInsensitiveHeaders(); for (Map.Entry<String, Object> entry: hdrs) { if (!(entry.getValue() instanceof String)) { throw new IllegalStateException("Invalid type for message header value " + entry.getValue().getClass()); } headers.set(entry.getKey(), (String)entry.getValue()); } } this.localOnly = json.getBoolean("localOnly", DEFAULT_LOCAL_ONLY); }
/** * Create options from JSON * * @param json the JSON */ public RequestOptions(JsonObject json) { setHost(json.getString("host", DEFAULT_HOST)); setPort(json.getInteger("port", DEFAULT_PORT)); setSsl(json.getBoolean("ssl", DEFAULT_SSL)); setURI(json.getString("uri", DEFAULT_URI)); }
/** * Initialise the fields of this instance from the specified JSON * * @param json the JSON */ public void fromJson(JsonObject json) { this.config = json.getJsonObject("config"); this.worker = json.getBoolean("worker", DEFAULT_WORKER); this.isolationGroup = json.getString("isolationGroup", DEFAULT_ISOLATION_GROUP); this.ha = json.getBoolean("ha", DEFAULT_HA); JsonArray arr = json.getJsonArray("extraClasspath", null); if (arr != null) { this.extraClasspath = arr.getList(); } this.instances = json.getInteger("instances", DEFAULT_INSTANCES); JsonArray arrIsolated = json.getJsonArray("isolatedClasses", null); if (arrIsolated != null) { this.isolatedClasses = arrIsolated.getList(); } }
@Test public void testGetBoolean() { jsonObject.put("foo", true); assertEquals(true, jsonObject.getBoolean("foo")); jsonObject.put("foo", false); assertEquals(false, jsonObject.getBoolean("foo")); jsonObject.put("bar", 123); try { jsonObject.getBoolean("bar"); fail(); } catch (ClassCastException e) { // Ok } // Null and absent values jsonObject.putNull("foo"); assertNull(jsonObject.getBoolean("foo")); assertNull(jsonObject.getBoolean("absent")); try { jsonObject.getBoolean(null); fail(); } catch (NullPointerException e) { // OK } }
@Test public void testGetBooleanDefault() { jsonObject.put("foo", true); assertEquals(true, jsonObject.getBoolean("foo", false)); assertEquals(true, jsonObject.getBoolean("foo", null)); jsonObject.put("foo", false); assertEquals(false, jsonObject.getBoolean("foo", true)); assertEquals(false, jsonObject.getBoolean("foo", null)); jsonObject.put("bar", 123); try { jsonObject.getBoolean("bar", true); fail(); } catch (ClassCastException e) { // Ok } // Null and absent values jsonObject.putNull("foo"); assertNull(jsonObject.getBoolean("foo", true)); assertNull(jsonObject.getBoolean("foo", false)); assertEquals(true, jsonObject.getBoolean("absent", true)); assertEquals(false, jsonObject.getBoolean("absent", false)); try { jsonObject.getBoolean(null, null); fail(); } catch (NullPointerException e) { // OK } }
@Test public void testPutBoolean() { assertSame(jsonObject, jsonObject.put("foo", true)); assertEquals(true, jsonObject.getBoolean("foo")); jsonObject.put("quux", true); assertEquals(true, jsonObject.getBoolean("quux")); assertEquals(true, jsonObject.getBoolean("foo")); jsonObject.put("foo", true); assertEquals(true, jsonObject.getBoolean("foo")); jsonObject.put("foo", (Boolean) null); assertTrue(jsonObject.containsKey("foo")); try { jsonObject.put(null, false); fail(); } catch (NullPointerException e) { // OK } }
@Test public void testJsonOptions() { Random rand = new Random(); boolean enabled = rand.nextBoolean(); FileSystemOptions options = new FileSystemOptions(new JsonObject(). put("fileCachingEnabled", enabled). put("classPathResolvingEnabled", enabled) ); assertEquals(enabled, options.isFileCachingEnabled()); assertEquals(enabled, options.toJson().getBoolean("fileCachingEnabled")); assertEquals(enabled, options.isClassPathResolvingEnabled()); assertEquals(enabled, options.toJson().getBoolean("classPathResolvingEnabled")); } }
@Test public void testStartListStopWithIdAndAnotherArgument() throws InterruptedException, IOException { record(); cli.dispatch(new String[]{"start", "run", HttpTestVerticle.class.getName(), "--launcher-class", Launcher.class.getName(), "--vertx-id=hello", "-cluster"}); waitForStartup(); assertThat(output.toString()).contains("Starting vert.x application").contains("hello"); assertThat(RunCommandTest.getContent().getBoolean("clustered")).isTrue(); output.reset(); cli.dispatch(new String[]{"list"}); assertThat(output.toString()).hasLineCount(2).contains("hello"); // Extract id. String[] lines = output.toString().split(System.lineSeparator()); String id = lines[1].trim().substring(0, lines[1].trim().indexOf("\t")); assertThat(id).isEqualToIgnoringCase("hello"); output.reset(); // pass --redeploy to not call system.exit cli.dispatch(new String[]{"stop", id, "--redeploy"}); assertThat(output.toString()) .contains("Stopping vert.x application '" + id + "'") .contains("Application '" + id + "' terminated with status 0"); waitForShutdown(); assertWaitUntil(() -> { output.reset(); cli.dispatch(new String[]{"list"}); return !output.toString().contains(id); }); assertThat(output.toString()).hasLineCount(2).contains("No vert.x application found"); }
@Test public void testStartListStopWithIdAndAnotherArgumentBeforeId() throws InterruptedException, IOException { record(); cli.dispatch(new String[]{"start", "run", HttpTestVerticle.class.getName(), "--launcher-class", Launcher.class.getName(), "-cluster", "--vertx-id=hello"}); waitForStartup(); assertThat(output.toString()).contains("Starting vert.x application").contains("hello"); assertThat(RunCommandTest.getContent().getBoolean("clustered")).isTrue(); output.reset(); cli.dispatch(new String[]{"list"}); assertThat(output.toString()).hasLineCount(2).contains("hello"); // Extract id. String[] lines = output.toString().split(System.lineSeparator()); String id = lines[1].trim().substring(0, lines[1].trim().indexOf("\t")); assertThat(id).isEqualToIgnoringCase("hello"); output.reset(); // pass --redeploy to not call system.exit cli.dispatch(new String[]{"stop", id, "--redeploy"}); assertThat(output.toString()) .contains("Stopping vert.x application '" + id + "'") .contains("Application '" + id + "' terminated with status 0"); waitForShutdown(); assertWaitUntil(() -> { output.reset(); cli.dispatch(new String[]{"list"}); return !output.toString().contains(id); }); assertThat(output.toString()).hasLineCount(2).contains("No vert.x application found"); }
@Test public void testDeploymentOfJavaVerticleWithCluster() throws IOException { cli.dispatch(new Launcher(), new String[] {"run", HttpTestVerticle.class.getName(), "-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testJsonOptions() { MetricsOptions options = new MetricsOptions(new JsonObject()); assertFalse(options.isEnabled()); Random rand = new Random(); boolean metricsEnabled = rand.nextBoolean(); String customValue = TestUtils.randomAlphaString(10); options = new MetricsOptions(new JsonObject(). put("enabled", metricsEnabled). put("custom", customValue) ); assertEquals(metricsEnabled, options.isEnabled()); assertEquals(metricsEnabled, options.toJson().getBoolean("enabled")); assertEquals(customValue, options.toJson().getString("custom")); }
@Test public void testStartingApplicationInRedeployModeWithCluster() throws IOException { cli.dispatch(new Launcher(), new String[]{"run", HttpTestVerticle.class.getName(), "--redeploy=**" + File.separator + "*.txt", "--launcher-class=" + Launcher.class.getName(), "--cluster", ExecUtils.isWindows() ? "--redeploy-termination-period=3000" : "" }); assertWaitUntil(() -> { try { return RunCommandTest.getHttpCode() == 200; } catch (IOException e) { return false; } }, 20000); assertThat(RunCommandTest.getContent().getBoolean("clustered")).isTrue(); }
@Test public void testToJsonObject() { Map<String, Object> map = new HashMap<>(); map.put("string", "the_string"); map.put("integer", 4); map.put("boolean", true); map.put("charsequence", new AsciiString("the_charsequence")); map.put("biginteger", new BigInteger("1234567")); map.put("binary", Buffer.buffer("hello")); map.put("object", Collections.singletonMap("nested", 4)); map.put("array", Arrays.asList(1, 2, 3)); JsonObject json = (JsonObject) ConversionHelper.toObject(map); assertEquals(8, json.size()); assertEquals("the_string", json.getString("string")); assertEquals(4, (int)json.getInteger("integer")); assertEquals(true, json.getBoolean("boolean")); assertEquals("the_charsequence", json.getString("charsequence")); assertEquals(1234567, (int)json.getInteger("biginteger")); assertEquals("hello", new String(json.getBinary("binary"))); assertEquals(new JsonObject().put("nested", 4), json.getJsonObject("object")); assertEquals(new JsonArray().add(1).add(2).add(3), json.getJsonArray("array")); }
@Test public void testThatHADeploysVerticleWhenCombinedWithCluster() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-ha", "-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testThatHADeploysVerticle() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-ha", "-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testFatJarWithHTTPVerticleWithCluster() throws IOException, InterruptedException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[]{"-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testFatJarWithHTTPVerticle() throws IOException, InterruptedException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[]{}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isFalse(); }
@Test public void testDecode() throws Exception { byte[] bytes = TestUtils.randomByteArray(10); String strBytes = Base64.getEncoder().encodeToString(bytes); Instant now = Instant.now(); String strInstant = ISO_INSTANT.format(now); String json = "{\"mystr\":\"foo\",\"myint\":123,\"mylong\":1234,\"myfloat\":1.23,\"mydouble\":2.34,\"" + "myboolean\":true,\"mybinary\":\"" + strBytes + "\",\"myinstant\":\"" + strInstant + "\",\"mynull\":null,\"myobj\":{\"foo\":\"bar\"},\"myarr\":[\"foo\",123]}"; JsonObject obj = new JsonObject(json); assertEquals(json, obj.encode()); assertEquals("foo", obj.getString("mystr")); assertEquals(Integer.valueOf(123), obj.getInteger("myint")); assertEquals(Long.valueOf(1234), obj.getLong("mylong")); assertEquals(Float.valueOf(1.23f), obj.getFloat("myfloat")); assertEquals(Double.valueOf(2.34d), obj.getDouble("mydouble")); assertTrue(obj.getBoolean("myboolean")); assertArrayEquals(bytes, obj.getBinary("mybinary")); assertEquals(Base64.getEncoder().encodeToString(bytes), obj.getValue("mybinary")); assertEquals(now, obj.getInstant("myinstant")); assertEquals(now.toString(), obj.getValue("myinstant")); assertTrue(obj.containsKey("mynull")); JsonObject nestedObj = obj.getJsonObject("myobj"); assertEquals("bar", nestedObj.getString("foo")); JsonArray nestedArr = obj.getJsonArray("myarr"); assertEquals("foo", nestedArr.getString(0)); assertEquals(Integer.valueOf(123), Integer.valueOf(nestedArr.getInteger(1))); }
public StreamPriority(JsonObject json) { this.weight = json.getInteger("weight", (int)DEFAULT_WEIGHT).shortValue(); this.dependency = json.getInteger("dependency", DEFAULT_DEPENDENCY); this.exclusive = json.getBoolean("exclusive", DEFAULT_EXCLUSIVE); }