use of com.sonar.orchestrator.Orchestrator in project sonarqube by SonarSource.
the class ClusterTest method start_cluster_of_elasticsearch_and_web_nodes.
@Test
public void start_cluster_of_elasticsearch_and_web_nodes() throws IOException {
Orchestrator elasticsearch = null;
Orchestrator web = null;
try {
ElasticsearchStartupWatcher esWatcher = new ElasticsearchStartupWatcher();
elasticsearch = Orchestrator.builderEnv().setServerProperty("sonar.cluster.enabled", "true").setServerProperty("sonar.cluster.name", "start_cluster_of_elasticsearch_and_web_nodes").setServerProperty("sonar.cluster.web.disabled", "true").setServerProperty("sonar.cluster.ce.disabled", "true").setStartupLogWatcher(esWatcher).build();
elasticsearch.start();
assertThat(esWatcher.port).isGreaterThan(0);
assertThat(FileUtils.readFileToString(elasticsearch.getServer().getAppLogs())).doesNotContain("Process[web]");
web = Orchestrator.builderEnv().setServerProperty("sonar.cluster.enabled", "true").setServerProperty("sonar.cluster.name", "start_cluster_of_elasticsearch_and_web_nodes").setServerProperty("sonar.cluster.web.startupLeader", "true").setServerProperty("sonar.cluster.search.disabled", "true").setServerProperty("sonar.cluster.search.hosts", "localhost:" + esWatcher.port).setServerProperty("sonar.cluster.ce.disabled", "true").setStartupLogWatcher(log -> log.contains("SonarQube is up")).build();
web.start();
String coreId = getPropertyValue(web, "sonar.core.id");
String startTime = getPropertyValue(web, "sonar.core.startTime");
assertThat(FileUtils.readFileToString(web.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);
web.restartServer();
// sonar core id must not change after restart
assertThat(getPropertyValue(web, "sonar.core.id")).isEqualTo(coreId);
// startTime must change at each startup
assertThat(getPropertyValue(web, "sonar.core.startTime")).isNotEqualTo(startTime);
} finally {
if (web != null) {
web.stop();
}
if (elasticsearch != null) {
elasticsearch.stop();
}
}
}
use of com.sonar.orchestrator.Orchestrator in project sonarqube by SonarSource.
the class ClusterTest method secondary_nodes_do_not_write_to_datastores_at_startup.
/**
* SONAR-7899
*/
@Test
public void secondary_nodes_do_not_write_to_datastores_at_startup() throws Exception {
// start "startup leader", which creates and populates datastores
Orchestrator orchestrator = Orchestrator.builderEnv().setServerProperty("sonar.cluster.enabled", "true").setServerProperty("sonar.cluster.name", "secondary_nodes_do_not_write_to_datastores_at_startup").setServerProperty("sonar.cluster.web.startupLeader", "true").setServerProperty("sonar.log.level", "TRACE").addPlugin(ItUtils.xooPlugin()).build();
orchestrator.start();
expectLog(orchestrator, "Cluster enabled (startup leader)");
expectWriteOperations(orchestrator, true);
// verify that datastores are populated by requesting rules
assertThat(newWsClient(orchestrator).rules().search(new SearchWsRequest()).getTotal()).isGreaterThan(0);
FileUtils.write(orchestrator.getServer().getWebLogs(), "", false);
updateSonarPropertiesFile(orchestrator, ImmutableMap.of("sonar.cluster.web.startupLeader", "false"));
orchestrator.restartServer();
expectLog(orchestrator, "Cluster enabled (startup follower)");
expectWriteOperations(orchestrator, false);
orchestrator.stop();
}
use of com.sonar.orchestrator.Orchestrator in project sonarqube by SonarSource.
the class ServerTest method server_startup_and_shutdown.
// ES + TOMCAT
@Test
public void server_startup_and_shutdown() throws Exception {
String defaultWebJavaOptions = "-Xmx768m -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Dfile.encoding=UTF-8";
Orchestrator orchestrator = Orchestrator.builderEnv().setOrchestratorProperty("javaVersion", "LATEST_RELEASE").addPlugin("java").setServerProperty("sonar.web.javaOpts", defaultWebJavaOptions + " -Djava.security.egd=file:/dev/./urandom").build();
try {
ServerLogs.clear(orchestrator);
orchestrator.start();
// compare dates of first and last log
long firstLogDate = ServerLogs.extractFirstDate(readLines(orchestrator.getServer().getAppLogs())).getTime();
long startedAtDate = extractStartedAtDate(orchestrator);
assertDurationAround(startedAtDate - firstLogDate, 28_000);
ServerLogs.clear(orchestrator);
orchestrator.stop();
List<String> lines = readLines(orchestrator.getServer().getAppLogs());
long firstStopLogDate = ServerLogs.extractFirstDate(lines).getTime();
long stopDate = extractStopDate(lines);
assertDurationLessThan(stopDate - firstStopLogDate, 10_000);
} finally {
orchestrator.stop();
}
}
Aggregations