From 733b95e640fc4c5f3c69e639e839cead6005b439 Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Mon, 15 Apr 2024 14:39:46 +0530 Subject: [PATCH 1/2] feat: send graphql request to update report with coverage data Signed-off-by: Akash Kumar --- v2/src/main/java/io/keploy/Keploy.java | 70 +++++++++++++++++++++----- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/v2/src/main/java/io/keploy/Keploy.java b/v2/src/main/java/io/keploy/Keploy.java index 5aae90c..b9077f7 100644 --- a/v2/src/main/java/io/keploy/Keploy.java +++ b/v2/src/main/java/io/keploy/Keploy.java @@ -221,17 +221,16 @@ public static void FindCoverage(String testSet) throws IOException, InterruptedE String dest = "target/" + testSet + ".exec"; String jacocoCliPath = getJacococliPath(); List command = Arrays.asList( - "java", - "-jar", - jacocoCliPath, - "dump", - "--address", - "localhost", - "--port", - "36320", - "--destfile", - dest - ); + "java", + "-jar", + jacocoCliPath, + "dump", + "--address", + "localhost", + "--port", + "36320", + "--destfile", + dest); // Start the command using ProcessBuilder ProcessBuilder processBuilder = new ProcessBuilder(command); @@ -552,6 +551,11 @@ public static void runTests(String jarPath, RunOptions runOptions) { if (appErr != null) { throw new AssertionError("error stopping user application: " + appErr); } + + Boolean updateReportResult = udpateReportWithCoverage(testRunId, testSet); + if (!updateReportResult) { + throw new AssertionError("error updating report with coverage data"); + } } // unload the ebpf hooks from the kernel // delete jacoco files @@ -566,7 +570,7 @@ public static void startKeploy(String runCmd, int delay, boolean debug, int port Runnable task = () -> runKeploy(runCmd, delay, debug, port); Thread thread = new Thread(task); thread.start(); - return ; + return; } public static void runKeploy(String runCmd, int delay, boolean debug, int port) { @@ -805,6 +809,48 @@ public static RunTestSetResult runTestSet(String testRunId, String testSetId, St } } + public static Boolean udpateReportWithCoverage(String testRunId, String testSetId) { + HttpURLConnection conn = setHttpClient(); + if (conn == null) { + logger.error("Could not initialize HTTP connection."); + return false; + } + + String payload = "{\"query\": \"mutation UpdateReportWithCov { UpdateReportWithCov(testRunId: \\\"%s\\\", testSetId: \\\"%s\\\", language: \"java\") }\"}"; + + try { + conn.setDoOutput(true); + try (OutputStream os = conn.getOutputStream()) { + os.write(payload.getBytes()); + os.flush(); + } + + int responseCode = conn.getResponseCode(); + logger.debug("Status code received: " + responseCode); + + if (responseCode >= 200 && responseCode < 300) { + String resBody = getResponseBody(conn); + logger.debug("Response body received: " + resBody); + + // Parse the response body using Gson + Gson gson = new Gson(); + GraphQLResponse response = gson.fromJson(resBody, GraphQLResponse.class); + + if (response.data == null) { + return false; + } + + return true; + } else { + logger.error("Failed to update report with coverage data. Status code: " + responseCode); + return false; + } + } catch (Exception e) { + logger.error("Error updating report with coverage data: " + e.getMessage(), e); + return false; + } + } + public static class StopHooksResult { Boolean success; String error; From 1821ba5e3d3395d14cd6397112b00fb92783a6f5 Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Mon, 15 Apr 2024 16:06:27 +0530 Subject: [PATCH 2/2] fix: 422 error Signed-off-by: Akash Kumar --- v2/src/main/java/io/keploy/Keploy.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/v2/src/main/java/io/keploy/Keploy.java b/v2/src/main/java/io/keploy/Keploy.java index b9077f7..5a43a5c 100644 --- a/v2/src/main/java/io/keploy/Keploy.java +++ b/v2/src/main/java/io/keploy/Keploy.java @@ -816,7 +816,9 @@ public static Boolean udpateReportWithCoverage(String testRunId, String testSetI return false; } - String payload = "{\"query\": \"mutation UpdateReportWithCov { UpdateReportWithCov(testRunId: \\\"%s\\\", testSetId: \\\"%s\\\", language: \"java\") }\"}"; + String payload = String.format( + "{\"query\": \"mutation updateReportWithCov{ updateReportWithCov(testRunId: \\\"%s\\\", testSetId: \\\"%s\\\", language: \\\"java\\\") }\"}", + testRunId, testSetId); try { conn.setDoOutput(true);