diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-08-11 15:51:36 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-08-16 08:20:14 +0200 |
commit | c6198890af6b3582bc353dc4864273d67a111f20 (patch) | |
tree | 8f38fd92e78d3db33b63883032703278c8c39231 /tests | |
parent | 825c3a67f6e5b7906a6f611201033cc5d1949fcb (diff) | |
download | sonarqube-c6198890af6b3582bc353dc4864273d67a111f20.tar.gz sonarqube-c6198890af6b3582bc353dc4864273d67a111f20.zip |
SONAR-7834 fix perf test as task duration is now in ce_activity.log
Diffstat (limited to 'tests')
5 files changed, 67 insertions, 35 deletions
diff --git a/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/MavenLogs.java b/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/MavenLogs.java index 69f0289f440..9386ba31e75 100644 --- a/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/MavenLogs.java +++ b/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/MavenLogs.java @@ -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; - } } diff --git a/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/ServerLogs.java b/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/ServerLogs.java index bc85ad04ae9..711ee1a59c6 100644 --- a/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/ServerLogs.java +++ b/tests/perf/src/main/java/org/sonarsource/sonarqube/perf/ServerLogs.java @@ -20,12 +20,15 @@ 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 index 00000000000..d1d9fe4ff7d --- /dev/null +++ b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/ServerLogsTest.java @@ -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); + } + +} diff --git a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/computation/ComputationTest.java b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/computation/ComputationTest.java index 85a9e0c99de..24b525b86cb 100644 --- a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/computation/ComputationTest.java +++ b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/computation/ComputationTest.java @@ -19,13 +19,11 @@ */ 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); } diff --git a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/MavenLogsTest.java b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/MavenLogsTest.java index 434c02510bf..d44fc0189d2 100644 --- a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/MavenLogsTest.java +++ b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/MavenLogsTest.java @@ -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); - } } |