You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2022/08/23 19:04:25 UTC

[camel-quarkus] branch main updated: perf-regresssion: fix number format exception when java and mvnw don't have same default locale #4014

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

aldettinger pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new df16457ffc perf-regresssion: fix number format exception when java and mvnw don't have same default locale #4014
df16457ffc is described below

commit df16457ffc784559f999a0e06000727e323fb47a
Author: aldettinger <al...@gmail.com>
AuthorDate: Mon Aug 22 10:42:58 2022 +0200

    perf-regresssion: fix number format exception when java and mvnw don't have same default locale #4014
---
 .../performance/regression/MvnwCmdHelper.java      |  6 +++---
 .../regression/PerfRegressionCommand.java          | 15 +++++++++++++--
 .../regression/PerformanceRegressionReport.java    |  6 ++++--
 .../regression/it/PerfRegressionIT.java            | 22 ++++++++++++++++++++--
 4 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/MvnwCmdHelper.java b/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/MvnwCmdHelper.java
index e1fb18f23d..380d7494e6 100644
--- a/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/MvnwCmdHelper.java
+++ b/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/MvnwCmdHelper.java
@@ -68,14 +68,14 @@ public class MvnwCmdHelper {
 
             Map<String, String> environment = EnvironmentUtils.getProcEnvironment();
 
-            String newMavenOpts = "MAVEN_OPTS=--add-opens java.base/java.lang=ALL-UNNAMED";
+            String newMavenOpts = "-Duser.language=en -Duser.country=US --add-opens java.base/java.lang=ALL-UNNAMED";
             if (environment.containsKey("MAVEN_OPTS")) {
                 String currentMavenOpts = environment.get("MAVEN_OPTS");
                 LOGGER.debugf("MAVEN_OPTS is already set up in the main process with value: %s", currentMavenOpts);
-                newMavenOpts = "MAVEN_OPTS=" + currentMavenOpts + " --add-opens java.base/java.lang=ALL-UNNAMED";
+                newMavenOpts = currentMavenOpts + " " + newMavenOpts;
             }
             LOGGER.debugf("Setting MAVEN_OPTS in child process with value: %s", newMavenOpts);
-            EnvironmentUtils.addVariableToEnvironment(environment, newMavenOpts);
+            EnvironmentUtils.addVariableToEnvironment(environment, "MAVEN_OPTS=" + newMavenOpts);
 
             int exitValue = executor.execute(cmd, environment);
             String outAndErr = stdoutAndStderrMemoryStream.toString(StandardCharsets.UTF_8);
diff --git a/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerfRegressionCommand.java b/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerfRegressionCommand.java
index 8703fb99d1..a07100766e 100644
--- a/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerfRegressionCommand.java
+++ b/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerfRegressionCommand.java
@@ -20,6 +20,9 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.RegExUtils;
@@ -30,6 +33,8 @@ import picocli.CommandLine.Parameters;
 @picocli.CommandLine.Command(description = "Run a performance test against a list of Camel Quarkus versions and print a report")
 public class PerfRegressionCommand implements Runnable {
 
+    private static NumberFormat US_NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
+
     private static Path PERF_SAMPLE_TEMPLATE_FOLDER = Paths.get("cq-perf-regression-sample-base");
 
     @Parameters(paramLabel = "<versions>", arity = "1..*", description = "A list of versions, e.g: 2.7.0 2.8.0-SNAPSHOT")
@@ -113,8 +118,14 @@ public class PerfRegressionCommand implements Runnable {
         String stdout = MvnwCmdHelper.execute(cqVersionUnderTestFolder, args);
 
         // Extract the throughput from a log line like "15:26:23,110 INFO  (main) [i.h.m.RunMojo] Requests/sec: 1153.56"
-        String throughput = RegExUtils.replacePattern(stdout, ".*RunMojo] Requests/sec: ([0-9.,]+).*", "$1");
-        return Double.parseDouble(throughput);
+        String throughput = RegExUtils.replacePattern(stdout, ".*RunMojo] Requests/sec: ([0-9.]+).*", "$1");
+
+        try {
+            return US_NUMBER_FORMAT.parse(throughput).doubleValue();
+        } catch (ParseException pex) {
+            throw new RuntimeException(
+                    "An issue occured while parsing the mean throughput measured by the hyperfoil-maven-plugin", pex);
+        }
     }
 
 }
diff --git a/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerformanceRegressionReport.java b/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerformanceRegressionReport.java
index efd54ebe8f..8d1c0f1fa0 100644
--- a/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerformanceRegressionReport.java
+++ b/tooling/perf-regression/src/main/java/org/apache/camel/quarkus/performance/regression/PerformanceRegressionReport.java
@@ -17,6 +17,7 @@
 package org.apache.camel.quarkus.performance.regression;
 
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -63,7 +64,7 @@ public class PerformanceRegressionReport {
             double jvmMeasure = measurePerVersion.getValue().get("JVM");
             double percentIncreaseJvm = (previousJvmMeasure == Double.POSITIVE_INFINITY) ? 0.0
                     : ((jvmMeasure / previousJvmMeasure) - 1.0) * 100.0;
-            jvmMeasuresColumn.append(String.format("%.2f req/s [%+.2f%%]", jvmMeasure, percentIncreaseJvm));
+            jvmMeasuresColumn.append(String.format(Locale.US, "%.2f req/s [%+.2f%%]", jvmMeasure, percentIncreaseJvm));
             previousJvmMeasure = jvmMeasure;
             if (percentIncreaseJvm <= -5.00) {
                 regressionDetected = true;
@@ -73,7 +74,8 @@ public class PerformanceRegressionReport {
                 double nativeMeasure = measurePerVersion.getValue().get("Native");
                 double percentIncreaseNative = (previousNativeMeasure == Double.POSITIVE_INFINITY) ? 0.0
                         : ((nativeMeasure / previousNativeMeasure) - 1.0) * 100.0;
-                nativeMeasuresColumn.append(String.format("%.2f req/s [%+.2f%%]", nativeMeasure, percentIncreaseNative));
+                nativeMeasuresColumn
+                        .append(String.format(Locale.US, "%.2f req/s [%+.2f%%]", nativeMeasure, percentIncreaseNative));
                 previousNativeMeasure = nativeMeasure;
                 if (percentIncreaseNative <= -5.00) {
                     regressionDetected = true;
diff --git a/tooling/perf-regression/src/test/java/org/apache/camel/quarkus/performance/regression/it/PerfRegressionIT.java b/tooling/perf-regression/src/test/java/org/apache/camel/quarkus/performance/regression/it/PerfRegressionIT.java
index fc0d50d93b..fc130ee2a5 100644
--- a/tooling/perf-regression/src/test/java/org/apache/camel/quarkus/performance/regression/it/PerfRegressionIT.java
+++ b/tooling/perf-regression/src/test/java/org/apache/camel/quarkus/performance/regression/it/PerfRegressionIT.java
@@ -18,9 +18,14 @@ package org.apache.camel.quarkus.performance.regression.it;
 
 import java.io.IOException;
 import java.util.concurrent.TimeoutException;
+import java.util.stream.Stream;
 
 import org.apache.commons.lang3.StringUtils;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.zeroturnaround.exec.InvalidExitValueException;
 import org.zeroturnaround.exec.ProcessExecutor;
 
@@ -52,14 +57,27 @@ public class PerfRegressionIT {
         }
     }
 
-    @Test
-    void nominalShouldPrintReport() throws IOException, InterruptedException, TimeoutException {
+    private static Stream<String> getSelectLocales() {
+        return Stream.of("fr_FR", "de_DE", "it_IT", "cs_CZ", "zh_CN", "ja_JP", "ar_JO");
+    }
+
+    @Disabled("This long test is meant to be run when diagnosing locale issues only")
+    @ParameterizedTest
+    @MethodSource("getSelectLocales")
+    void nominalTestShouldBehaveTheSameAgainstSelectLocales(String locale)
+            throws IOException, InterruptedException, TimeoutException {
+        nominalShouldPrintReport(locale);
+    }
 
+    @ParameterizedTest
+    @ValueSource(strings = { "en_US" })
+    void nominalShouldPrintReport(String locale) throws IOException, InterruptedException, TimeoutException {
         try {
             String cqVersion = System.getProperty("camel.quarkus.version");
 
             String processOutput = new ProcessExecutor()
                     .command("java", "-jar", "target/quarkus-app/quarkus-run.jar", "-d", "1s", cqVersion)
+                    .environment("LANG", locale + ".UTF-8")
                     .readOutput(true)
                     .exitValue(0)
                     .execute()