From 467bb69f0a38e56ffe13f05bd697439e23eda98e Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 20 Feb 2024 19:45:22 -0500 Subject: [PATCH] test --- src/test/java/itest/CustomTargetsIT.java | 61 +++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/src/test/java/itest/CustomTargetsIT.java b/src/test/java/itest/CustomTargetsIT.java index 02db95169f..8da9e86775 100644 --- a/src/test/java/itest/CustomTargetsIT.java +++ b/src/test/java/itest/CustomTargetsIT.java @@ -15,6 +15,8 @@ */ package itest; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -307,10 +309,8 @@ void targetShouldAppearInListing() @Test @Order(5) void shouldBeAbleToDeleteTarget() - throws ExecutionException, InterruptedException { + throws TimeoutException, ExecutionException, InterruptedException { CompletableFuture response3 = new CompletableFuture<>(); - //String expectedConnectUrl = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; - webClient .get("/api/v1/targets") .send( @@ -324,11 +324,60 @@ void shouldBeAbleToDeleteTarget() MatcherAssert.assertThat(body3, Matchers.notNullValue()); MatcherAssert.assertThat(body3.size(), Matchers.equalTo(2)); - CountDownLatch latch = new CountDownLatch(1); + CountDownLatch latch = new CountDownLatch(2); + worker.submit( + () -> { + try { + expectNotification("TargetJvmDiscovery", 5, TimeUnit.SECONDS) + .thenAcceptAsync( + notification -> { + JsonObject event = notification + .getJsonObject("message") + .getJsonObject("event"); + MatcherAssert.assertThat( + event.getString("kind"), + Matchers.equalTo( + "LOST")); + MatcherAssert.assertThat( + event.getJsonObject( + "serviceRef") + .getString("connectUrl"), + Matchers.equalTo( + "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi")); + MatcherAssert.assertThat( + event.getJsonObject( + "serviceRef") + .getString("alias"), + Matchers.equalTo( + "self")); + latch.countDown(); + }) + .get(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + CompletableFuture response1 = new CompletableFuture<>(); + webClient + .get("/api/v1/targets") + .send( + ar -> { + assertRequestStatus(ar, response1); + response1.complete(ar.result().bodyAsJsonArray()); + latch.countDown(); + }); + JsonArray body1 = response1.get(); + System.out.println("+++body1 "+ body1.encodePrettily()); + System.out.println("+++ size1 "+ body1.size()); + MatcherAssert.assertThat(body1, Matchers.notNullValue()); + MatcherAssert.assertThat(body1.size(), Matchers.equalTo(2)); + + String jmxServiceUrl = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; + String encodedUrl = URLEncoder.encode(jmxServiceUrl, StandardCharsets.UTF_8); CompletableFuture response = new CompletableFuture<>(); webClient - .delete("/api/v2/targets/:service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi") + .delete("/api/v2/targets/" + encodedUrl) .send( ar -> { assertRequestStatus(ar, response); @@ -344,7 +393,7 @@ void shouldBeAbleToDeleteTarget() .send( ar -> { assertRequestStatus(ar, response2); - response2.complete(ar.result().bodyAsJsonArray()); + response1.complete(ar.result().bodyAsJsonArray()); }); JsonArray body2 = response2.get(); System.out.println("+++body2 after delete "+ body2.encodePrettily());