]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7834 fix perf test as task duration is now in ce_activity.log
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 11 Aug 2016 13:51:36 +0000 (15:51 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 16 Aug 2016 06:20:14 +0000 (08:20 +0200)
tests/perf/src/main/java/org/sonarsource/sonarqube/perf/MavenLogs.java
tests/perf/src/main/java/org/sonarsource/sonarqube/perf/ServerLogs.java
tests/perf/src/test/java/org/sonarsource/sonarqube/perf/ServerLogsTest.java [new file with mode: 0644]
tests/perf/src/test/java/org/sonarsource/sonarqube/perf/computation/ComputationTest.java
tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/MavenLogsTest.java

index 69f0289f44050345d73d4ce170f043c75931ed42..9386ba31e7572dd309b6de293fe02ae2cc6a323b 100644 (file)
@@ -64,21 +64,4 @@ public class MavenLogs {
     }
     return null;
   }
-
-  /**
-   * 2015.09.29 16:57:45 INFO  web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms
-   */
-  public static Long extractComputationTotalTime(List<String> logs) {
-    Pattern pattern = Pattern.compile(".*INFO.*Executed task.* \\| time=(\\d+)ms.*");
-    for (int i = logs.size() - 1; i >= 0; i--) {
-      String line = logs.get(i);
-      Matcher matcher = pattern.matcher(line);
-      if (matcher.matches()) {
-        String duration = matcher.group(1);
-        return Long.parseLong(duration);
-      }
-    }
-
-    return null;
-  }
 }
index bc85ad04ae98c2c9cb4416702b23d4dcbdb216dd..711ee1a59c60d64b2c1e9474e6c50b186f6d3810 100644 (file)
 package org.sonarsource.sonarqube.perf;
 
 import com.sonar.orchestrator.Orchestrator;
-import org.apache.commons.io.FileUtils;
-
+import java.io.File;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.FileUtils;
 
 public class ServerLogs {
 
@@ -58,4 +61,27 @@ public class ServerLogs {
     }
   }
 
+  /**
+   * 2015.09.29 16:57:45 INFO ce[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms
+   */
+  public static Long extractComputationTotalTime(Orchestrator orchestrator) throws IOException {
+    File report = new File(orchestrator.getServer().getLogs().getParent(), "ce_activity.log");
+    List<String> logsLines = FileUtils.readLines(report, Charsets.UTF_8);
+    return extractComputationTotalTime(logsLines);
+  }
+
+  static Long extractComputationTotalTime(List<String> logs) {
+    Pattern pattern = Pattern.compile(".*INFO.*Executed task.* \\| time=(\\d+)ms.*");
+    for (int i = logs.size() - 1; i >= 0; i--) {
+      String line = logs.get(i);
+      Matcher matcher = pattern.matcher(line);
+      if (matcher.matches()) {
+        String duration = matcher.group(1);
+        return Long.parseLong(duration);
+      }
+    }
+
+    return null;
+  }
+
 }
diff --git a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/ServerLogsTest.java b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/ServerLogsTest.java
new file mode 100644 (file)
index 0000000..d1d9fe4
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarsource.sonarqube.perf;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ServerLogsTest {
+  @Test
+  public void logs_with_different_computations_take_the_last_one() throws Exception {
+    assertThat(ServerLogs.extractComputationTotalTime(Lists.newArrayList(
+      "2015.09.29 16:57:45 INFO  web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms",
+      "2015.09.29 16:57:45 INFO  web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=1234ms")))
+        .isEqualTo(1234L);
+  }
+
+}
index 85a9e0c99de50629049a6221f05166b11e8ec18d..24b525b86cb941fa1a68ddff8fe06fe2fab4ba10 100644 (file)
  */
 package org.sonarsource.sonarqube.perf.computation;
 
-import com.google.common.base.Charsets;
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
 import com.sonar.orchestrator.locator.FileLocation;
 import java.io.File;
 import java.io.IOException;
-import java.util.List;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
@@ -33,8 +31,8 @@ import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonarsource.sonarqube.perf.MavenLogs;
 import org.sonarsource.sonarqube.perf.PerfTestCase;
+import org.sonarsource.sonarqube.perf.ServerLogs;
 
 public class ComputationTest extends PerfTestCase {
   private static int MAX_HEAP_SIZE_IN_MEGA = 600;
@@ -82,9 +80,7 @@ public class ComputationTest extends PerfTestCase {
   }
 
   private void assertComputationDurationAround(long expectedDuration) throws IOException {
-    File report = new File(orchestrator.getServer().getLogs().getParent(), "sonar.log");
-    List<String> logsLines = FileUtils.readLines(report, Charsets.UTF_8);
-    Long duration = MavenLogs.extractComputationTotalTime(logsLines);
+    Long duration = ServerLogs.extractComputationTotalTime(orchestrator);
 
     assertDurationAround(duration, expectedDuration);
   }
index 434c02510bfb806a567f3bd84daaa36a715be979..d44fc0189d272f305deda968acb13a91ce3c67b5 100644 (file)
@@ -19,9 +19,8 @@
  */
 package org.sonarsource.sonarqube.perf.scanner;
 
-import com.google.common.collect.Lists;
-import org.sonarsource.sonarqube.perf.MavenLogs;
 import org.junit.Test;
+import org.sonarsource.sonarqube.perf.MavenLogs;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -41,12 +40,4 @@ public class MavenLogsTest {
   public void testEndMemory() throws Exception {
     assertThat(MavenLogs.extractEndMemory("  Final Memory: 68M/190M  ")).isEqualTo(68);
   }
-
-  @Test
-  public void logs_with_different_computations_take_the_last_one() throws Exception {
-    assertThat(MavenLogs.extractComputationTotalTime(Lists.newArrayList(
-      "2015.09.29 16:57:45 INFO  web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms",
-      "2015.09.29 16:57:45 INFO  web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=1234ms")))
-      .isEqualTo(1234L);
-  }
 }