This is an automated email from the ASF dual-hosted git repository.

kbowers pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-benchmarks.git

commit 95425f40e71ba7983cf864ac225ca2818d7cf56b
Author: Marián Macik <[email protected]>
AuthorDate: Tue May 4 21:18:50 2021 +0200

    Enhancements
---
 .../org/kie/kogito/benchmarks/framework/App.java   |   8 ++---
 .../kie/kogito/benchmarks/framework/Commands.java  |  36 ++++++++++++-------
 .../org/kie/kogito/benchmarks/framework/Logs.java  |  13 ++++---
 framework/src/main/resources/CtrlC.exe             | Bin 0 -> 120832 bytes
 framework/src/main/resources/README.md             |  39 +++++++++++++++++++++
 tests/pom.xml                                      |  17 +++++++++
 .../kogito/benchmarks/AbstractTemplateTest.java    |  20 ++---------
 7 files changed, 94 insertions(+), 39 deletions(-)

diff --git 
a/framework/src/main/java/org/kie/kogito/benchmarks/framework/App.java 
b/framework/src/main/java/org/kie/kogito/benchmarks/framework/App.java
index ab39a3a..34468a1 100644
--- a/framework/src/main/java/org/kie/kogito/benchmarks/framework/App.java
+++ b/framework/src/main/java/org/kie/kogito/benchmarks/framework/App.java
@@ -10,7 +10,7 @@ import java.util.Properties;
 
 import org.apache.commons.lang3.StringUtils;
 
