Skip to content

Commit

Permalink
Resolved: [1]:Filter by Node name and then with recording names.
Browse files Browse the repository at this point in the history
[2]:Use exact names to filter for archived recordings instead of RegEx.
  • Loading branch information
aali309 committed Jun 26, 2023
1 parent a514f82 commit c19261e
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/test/java/itest/GraphQLIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
*/
package itest;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
Expand All @@ -55,7 +54,6 @@
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import io.cryostat.MainModule;
Expand Down Expand Up @@ -696,8 +694,10 @@ public void testQueryForFilteredActiveRecordingsByNames() throws Exception {
// GraphQL Query to filter Active recordings by names
CompletableFuture<TargetNodesQueryResponse> resp2 = new CompletableFuture<>();
String query =
"query { targetNodes {recordings {active(filter: { names: [\"Recording1\","
+ " \"Recording2\",\"Recording3\"] }) {data {name}}}}}";
"query { targetNodes (filter: {name:"
+ " \"service:jmx:rmi:///jndi/rmi://cryostat-itests:9091/jmxrmi\"}){ recordings"
+ " {active(filter: { names: [\"Recording1\", \"Recording2\",\"Recording3\"] })"
+ " {data {name}}}}}";
webClient
.post("/api/v2.2/graphql")
.sendJson(
Expand Down Expand Up @@ -825,19 +825,20 @@ public void shouldReturnArchivedRecordingsFilteredByNames() throws Exception {

Thread.sleep(2_000L);

// Retrieve the list of archived recordings
CompletableFuture<JsonArray> archivedRecordingsFuture = new CompletableFuture<>();
// retrieve to match the exact name
CompletableFuture<JsonArray> archivedRecordingsFuture2 = new CompletableFuture<>();
webClient
.get(String.format("/api/v1/targets/%s/recordings", SELF_REFERENCE_TARGET_ID))
.get(String.format("/api/v1/recordings"))
.send(
ar -> {
if (assertRequestStatus(ar, archivedRecordingsFuture)) {
archivedRecordingsFuture.complete(ar.result().bodyAsJsonArray());
if (assertRequestStatus(ar, archivedRecordingsFuture2)) {
archivedRecordingsFuture2.complete(ar.result().bodyAsJsonArray());
}
});

JsonArray archivedRecordings =
archivedRecordingsFuture.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
JsonArray retrivedArchivedRecordings =
archivedRecordingsFuture2.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
JsonObject retrievedArchivedrecordings = retrivedArchivedRecordings.getJsonObject(0);
String retrievedArchivedRecordingsName = retrievedArchivedrecordings.getString("name");

// GraphQL Query to filter Archived recordings by names
CompletableFuture<TargetNodesQueryResponse> resp2 = new CompletableFuture<>();
Expand Down Expand Up @@ -872,20 +873,21 @@ public void shouldReturnArchivedRecordingsFilteredByNames() throws Exception {
.flatMap(targetNode -> targetNode.recordings.archived.data.stream())
.collect(Collectors.toList());

ArchivedRecording archivedRecording = archivedRecordings2.get(0);
String pattern = "io-cryostat-Cryostat_archivedRecording_[\\d]{8}T[\\d]{6}Z.jfr";
String archivedRecordingName = archivedRecording.name;

boolean isMatch = Pattern.matches(pattern, archivedRecordingName);
Assertions.assertTrue(isMatch, "Filtered name should match the pattern");

int filteredRecordingsCount = archivedRecordings.size();
int filteredRecordingsCount = archivedRecordings2.size();
Assertions.assertEquals(
1, filteredRecordingsCount, "Number of filtered recordings should be 1");

ArchivedRecording archivedRecording = archivedRecordings2.get(0);
String filteredName = archivedRecording.name;
Assertions.assertEquals(
filteredName,
retrievedArchivedRecordingsName,
"Filtered name should match the archived recording name");

// Delete archived recording by name
for (ArchivedRecording archrecording : archivedRecordings2) {
String nameMatch = archrecording.name;
// Delete archived recording by name

CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
webClient
.delete(
Expand Down

0 comments on commit c19261e

Please sign in to comment.