Skip to content

Commit

Permalink
SONAR-8333 use orchestrator 3.13-build783 to fix SQ ITs based on logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Nov 16, 2016
1 parent 8acb0ed commit 38242dc
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void ad_hoc_build_break_strategy() throws IOException {
}

private void verifyQGStatusInPostTask(BuildResult buildResult, String taskStatus, String qgStatus) throws IOException {
List<String> logsLines = FileUtils.readLines(orchestrator.getServer().getLogs(), Charsets.UTF_8);
List<String> logsLines = FileUtils.readLines(orchestrator.getServer().getCeLogs(), Charsets.UTF_8);
List<String> postTaskLogLines = extractPosttaskPluginLogs(extractCeTaskId(buildResult), logsLines);

assertThat(postTaskLogLines).hasSize(1);
Expand Down
10 changes: 5 additions & 5 deletions it/it-tests/src/test/java/it/serverSystem/ClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void secondary_nodes_do_not_write_to_datastores_at_startup() throws Excep
// 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();

Expand All @@ -96,7 +96,7 @@ public void start_cluster_of_elasticsearch_and_web_nodes() throws IOException {
.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")
Expand All @@ -114,7 +114,7 @@ public void start_cluster_of_elasticsearch_and_web_nodes() throws IOException {
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);
Expand Down Expand Up @@ -160,14 +160,14 @@ public boolean isStarted(String log) {
}

private static void expectLog(Orchestrator orchestrator, String expectedLog) throws IOException {
File logFile = orchestrator.getServer().getLogs();
File logFile = orchestrator.getServer().getWebLogs();
try (Stream<String> 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<String> lines = Files.lines(orchestrator.getServer().getLogs().toPath())) {
try (Stream<String> lines = Files.lines(orchestrator.getServer().getWebLogs().toPath())) {
List<String> writeOperations = lines.filter(ClusterTest::isWriteOperation).collect(Collectors.toList());
if (expected) {
assertThat(writeOperations).isNotEmpty();
Expand Down
4 changes: 2 additions & 2 deletions it/it-tests/src/test/java/it/serverSystem/RestartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void restart_in_prod_mode_requires_root_and_restarts_WebServer_and_ES() t
// 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");
}
}
Expand All @@ -99,7 +99,7 @@ public void restart_on_dev_mode() throws Exception {
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void check_minimal_sonar_version_at_startup() throws Exception {
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");
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ public void should_create_in_temp_folder() throws Exception {

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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void download_system_info() throws Exception {

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;
}
Expand Down
3 changes: 2 additions & 1 deletion it/it-tests/src/test/java/it/settings/SettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void reset_settings() throws Exception {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void display_message_in_ui_but_not_in_log_when_unauthorized_exception() t
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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void display_message_in_ui_but_not_in_log_when_unauthorized_exception() t
assertThat(response.code()).isEqualTo(200);
assertThat(response.body().string()).contains("You're not authorized to access this page. Please contact the administrator");

List<String> logsLines = FileUtils.readLines(orchestrator.getServer().getLogs(), Charsets.UTF_8);
List<String> 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);
}
Expand Down
29 changes: 10 additions & 19 deletions it/it-tests/src/test/java/util/ItUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,11 +33,15 @@
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;
Expand All @@ -57,10 +58,8 @@
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;

Expand Down Expand Up @@ -252,7 +251,8 @@ public static String[] concat(String[] properties, String... str) {
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) {
Expand Down Expand Up @@ -283,19 +283,10 @@ public static String extractCeTaskId(BuildResult buildResult) {

public static List<String> extractCeTaskIds(BuildResult buildResult) {
String logs = buildResult.getLogs();
return from(LINE_SPLITTER.split(logs))
.filter(new Predicate<String>() {
@Override
public boolean apply(String s) {
return s.contains("More about the report processing at");
}
}).transform(new Function<String, String>() {
@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<String, Object> jsonToMap(String json) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<slf4j.version>1.7.21</slf4j.version>
<tomcat.version>8.0.32</tomcat.version>
<elasticsearch.version>2.3.5</elasticsearch.version>
<orchestrator.version>3.13-build640</orchestrator.version>
<orchestrator.version>3.13-build783</orchestrator.version>
<okhttp.version>3.3.1</okhttp.version>
<jackson.version>2.6.6</jackson.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public static Date extractFirstDate(List<String> lines) {
}

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);
}
}

/**
* 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<String> logsLines = FileUtils.readLines(report, Charsets.UTF_8);
return extractComputationTotalTime(logsLines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ private static long extractStopDate(List<String> lines) throws IOException {
}

private static List<String> readLogLines(Orchestrator orchestrator) throws IOException {
return FileUtils.readLines(orchestrator.getServer().getLogs());
return FileUtils.readLines(orchestrator.getServer().getCeLogs());
}
}

0 comments on commit 38242dc

Please sign in to comment.