-import static org.kie.kogito.benchmarks.framework.Commands.BASE_DIR;
+import static org.kie.kogito.benchmarks.framework.Commands.APPS_DIR;
 
 public enum App {
     SAMPLE_KOGITO_APP_QUARKUS_JVM("sample-kogito-app", MvnCmds.QUARKUS_JVM, 
URLContent.SAMPLE_KOGITO_APP, WhitelistLogLines.SAMPLE_KOGITO_APP),
@@ -30,7 +30,7 @@ public enum App {
         this.mavenCommands = mavenCommands;
         this.urlContent = urlContent;
         this.whitelistLogLines = whitelistLogLines;
-        File tpFile = new File(BASE_DIR + File.separator + dir + 
File.separator + "threshold.properties");
+        File tpFile = new File(APPS_DIR + File.separator + dir + 
File.separator + "threshold.properties");
         String appDirNormalized = dir.toUpperCase().replace('-', '_') + "_";
         try (InputStream input = new FileInputStream(tpFile)) {
             Properties props = new Properties();
@@ -55,7 +55,7 @@ public enum App {
         }
     }
 
-    public File getAppDir(String parent) {
-        return new File(parent + File.separator + dir);
+    public File getAppDir() {
+        return new File(APPS_DIR, dir);
     }
 }
diff --git 
a/framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java 
b/framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
index de70e59..231c1fa 100644
--- a/framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
+++ b/framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
@@ -47,6 +47,7 @@ public class Commands {
     private static final Logger LOGGER = 
Logger.getLogger(Commands.class.getName());
 
     public static final String BASE_DIR = getBaseDir();
+    public static final String APPS_DIR = getAppsDir();
     public static final String MVNW = Commands.isThisWindows ? "mvnw.cmd" : 
"./mvnw";
     public static final boolean isThisWindows = 
System.getProperty("os.name").matches(".*[Ww]indows.*");
     private static final Pattern numPattern = Pattern.compile("[ \t]*[0-9]+[ 
\t]*");
@@ -136,15 +137,26 @@ public class Commands {
     }
 
     public static String getBaseDir() {
-        String env = System.getenv().get("basedir");
-        String sys = System.getProperty("basedir");
-        if (StringUtils.isNotBlank(env)) {
-            return new File(env).getParent();
+        String baseDirValue = getSystemPropertyOrEnvVarValue("basedir");
+        return new File(baseDirValue).getParent();
+    }
+
+    public static String getAppsDir() {
+        return getSystemPropertyOrEnvVarValue("appsDir");
+    }
+
+    private static String getSystemPropertyOrEnvVarValue(String name) {
+        String systemPropertyValue = System.getProperty(name);
+        if (StringUtils.isNotBlank(systemPropertyValue)) {
+            return systemPropertyValue;
         }
-        if (StringUtils.isBlank(sys)) {
-            throw new IllegalArgumentException("Unable to determine 
project.basedir.");
+
+        String envPropertyValue = System.getenv(name);
+
+        if (StringUtils.isBlank(envPropertyValue)) {
+            throw new IllegalArgumentException("Unable to determine the value 
of the property " + name);
         }
-        return new File(sys).getParent();
+        return envPropertyValue;
     }
 
     public static String getCodeQuarkusURL() {
@@ -178,13 +190,13 @@ public class Commands {
     }
 
     public static void cleanTarget(App app) {
-        String target = BASE_DIR + File.separator + app.dir + File.separator + 
"target";
-        String logs = BASE_DIR + File.separator + app.dir + File.separator + 
"logs";
+        String target = APPS_DIR + File.separator + app.dir + File.separator + 
"target";
+        String logs = APPS_DIR + File.separator + app.dir + File.separator + 
"logs";
         cleanDirOrFile(target, logs);
     }
 
     public static BuildResult buildApp(App app, String methodName, String 
className, StringBuilder whatIDidReport) throws InterruptedException {
-        File appDir = app.getAppDir(BASE_DIR);
+        File appDir = app.getAppDir();
         File buildLogA = new File(appDir.getAbsolutePath() + File.separator + 
"logs" + File.separator + app.mavenCommands.name().toLowerCase() + 
"-build.log");
         ExecutorService buildService = Executors.newFixedThreadPool(1);
 
@@ -207,7 +219,7 @@ public class Commands {
     }
 
     public static RunInfo startApp(App app, StringBuilder whatIDidReport) 
throws IOException, InterruptedException {
-        File appDir = app.getAppDir(BASE_DIR);
+        File appDir = app.getAppDir();
         File runLogA = new File(appDir.getAbsolutePath() + File.separator + 
"logs" + File.separator + app.mavenCommands.name().toLowerCase() + "-run.log");
         List<String> cmd = getRunCommand(app.mavenCommands.mvnCmds[1]);
         appendln(whatIDidReport, appDir.getAbsolutePath());
@@ -448,7 +460,7 @@ public class Commands {
             if (isThisWindows) {
                 if (!force) {
                     Process p = Runtime.getRuntime().exec(new String[] {
-                            BASE_DIR + File.separator + "testsuite" + 
File.separator + "src" + File.separator + "it" + File.separator + "resources" + 
File.separator +
+                            BASE_DIR + File.separator + "framework" + 
File.separator + "src" + File.separator + "main" + File.separator + "resources" 
+ File.separator +
                                     "CtrlC.exe ",
                             Long.toString(pid) });
                     p.waitFor(1, TimeUnit.MINUTES);
diff --git 
a/framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java 
b/framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
index dba7874..fb781fc 100644
--- a/framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
+++ b/framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
@@ -7,7 +7,6 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Scanner;
@@ -230,8 +229,7 @@ public class Logs {
     }
 
     public static Path getLogsDir() throws IOException {
-        Path destDir = new File(BASE_DIR + File.separator + "testsuite" + 
File.separator + "target" +
-                File.separator + "archived-logs").toPath();
+        Path destDir = new File(BASE_DIR + File.separator + "tests" + 
File.separator + "archived-logs").toPath();
         Files.createDirectories(destDir);
         return destDir;
     }
@@ -253,7 +251,7 @@ public class Logs {
 
         List<String> lines = 
Files.lines(path).collect(Collectors.toCollection(ArrayList::new));
         String currentHeader = lines.get(0);
-        String headerWithoutAppAndMode = 
Arrays.stream(log.headerCSV.split(",")).skip(2).collect(Collectors.joining(","));
+        String headerWithoutAppAndMode = stripAppAndModeColumns(log.headerCSV);
         if (!currentHeader.contains(headerWithoutAppAndMode)) {
             lines.set(0, currentHeader + "," + headerWithoutAppAndMode);
             currentHeader = lines.get(0);
@@ -264,7 +262,7 @@ public class Logs {
         long headerLength = currentHeader.chars().filter(value -> value == 
',').count();
         long lastLineLength = lastLine.chars().filter(value -> value == 
',').count();
         if (lastLineLength < headerLength) {
-            String newDataWithoutAppAndMode = 
Arrays.stream(log.lineCSV.split(",")).skip(2).collect(Collectors.joining(","));
+            String newDataWithoutAppAndMode = 
stripAppAndModeColumns(log.lineCSV);
             lines.set(lines.size() - 1, lastLine + "," + 
newDataWithoutAppAndMode);
         } else {
             lines.add(log.lineCSV);
@@ -275,6 +273,11 @@ public class Logs {
         LOGGER.info("\n" + log.headerCSV + "\n" + log.lineCSV);
     }
 
+    private static String stripAppAndModeColumns(String line) {
+        int secondOccurrence = line.indexOf(",", line.indexOf(",") + 1);
+        return line.substring(secondOccurrence + 1);
+    }
+
     /**
      * List Jar file names failing regexp pattern check
      *
diff --git a/framework/src/main/resources/CtrlC.exe 
b/framework/src/main/resources/CtrlC.exe
new file mode 100644
index 0000000..8b03861
Binary files /dev/null and b/framework/src/main/resources/CtrlC.exe differ
diff --git a/framework/src/main/resources/README.md 
b/framework/src/main/resources/README.md
new file mode 100644
index 0000000..c135692
--- /dev/null
+++ b/framework/src/main/resources/README.md
@@ -0,0 +1,39 @@
+# CtrlC.exe
+
+When you start Quarkus on Windows as a process without
+a console window, you cannot stop it gently with TASKKILL, 
+you have to use TASKKILL /F. That terminates the process immediately
+and it does not let it write "stopped in" to the process output.
+
+To mitigate this, you have to use a native Windows API with
+a small tool that detaches itself from its own console,
+attaches to the non-existing console of the PID you want
+to stop and sends it Ctrl+C.
+
+```$c
+
+#include <windows.h>
+#include <stdio.h>
+
+void ctrlC(int pid) {
+    FreeConsole();
+    if (AttachConsole(pid)) {
+        SetConsoleCtrlHandler(NULL, true);
+        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
+    }
+    exit(1);
+}
+
+int main(int argc, const char* argv[]) {
+    if (argc != 2) {
+        printf("provide a pid number");
+        return 1;
+    }
+    int pid = atoi(argv[1]);
+    printf("stopping pid %d", pid);
+    ctrlC(pid);
+    return 0;
+}
+
+``` 
+
diff --git a/tests/pom.xml b/tests/pom.xml
index 38a9d04..5274a7b 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -15,6 +15,10 @@
   <name></name>
   <description></description>
 
+  <properties>
+    <appsDir>${project.parent.basedir}/</appsDir>
+  </properties>
+
   <dependencyManagement>
     <dependencies>
       <dependency>
@@ -38,4 +42,17 @@
     </dependency>
   </dependencies>
 
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <appsDir>${appsDir}</appsDir>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
 </project>
\ No newline at end of file
diff --git 
a/tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java 
b/tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
index e9d93dd..27260ed 100644
--- a/tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
+++ b/tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
@@ -2,30 +2,17 @@ package org.kie.kogito.benchmarks;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.net.URL;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.time.Duration;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-import java.util.Scanner;
-import java.util.stream.Collectors;
 
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
 import org.assertj.core.api.Assertions;
@@ -40,7 +27,6 @@ import org.kie.kogito.benchmarks.framework.MvnCmds;
 import org.kie.kogito.benchmarks.framework.RunInfo;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.kie.kogito.benchmarks.framework.Commands.BASE_DIR;
 import static org.kie.kogito.benchmarks.framework.Commands.buildApp;
 import static org.kie.kogito.benchmarks.framework.Commands.cleanTarget;
 import static org.kie.kogito.benchmarks.framework.Commands.getOpenedFDs;
@@ -73,7 +59,7 @@ public abstract class AbstractTemplateTest {
         File buildLogA = null;
         File runLogA = null;
         StringBuilder whatIDidReport = new StringBuilder();
-        File appDir = app.getAppDir(BASE_DIR);
+        File appDir = app.getAppDir();
         MvnCmds mvnCmds = app.mavenCommands;
         String cn = testInfo.getTestClass().get().getCanonicalName();
         String mn = testInfo.getTestMethod().get().getName();
@@ -193,7 +179,7 @@ public abstract class AbstractTemplateTest {
         File buildLogA = null;
         File runLogA = null;
         StringBuilder whatIDidReport = new StringBuilder();
-        File appDir = app.getAppDir(BASE_DIR);
+        File appDir = app.getAppDir();
         MvnCmds mvnCmds = app.mavenCommands;
         String cn = testInfo.getTestClass().get().getCanonicalName();
         String mn = testInfo.getTestMethod().get().getName();
@@ -302,8 +288,6 @@ public abstract class AbstractTemplateTest {
             long endTime = System.currentTimeMillis();
 
             System.out.println("First response time: " + values.get(0));
-            System.out.println("Second response time: " + values.get(1));
-            System.out.println("Third response time: " + values.get(2));
             System.out.println("Average response time: " + 
values.stream().mapToLong(Long::longValue).skip(1).average());
             System.out.println("Total duration: " + (endTime - startTime));
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to