diff --git a/src/org/testKitGen/TestDivider.java b/src/org/testKitGen/TestDivider.java index 8d503d7f..32379af0 100644 --- a/src/org/testKitGen/TestDivider.java +++ b/src/org/testKitGen/TestDivider.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import java.io.FileReader; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -226,22 +227,53 @@ private Map getDataFromTRSS() { String level = getLevel(); Map map = new HashMap(); String URL = constructURL(impl, plat, group, level); - String command = "curl --silent --max-time 120 -L " + URL; + String osName = System.getProperty("os.name").toLowerCase(); + String responseFilePath = new File("response.json").getAbsolutePath(); + String command; + + if (osName.contains("win")) { + command = "cmd.exe /c curl --silent --max-time 120 -L -k \"" + URL + "\""; + } else { + command = "curl --silent --max-time 120 -L -k " + URL; + } + System.out.println("Attempting to get test duration data from TRSS."); System.out.println(command); - Process process; + try { - process = Runtime.getRuntime().exec(command); - } catch (IOException e) { - System.out.println("Warning: cannot get data from TRSS."); - return map; - } - try (InputStream responseStream = process.getInputStream(); - Reader responseReader = new BufferedReader(new InputStreamReader(responseStream))) { - parseDuration(responseReader, map); - } catch (IOException | ParseException e) { - System.out.println("Warning: cannot parse data from TRSS."); + Process process = Runtime.getRuntime().exec(command); + int exitCode = process.waitFor(); + if (exitCode != 0) { + System.out.println("Curl command failed with exit code " + exitCode); + return map; + } + + try (InputStream responseStream = process.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(responseStream))) { + String line; + StringBuilder responseBuilder = new StringBuilder(); + while ((line = reader.readLine()) != null) { + responseBuilder.append(line); + } + String responseData = responseBuilder.toString(); + System.out.println("Response from TRSS: " + responseData); + + if (!responseData.isEmpty()) { + try (Reader stringReader = new StringReader(responseData)) { + parseDuration(stringReader, map); + map.forEach((key, value) -> System.out.println("Test ID: " + key + ", Average Duration: " + value)); + } catch (ParseException e) { + System.out.println("Error parsing the data: " + e.getMessage()); + e.printStackTrace(); + } + } else { + System.out.println("No data received from TRSS."); + } + } + } catch (IOException | InterruptedException e) { + System.out.println("Error executing curl command or reading input: " + e.getMessage()); e.printStackTrace(); + return map; } return map; } @@ -276,7 +308,15 @@ private Queue> createDurationQueue() { Map testsInvalid = new HashMap<>(); for (String test : allTests) { if (matchTRSS.contains(test) || matchCache.contains(test)) { - int duration = TRSSMap.containsKey(test) ? TRSSMap.get(test) : cacheMap.get(test); + int duration; + if (TRSSMap.containsKey(test)) { + duration = TRSSMap.get(test); + System.out.println("TRSSMap.get(" + test + "): " + duration); + } else { + duration = cacheMap.get(test); + System.out.println("cacheMap.get(" + test + "): " + duration); + } + // int duration = TRSSMap.containsKey(test) ? TRSSMap.get(test) : cacheMap.get(test); if (duration > 0) { durationQueue.offer(new AbstractMap.SimpleEntry<>(test, duration)); } else {