Skip to content

Commit

Permalink
removed file use
Browse files Browse the repository at this point in the history
  • Loading branch information
annaibm committed Jul 22, 2024
1 parent 9db2ee5 commit 6b83bd9
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions src/org/testKitGen/TestDivider.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,54 +232,48 @@ private Map<String, Integer> getDataFromTRSS() {
String command;

if (osName.contains("win")) {
command = "cmd.exe /c curl --silent --max-time 120 -L -k \"" + URL + "\" -o " + responseFilePath;
command = "cmd.exe /c curl --silent --max-time 120 -L -k \"" + URL + "\"";
} else {
command = "curl --silent --max-time 120 -L -k "+ URL + " -o " + responseFilePath;
command = "curl --silent --max-time 120 -L -k " + URL;
}

System.out.println("Attempting to get test duration data from TRSS.");
System.out.println(command);

try {
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;
}

File responseFile = new File(responseFilePath);
System.out.println("Response data written to file: " + responseFile.getAbsolutePath());

if (!responseFile.exists() || responseFile.length() == 0) {
System.out.println("Response file does not exist or is empty.");
return map;
}

StringBuilder responseData = new StringBuilder();
try (BufferedReader fileReader = new BufferedReader(new FileReader(responseFile))) {
String line;
while ((line = fileReader.readLine()) != null) {
responseData.append(line).append(System.lineSeparator());
}
} catch (IOException e) {
System.out.println("Error reading the response file: " + e.getMessage());
e.printStackTrace();
return map;
}

System.out.println("Response Data: " + responseData.toString());

try (Reader fileReader = new FileReader(responseFile)) {
parseDuration(fileReader, map);
} catch (IOException | ParseException e) {
System.out.println("Error reading or parsing the response file: " + e.getMessage());
e.printStackTrace();

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 from TRSS: " + e.getMessage());
System.out.println("Error executing curl command or reading input: " + e.getMessage());
e.printStackTrace();
return map;
}
return map;
}
Expand Down

0 comments on commit 6b83bd9

Please sign in to comment.