From 38242dc18f85afbf8a134ffbe48be5cf8e98eceb Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 9 Nov 2016 16:22:08 +0100 Subject: [PATCH] SONAR-8333 use orchestrator 3.13-build783 to fix SQ ITs based on logs --- .../java/it/qualityGate/QualityGateTest.java | 2 +- .../java/it/serverSystem/ClusterTest.java | 10 +++---- .../java/it/serverSystem/RestartTest.java | 4 +-- .../ServerSystemRestartingOrchestrator.java | 4 +-- .../it/serverSystem/ServerSystemTest.java | 2 +- .../test/java/it/settings/SettingsTest.java | 3 +- .../it/user/BaseIdentityProviderTest.java | 2 +- .../java/it/user/SsoAuthenticationTest.java | 2 +- it/it-tests/src/test/java/util/ItUtils.java | 29 +++++++------------ pom.xml | 2 +- .../sonarqube/perf/ServerLogs.java | 6 ++-- .../sonarqube/perf/server/ServerTest.java | 2 +- 12 files changed, 30 insertions(+), 38 deletions(-) diff --git a/it/it-tests/src/test/java/it/qualityGate/QualityGateTest.java b/it/it-tests/src/test/java/it/qualityGate/QualityGateTest.java index fb82d80c56f..46b3160a667 100644 --- a/it/it-tests/src/test/java/it/qualityGate/QualityGateTest.java +++ b/it/it-tests/src/test/java/it/qualityGate/QualityGateTest.java @@ -259,7 +259,7 @@ public class QualityGateTest { } private void verifyQGStatusInPostTask(BuildResult buildResult, String taskStatus, String qgStatus) throws IOException { - List logsLines = FileUtils.readLines(orchestrator.getServer().getLogs(), Charsets.UTF_8); + List logsLines = FileUtils.readLines(orchestrator.getServer().getCeLogs(), Charsets.UTF_8); List postTaskLogLines = extractPosttaskPluginLogs(extractCeTaskId(buildResult), logsLines); assertThat(postTaskLogLines).hasSize(1); diff --git a/it/it-tests/src/test/java/it/serverSystem/ClusterTest.java b/it/it-tests/src/test/java/it/serverSystem/ClusterTest.java index bf2640ab9af..4b50204454e 100644 --- a/it/it-tests/src/test/java/it/serverSystem/ClusterTest.java +++ b/it/it-tests/src/test/java/it/serverSystem/ClusterTest.java @@ -71,7 +71,7 @@ public class ClusterTest { // verify that datastores are populated by requesting rules assertThat(newWsClient(orchestrator).rules().search(new SearchWsRequest()).getTotal()).isGreaterThan(0); - FileUtils.write(orchestrator.getServer().getLogs(), "", false); + FileUtils.write(orchestrator.getServer().getWebLogs(), "", false); updateSonarPropertiesFile(orchestrator, ImmutableMap.of("sonar.cluster.web.startupLeader", "false")); orchestrator.restartServer(); @@ -96,7 +96,7 @@ public class ClusterTest { .build(); elasticsearch.start(); assertThat(esWatcher.port).isGreaterThan(0); - assertThat(FileUtils.readFileToString(elasticsearch.getServer().getLogs())).doesNotContain("Process[web]"); + assertThat(FileUtils.readFileToString(elasticsearch.getServer().getAppLogs())).doesNotContain("Process[web]"); web = Orchestrator.builderEnv() .setServerProperty("sonar.cluster.enabled", "true") @@ -114,7 +114,7 @@ public class ClusterTest { String coreId = getPropertyValue(web, "sonar.core.id"); String startTime = getPropertyValue(web, "sonar.core.startTime"); - assertThat(FileUtils.readFileToString(elasticsearch.getServer().getLogs())).doesNotContain("Process[es]"); + assertThat(FileUtils.readFileToString(elasticsearch.getServer().getAppLogs())).doesNotContain("Process[es]"); // call a web service that requires Elasticsearch Issues.SearchWsResponse wsResponse = ItUtils.newWsClient(web).issues().search(new org.sonarqube.ws.client.issue.SearchWsRequest()); assertThat(wsResponse.getIssuesCount()).isEqualTo(0); @@ -160,14 +160,14 @@ public class ClusterTest { } private static void expectLog(Orchestrator orchestrator, String expectedLog) throws IOException { - File logFile = orchestrator.getServer().getLogs(); + File logFile = orchestrator.getServer().getWebLogs(); try (Stream lines = Files.lines(logFile.toPath())) { assertThat(lines.anyMatch(s -> StringUtils.containsIgnoreCase(s, expectedLog))).isTrue(); } } private static void expectWriteOperations(Orchestrator orchestrator, boolean expected) throws IOException { - try (Stream lines = Files.lines(orchestrator.getServer().getLogs().toPath())) { + try (Stream lines = Files.lines(orchestrator.getServer().getWebLogs().toPath())) { List writeOperations = lines.filter(ClusterTest::isWriteOperation).collect(Collectors.toList()); if (expected) { assertThat(writeOperations).isNotEmpty(); diff --git a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java index e7ffaf50e53..cbb6abb5e90 100644 --- a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java +++ b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java @@ -81,7 +81,7 @@ public class RestartTest { // we just wait five seconds, for a lack of a better approach to waiting for the restart process to start in SQ Thread.sleep(5000); - assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())) + assertThat(FileUtils.readFileToString(orchestrator.getServer().getWebLogs())) .contains("SonarQube restart requested by big"); } } @@ -99,7 +99,7 @@ public class RestartTest { orchestrator.start(); newAdminWsClient(orchestrator).system().restart(); - assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())) + assertThat(FileUtils.readFileToString(orchestrator.getServer().getWebLogs())) .contains("Fast restarting WebServer...") .contains("WebServer restarted"); } diff --git a/it/it-tests/src/test/java/it/serverSystem/ServerSystemRestartingOrchestrator.java b/it/it-tests/src/test/java/it/serverSystem/ServerSystemRestartingOrchestrator.java index ef91d1d7298..8161521a34b 100644 --- a/it/it-tests/src/test/java/it/serverSystem/ServerSystemRestartingOrchestrator.java +++ b/it/it-tests/src/test/java/it/serverSystem/ServerSystemRestartingOrchestrator.java @@ -63,7 +63,7 @@ public class ServerSystemRestartingOrchestrator { orchestrator.start(); fail(); } catch (Exception e) { - assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())).contains( + assertThat(FileUtils.readFileToString(orchestrator.getServer().getWebLogs())).contains( "Plugin incompatible-plugin [incompatibleplugin] requires at least SonarQube 100"); } } @@ -92,7 +92,7 @@ public class ServerSystemRestartingOrchestrator { File tempDir = new File(orchestrator.getServer().getHome(), "temp/tmp"); - String logs = FileUtils.readFileToString(orchestrator.getServer().getLogs()); + String logs = FileUtils.readFileToString(orchestrator.getServer().getWebLogs()); assertThat(logs).contains("Creating temp directory: " + tempDir.getAbsolutePath() + File.separator + "sonar-it"); assertThat(logs).contains("Creating temp file: " + tempDir.getAbsolutePath() + File.separator + "sonar-it"); diff --git a/it/it-tests/src/test/java/it/serverSystem/ServerSystemTest.java b/it/it-tests/src/test/java/it/serverSystem/ServerSystemTest.java index 86507c184a0..0c67af41e8b 100644 --- a/it/it-tests/src/test/java/it/serverSystem/ServerSystemTest.java +++ b/it/it-tests/src/test/java/it/serverSystem/ServerSystemTest.java @@ -130,7 +130,7 @@ public class ServerSystemTest { private static void waitForComputeEngineToBeUp(Orchestrator orchestrator) throws IOException { for (int i = 0; i < 10_000; i++) { - File logs = orchestrator.getServer().getLogs(); + File logs = orchestrator.getServer().getCeLogs(); if (FileUtils.readFileToString(logs).contains("Compute Engine is up")) { return; } diff --git a/it/it-tests/src/test/java/it/settings/SettingsTest.java b/it/it-tests/src/test/java/it/settings/SettingsTest.java index e9b1ea0a06a..41fc8df8296 100644 --- a/it/it-tests/src/test/java/it/settings/SettingsTest.java +++ b/it/it-tests/src/test/java/it/settings/SettingsTest.java @@ -67,7 +67,8 @@ public class SettingsTest { @Test public void global_property_change_extension_point() throws IOException { SETTINGS.set(SetRequest.builder().setKey("globalPropertyChange.received").setValue("NEWVALUE").build()); - assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())).contains("Received change: [key=globalPropertyChange.received, newValue=NEWVALUE]"); + assertThat(FileUtils.readFileToString(orchestrator.getServer().getWebLogs())) + .contains("Received change: [key=globalPropertyChange.received, newValue=NEWVALUE]"); } @Test diff --git a/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java b/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java index 2801b4e3d48..c5408415336 100644 --- a/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java +++ b/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java @@ -193,7 +193,7 @@ public class BaseIdentityProviderTest { new SeleneseTest(Selenese.builder().setHtmlTestsInClasspath("fail_to_authenticate_when_not_allowed_to_sign_up", "/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html").build()).runOn(ORCHESTRATOR); - File logFile = ORCHESTRATOR.getServer().getLogs(); + File logFile = ORCHESTRATOR.getServer().getWebLogs(); assertThat(FileUtils.readFileToString(logFile)).doesNotContain("A functional error has happened"); assertThat(FileUtils.readFileToString(logFile)).doesNotContain("UnauthorizedException"); diff --git a/it/it-tests/src/test/java/it/user/SsoAuthenticationTest.java b/it/it-tests/src/test/java/it/user/SsoAuthenticationTest.java index d13ff117f46..76543eb289e 100644 --- a/it/it-tests/src/test/java/it/user/SsoAuthenticationTest.java +++ b/it/it-tests/src/test/java/it/user/SsoAuthenticationTest.java @@ -132,7 +132,7 @@ public class SsoAuthenticationTest { assertThat(response.code()).isEqualTo(200); assertThat(response.body().string()).contains("You're not authorized to access this page. Please contact the administrator"); - List logsLines = FileUtils.readLines(orchestrator.getServer().getLogs(), Charsets.UTF_8); + List logsLines = FileUtils.readLines(orchestrator.getServer().getWebLogs(), Charsets.UTF_8); assertThat(logsLines).doesNotContain("org.sonar.server.exceptions.BadRequestException: user.bad_login"); USER_RULE.verifyUserDoesNotExist(USER_LOGIN); } diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java index 871b2778447..e445b242f15 100644 --- a/it/it-tests/src/test/java/util/ItUtils.java +++ b/it/it-tests/src/test/java/util/ItUtils.java @@ -19,11 +19,8 @@ */ package util; -import com.google.common.base.Function; -import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.sonar.orchestrator.Orchestrator; @@ -36,11 +33,15 @@ import java.io.IOException; import java.lang.reflect.Type; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.json.simple.JSONArray; @@ -57,10 +58,8 @@ import org.sonarqube.ws.client.setting.ResetRequest; import org.sonarqube.ws.client.setting.SetRequest; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.FluentIterable.from; import static com.sonar.orchestrator.container.Server.ADMIN_LOGIN; import static com.sonar.orchestrator.container.Server.ADMIN_PASSWORD; -import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -252,7 +251,8 @@ public class ItUtils { if (properties == null || properties.length == 0) { return str; } - return from(Iterables.concat(asList(properties), asList(str))).toArray(String.class); + return Stream.concat(Arrays.stream(properties), Arrays.stream(str)) + .toArray(String[]::new); } public static void verifyHttpException(Exception e, int expectedCode) { @@ -283,19 +283,10 @@ public class ItUtils { public static List extractCeTaskIds(BuildResult buildResult) { String logs = buildResult.getLogs(); - return from(LINE_SPLITTER.split(logs)) - .filter(new Predicate() { - @Override - public boolean apply(String s) { - return s.contains("More about the report processing at"); - } - }).transform(new Function() { - @Nullable - @Override - public String apply(String s) { - return s.substring(s.length() - 20, s.length()); - } - }).toList(); + return StreamSupport.stream(LINE_SPLITTER.split(logs).spliterator(), false) + .filter(s -> s.contains("More about the report processing at")) + .map(s -> s.substring(s.length() - 20, s.length())) + .collect(Collectors.toList()); } public static Map jsonToMap(String json) { diff --git a/pom.xml b/pom.xml index 68397c3753c..ba557d6ab11 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ 1.7.21 8.0.32 2.3.5 - 3.13-build640 + 3.13-build783 3.3.1 2.6.6 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 9bacd727c2f..5549395c963 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 @@ -56,8 +56,8 @@ public class ServerLogs { } public static void clear(Orchestrator orch) throws IOException { - if (orch.getServer() != null && orch.getServer().getLogs() != null) { - FileUtils.write(orch.getServer().getLogs(), "", false); + if (orch.getServer() != null && orch.getServer().getCeLogs() != null) { + FileUtils.write(orch.getServer().getCeLogs(), "", false); } } @@ -65,7 +65,7 @@ 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 = orchestrator.getServer().getLogs(); + File report = orchestrator.getServer().getCeLogs(); List logsLines = FileUtils.readLines(report, Charsets.UTF_8); return extractComputationTotalTime(logsLines); } diff --git a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/server/ServerTest.java b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/server/ServerTest.java index d0c17e807ff..b53b5efb9ac 100644 --- a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/server/ServerTest.java +++ b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/server/ServerTest.java @@ -106,6 +106,6 @@ public class ServerTest extends PerfTestCase { } private static List readLogLines(Orchestrator orchestrator) throws IOException { - return FileUtils.readLines(orchestrator.getServer().getLogs()); + return FileUtils.readLines(orchestrator.getServer().getCeLogs()); } } -- 2.39.5