From db8af07090920c79c46770174dea327cef4e10f9 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 5 Mar 2024 18:58:44 -0500 Subject: [PATCH 01/38] add testEnvironmentNodeListing --- src/test/java/itest/GraphQLTest.java | 126 ++++++++++++++++++--------- 1 file changed, 87 insertions(+), 39 deletions(-) diff --git a/src/test/java/itest/GraphQLTest.java b/src/test/java/itest/GraphQLTest.java index c8063c4d4..c9a0868c4 100644 --- a/src/test/java/itest/GraphQLTest.java +++ b/src/test/java/itest/GraphQLTest.java @@ -21,11 +21,9 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -34,8 +32,10 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import io.cryostat.discovery.DiscoveryNode; import io.cryostat.util.HttpMimeType; +import com.fasterxml.jackson.core.type.TypeReference; import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpHeaders; @@ -55,7 +55,7 @@ import org.junit.jupiter.params.provider.ValueSource; @TestMethodOrder(OrderAnnotation.class) -@Disabled("TODO not all GraphQL queries are implemented") +// @Disabled("TODO not all GraphQL queries are implemented") class GraphQLTest extends StandardSelfTest { private final ExecutorService worker = ForkJoinPool.commonPool(); @@ -69,7 +69,10 @@ void testEnvironmentNodeListing() throws Exception { query.put( "query", "query { environmentNodes(filter: { name: \"Custom Targets\" }) { name nodeType" - + " descendantTargets { name nodeType } } }"); + + " children { name nodeType } } }"); + + System.out.println("+++ Query sent: " + query.encodePrettily()); + HttpResponse resp = webClient .extensions() @@ -77,31 +80,39 @@ void testEnvironmentNodeListing() throws Exception { MatcherAssert.assertThat( resp.statusCode(), Matchers.both(Matchers.greaterThanOrEqualTo(200)).and(Matchers.lessThan(300))); - EnvironmentNodesResponse actual = - mapper.readValue(resp.bodyAsString(), EnvironmentNodesResponse.class); - EnvironmentNodes expected = new EnvironmentNodes(); + TypeReference typeRef = + new TypeReference() {}; + EnvironmentNodesResponse actual = mapper.readValue(resp.bodyAsString(), typeRef); - EnvironmentNode jdp = new EnvironmentNode(); - jdp.name = "JDP"; - jdp.nodeType = "Realm"; + List expectedChildren = new ArrayList<>(); + DiscoveryNode expectedChild = new DiscoveryNode(); + expectedChild.name = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; + expectedChild.nodeType = "JVM"; + expectedChildren.add(expectedChild); - jdp.descendantTargets = new ArrayList<>(); - Node cryostat = new Node(); - cryostat.name = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; - cryostat.nodeType = "JVM"; - jdp.descendantTargets.add(cryostat); + DiscoveryNode expectedNode = new DiscoveryNode(); + expectedNode.name = "Custom Targets"; + expectedNode.nodeType = "Realm"; + expectedNode.children = expectedChildren; + + assertThat(actual.getData().getEnvironmentNodes().size(), is(1)); - Node target = new Node(); - target.name = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; - target.nodeType = "JVM"; - jdp.descendantTargets.add(target); + DiscoveryNode actualNode = actual.getData().getEnvironmentNodes().get(0); - expected.environmentNodes = List.of(jdp); + assertThat(actualNode.name, is(expectedNode.name)); + assertThat(actualNode.nodeType, is(expectedNode.nodeType)); + assertThat(actualNode.children.size(), is(expectedNode.children.size())); - MatcherAssert.assertThat(actual.data, Matchers.equalTo(expected)); + for (int i = 0; i < actualNode.children.size(); i++) { + DiscoveryNode actualChild = actualNode.children.get(i); + DiscoveryNode expectedChildNode = expectedNode.children.get(i); + assertThat(actualChild.name, is(expectedChildNode.name)); + assertThat(actualChild.nodeType, is(expectedChildNode.nodeType)); + } } + @Disabled @Test @Order(1) void testOtherContainersFound() throws Exception { @@ -163,6 +174,7 @@ void testOtherContainersFound() throws Exception { MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasItem(ext)); } + @Disabled @Test @Order(2) void testQueryForSpecificTargetWithSpecificFields() throws Exception { @@ -190,6 +202,7 @@ void testQueryForSpecificTargetWithSpecificFields() throws Exception { MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasItem(ext)); } + @Disabled @Test @Order(3) void testStartRecordingMutationOnSpecificTarget() throws Exception { @@ -277,6 +290,7 @@ void testStartRecordingMutationOnSpecificTarget() throws Exception { MatcherAssert.assertThat(actual.data, Matchers.equalTo(nodes)); } + @Disabled @Test @Order(4) void testArchiveMutation() throws Exception { @@ -314,6 +328,7 @@ void testArchiveMutation() throws Exception { "^es-andrewazor-demo-Main_graphql-itest_[0-9]{8}T[0-9]{6}Z\\.jfr$")); } + @Disabled @Test @Order(5) void testActiveRecordingMetadataMutation() throws Exception { @@ -360,6 +375,7 @@ void testActiveRecordingMetadataMutation() throws Exception { "newValue")))); } + @Disabled @Test @Order(6) void testArchivedRecordingMetadataMutation() throws Exception { @@ -407,6 +423,7 @@ void testArchivedRecordingMetadataMutation() throws Exception { "newArchivedValue")))); } + @Disabled @Test @Order(7) void testDeleteMutation() throws Exception { @@ -451,6 +468,7 @@ void testDeleteMutation() throws Exception { "^es-andrewazor-demo-Main_graphql-itest_[0-9]{8}T[0-9]{6}Z\\.jfr$")); } + /* @Disabled @Test @Order(8) void testNodesHaveIds() throws Exception { @@ -481,8 +499,9 @@ void testNodesHaveIds() throws Exception { observedIds.add(target.id); } } - } + } */ + @Disabled @Test @Order(9) void testQueryForSpecificTargetsByNames() throws Exception { @@ -521,6 +540,7 @@ void testQueryForSpecificTargetsByNames() throws Exception { assertThat(targetNodes, hasItem(target2)); } + @Disabled @Test @Order(10) public void testQueryForFilteredActiveRecordingsByNames() throws Exception { @@ -653,6 +673,7 @@ public void testQueryForFilteredActiveRecordingsByNames() throws Exception { Matchers.equalTo(0)); } + @Disabled @Test @Order(11) public void shouldReturnArchivedRecordingsFilteredByNames() throws Exception { @@ -876,6 +897,7 @@ public void shouldReturnArchivedRecordingsFilteredByNames() throws Exception { } } + /* @Disabled @Test @Order(12) public void testQueryforFilteredEnvironmentNodesByNames() throws Exception { @@ -906,8 +928,9 @@ public void testQueryforFilteredEnvironmentNodesByNames() throws Exception { } } Assertions.assertTrue(nameExists, "Name not found"); - } + } */ + @Disabled @Test @Order(13) void testReplaceAlwaysOnStoppedRecording() throws Exception { @@ -932,6 +955,7 @@ void testReplaceAlwaysOnStoppedRecording() throws Exception { } } + @Disabled @Test @Order(14) void testReplaceNeverOnStoppedRecording() throws Exception { @@ -959,6 +983,7 @@ void testReplaceNeverOnStoppedRecording() throws Exception { } } + @Disabled @Test @Order(15) void testReplaceStoppedOnStoppedRecording() throws Exception { @@ -983,6 +1008,7 @@ void testReplaceStoppedOnStoppedRecording() throws Exception { } } + @Disabled @ParameterizedTest @ValueSource(strings = {"STOPPED", "NEVER"}) @Order(16) @@ -1006,6 +1032,7 @@ void testReplaceStoppedOrNeverOnRunningRecording(String replace) throws Exceptio } } + @Disabled @Test @Order(17) void testReplaceAlwaysOnRunningRecording() throws Exception { @@ -1025,6 +1052,7 @@ void testReplaceAlwaysOnRunningRecording() throws Exception { } } + @Disabled @Test @Order(18) void testRestartTrueOnRunningRecording() throws Exception { @@ -1044,6 +1072,7 @@ void testRestartTrueOnRunningRecording() throws Exception { } } + @Disabled @Test @Order(19) void testRestartFalseOnRunningRecording() throws Exception { @@ -1066,6 +1095,7 @@ void testRestartFalseOnRunningRecording() throws Exception { } } + @Disabled @Test @Order(20) void testRestartTrueOnStoppedRecording() throws Exception { @@ -1090,6 +1120,7 @@ void testRestartTrueOnStoppedRecording() throws Exception { } } + @Disabled @Test @Order(21) void testRestartFalseOnStoppedRecording() throws Exception { @@ -1117,6 +1148,7 @@ void testRestartFalseOnStoppedRecording() throws Exception { } } + @Disabled @ParameterizedTest @ValueSource(strings = {"ALWAYS", "STOPPED", "NEVER"}) @Order(22) @@ -1131,6 +1163,7 @@ void testStartRecordingwithReplaceNever(String replace) throws Exception { } } + @Disabled @ParameterizedTest @ValueSource(booleans = {true, false}) @Order(23) @@ -1737,12 +1770,12 @@ public boolean equals(Object obj) { } static class EnvironmentNode extends Node { - List descendantTargets; + List children; @Override public String toString() { - return "EnvironmentNode [descendantTargets=" - + descendantTargets + return "EnvironmentNode [children =" + + children + ", name=" + name + ", nodeType=" @@ -1752,7 +1785,7 @@ public String toString() { @Override public int hashCode() { - return Objects.hash(descendantTargets); + return Objects.hash(children); } @Override @@ -1767,12 +1800,20 @@ public boolean equals(Object obj) { return false; } EnvironmentNode other = (EnvironmentNode) obj; - return Objects.equals(descendantTargets, other.descendantTargets); + return Objects.equals(children, other.children); } } - static class EnvironmentNodes { - List environmentNodes; + public class EnvironmentNodes { + private List environmentNodes; + + public List getEnvironmentNodes() { + return environmentNodes; + } + + public void setEnvironmentNodes(List environmentNodes) { + this.environmentNodes = environmentNodes; + } @Override public String toString() { @@ -1800,21 +1841,28 @@ public boolean equals(Object obj) { } } - static class EnvironmentNodesResponse { - EnvironmentNodes data; - - @Override - public String toString() { - return "EnvironmentNodesResponse [data=" + data + "]"; - } + public static class EnvironmentNodesResponse { + private Data data; - public EnvironmentNodes getData() { + public Data getData() { return data; } - public void setData(EnvironmentNodes data) { + public void setData(Data data) { this.data = data; } + + public static class Data { + private List environmentNodes; + + public List getEnvironmentNodes() { + return environmentNodes; + } + + public void setEnvironmentNodes(List environmentNodes) { + this.environmentNodes = environmentNodes; + } + } } static class ArchiveMutationResponse { From 1304f9f03d20d6cab146b00e3659ea2b0c781c12 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Fri, 19 Apr 2024 10:29:04 -0400 Subject: [PATCH 02/38] reopen PR --- src/test/java/itest/GraphQLTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/itest/GraphQLTest.java b/src/test/java/itest/GraphQLTest.java index c9a0868c4..2ef39979c 100644 --- a/src/test/java/itest/GraphQLTest.java +++ b/src/test/java/itest/GraphQLTest.java @@ -110,6 +110,7 @@ void testEnvironmentNodeListing() throws Exception { assertThat(actualChild.name, is(expectedChildNode.name)); assertThat(actualChild.nodeType, is(expectedChildNode.nodeType)); } + // } @Disabled From cbbb7074001517d3bafc529e08611d7a03a4e092 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Mon, 22 Apr 2024 10:29:05 -0400 Subject: [PATCH 03/38] Test testOtherContainersFound --- src/test/java/itest/GraphQLTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/itest/GraphQLTest.java b/src/test/java/itest/GraphQLTest.java index 2ef39979c..932f636ad 100644 --- a/src/test/java/itest/GraphQLTest.java +++ b/src/test/java/itest/GraphQLTest.java @@ -71,8 +71,6 @@ void testEnvironmentNodeListing() throws Exception { "query { environmentNodes(filter: { name: \"Custom Targets\" }) { name nodeType" + " children { name nodeType } } }"); - System.out.println("+++ Query sent: " + query.encodePrettily()); - HttpResponse resp = webClient .extensions() @@ -110,10 +108,9 @@ void testEnvironmentNodeListing() throws Exception { assertThat(actualChild.name, is(expectedChildNode.name)); assertThat(actualChild.nodeType, is(expectedChildNode.nodeType)); } - // } - @Disabled + // @Disabled @Test @Order(1) void testOtherContainersFound() throws Exception { From 2da89843442cfb511d5a65acefaeae208d1c6c9b Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Mon, 29 Apr 2024 19:00:59 -0400 Subject: [PATCH 04/38] testOtherContainersFound pass --- src/test/java/itest/GraphQLTest.java | 322 +++++++++++++++++++++------ 1 file changed, 251 insertions(+), 71 deletions(-) diff --git a/src/test/java/itest/GraphQLTest.java b/src/test/java/itest/GraphQLTest.java index 932f636ad..1411cb961 100644 --- a/src/test/java/itest/GraphQLTest.java +++ b/src/test/java/itest/GraphQLTest.java @@ -35,6 +35,7 @@ import io.cryostat.discovery.DiscoveryNode; import io.cryostat.util.HttpMimeType; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; @@ -110,15 +111,14 @@ void testEnvironmentNodeListing() throws Exception { } } - // @Disabled @Test @Order(1) void testOtherContainersFound() throws Exception { JsonObject query = new JsonObject(); query.put( "query", - "query { targetNodes { name nodeType labels target { alias connectUrl annotations {" - + " cryostat platform } } } }"); + "query { targetNodes { name nodeType labels { key value } target { alias connectUrl" + + " annotations { cryostat { key value } platform { key value } } } } }"); HttpResponse resp = webClient .extensions() @@ -129,47 +129,24 @@ void testOtherContainersFound() throws Exception { TargetNodesQueryResponse actual = mapper.readValue(resp.bodyAsString(), TargetNodesQueryResponse.class); + MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasSize(1)); TargetNode cryostat = new TargetNode(); Target cryostatTarget = new Target(); - cryostatTarget.alias = "io.cryostat.Cryostat"; - cryostatTarget.connectUrl = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; - cryostat.name = cryostatTarget.connectUrl; - cryostat.target = cryostatTarget; - cryostat.nodeType = "JVM"; + cryostatTarget.setAlias("selftest"); + cryostatTarget.setConnectUrl("service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"); + cryostat.setName(cryostatTarget.getConnectUrl()); + cryostat.setTarget(cryostatTarget); + cryostat.setNodeType("JVM"); Annotations cryostatAnnotations = new Annotations(); - cryostatAnnotations.cryostat = - Map.of( - "REALM", - "JDP", - "JAVA_MAIN", - "io.cryostat.Cryostat", - "HOST", - "localhost", - "PORT", - "0"); - cryostatAnnotations.platform = Map.of(); - cryostatTarget.annotations = cryostatAnnotations; - cryostat.labels = Map.of(); + cryostatAnnotations.setCryostat(Arrays.asList(new KeyValue("REALM", "Custom Targets"))); + cryostatAnnotations.setPlatform(new ArrayList<>()); + cryostatTarget.setAnnotations(cryostatAnnotations); + cryostat.setLabels(new ArrayList<>()); MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasItem(cryostat)); - - String uri = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi"; - String mainClass = "es.andrewazor.demo.Main"; - TargetNode ext = new TargetNode(); - Target target = new Target(); - target.alias = mainClass; - target.connectUrl = uri; - ext.name = target.connectUrl; - ext.target = target; - ext.nodeType = "JVM"; - Annotations annotations = new Annotations(); - annotations.cryostat = - Map.of("REALM", "JDP", "JAVA_MAIN", mainClass, "HOST", "localhost", "PORT", "0"); - annotations.platform = Map.of(); - target.annotations = annotations; - ext.labels = Map.of(); - MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasItem(ext)); + assertThat(actual.data.targetNodes.get(0).name, is(cryostat.name)); + assertThat(actual.data.targetNodes.get(0).nodeType, is(cryostat.nodeType)); } @Disabled @@ -1181,6 +1158,30 @@ static class Target { String connectUrl; Annotations annotations; + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getConnectUrl() { + return connectUrl; + } + + public void setConnectUrl(String connectUrl) { + this.connectUrl = connectUrl; + } + + public Annotations getAnnotations() { + return annotations; + } + + public void setAnnotations(Annotations annotations) { + this.annotations = annotations; + } + @Override public int hashCode() { return Objects.hash(alias, connectUrl, annotations); @@ -1202,11 +1203,93 @@ public boolean equals(Object obj) { && Objects.equals(connectUrl, other.connectUrl) && Objects.equals(annotations, other.annotations); } + + @Override + public String toString() { + return "Target [alias=" + + alias + + ", connectUrl=" + + connectUrl + + ", annotations=" + + annotations + + "]"; + } } - static class Annotations { - Map platform; - Map cryostat; + public static class KeyValue { + private String key; + private String value; + + public KeyValue() {} + + public KeyValue(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + KeyValue keyValue = (KeyValue) o; + return Objects.equals(key, keyValue.key) && Objects.equals(value, keyValue.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } + + @Override + public String toString() { + return "KeyValue{" + "key='" + key + '\'' + ", value='" + value + '\'' + '}'; + } + } + + public static class Annotations { + private List cryostat; + private List platform; + + public List getCryostat() { + return cryostat; + } + + public void setCryostat(List cryostat) { + this.cryostat = cryostat; + } + + public List getPlatform() { + return platform; + } + + public void setPlatform(List platform) { + this.platform = platform; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Annotations that = (Annotations) o; + return Objects.equals(cryostat, that.cryostat) + && Objects.equals(platform, that.platform); + } @Override public int hashCode() { @@ -1214,19 +1297,8 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Annotations other = (Annotations) obj; - return Objects.equals(cryostat, other.cryostat) - && Objects.equals(platform, other.platform); + public String toString() { + return "Annotations{" + "cryostat=" + cryostat + ", platform=" + platform + '}'; } } @@ -1372,12 +1444,60 @@ public boolean equals(Object obj) { } static class TargetNode { - String name; - String nodeType; - Map labels; - Target target; - Recordings recordings; - ActiveRecording doStartRecording; + private String name; + private String nodeType; + private List