aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2017-08-16 16:26:06 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-05 14:24:13 +0200
commitfa97b5981a4bf8511f285577b5623c07e5130216 (patch)
tree5a47c740f93bcb827e1f475d4a380ff7d27ac9c6 /tests/src/test
parentd95bc1cd4454a7bd1e16ffc15fba14546c698909 (diff)
downloadsonarqube-fa97b5981a4bf8511f285577b5623c07e5130216.tar.gz
sonarqube-fa97b5981a4bf8511f285577b5623c07e5130216.zip
SONAR-9713 Allow to upgrade a cluster without stopping search nodes
Diffstat (limited to 'tests/src/test')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/Category5Suite.java4
-rw-r--r--tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java72
2 files changed, 73 insertions, 3 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category5Suite.java b/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
index fd12d951546..19ed5d87d37 100644
--- a/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
+++ b/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
@@ -22,7 +22,6 @@ package org.sonarqube.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.sonarqube.tests.ce.CeWorkersTest;
-import org.sonarqube.tests.cluster.DataCenterEditionTest;
import org.sonarqube.tests.qualityProfile.ActiveRuleEsResilienceTest;
import org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesNotificationTest;
import org.sonarqube.tests.rule.RuleEsResilienceTest;
@@ -63,8 +62,7 @@ import org.sonarqube.tests.user.UserEsResilienceTest;
TelemetryUploadTest.class,
TelemetryOptOutTest.class,
// ce
- CeWorkersTest.class,
- DataCenterEditionTest.class
+ CeWorkersTest.class
})
public class Category5Suite {
diff --git a/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java b/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java
index 832d6111c82..2a52d6f7818 100644
--- a/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java
@@ -20,20 +20,37 @@
package org.sonarqube.tests.cluster;
+import com.sonar.orchestrator.db.Database;
+import com.sonar.orchestrator.db.DatabaseClient;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.DisableOnDebug;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
+import static org.junit.Assert.fail;
import static org.sonarqube.tests.cluster.Cluster.NodeType.APPLICATION;
import static org.sonarqube.tests.cluster.Cluster.NodeType.SEARCH;
public class DataCenterEditionTest {
+ @Rule
+ public TestRule timeout = new DisableOnDebug(Timeout.builder()
+ .withLookingForStuckThread(true)
+ .withTimeout(5, TimeUnit.MINUTES)
+ .build());
+
@Test
public void launch() throws ExecutionException, InterruptedException {
DataCenterEdition dce = new DataCenterEdition();
@@ -51,6 +68,46 @@ public class DataCenterEditionTest {
dce.stop();
}
+ @Test
+ public void upgrade_application_nodes_without_stopping_search_nodes_must_work() throws ExecutionException, InterruptedException, SQLException {
+ DataCenterEdition dce = new DataCenterEdition();
+ Cluster cluster = dce.getCluster();
+ dce.start();
+
+ // Stop all Application nodes
+ cluster.stopAll(n -> n.getType() == APPLICATION);
+
+ // Drop the schema
+ Database database = cluster.getNodes().get(0).getOrchestrator().getDatabase();
+ dropAndCreate(database.getClient());
+ assertDatabaseDropped(database);
+
+ // Start all Application nodes
+ cluster.startAll(n -> n.getType() == APPLICATION);
+
+ // We are expecting a new leader to be elected which will recreate the database
+ assertDatabaseInitialized(database);
+
+ dce.stop();
+ }
+
+ private void assertDatabaseInitialized(Database database) {
+ assertThat(countRowsOfMigration(database)).isGreaterThan(0);
+ }
+
+ private int countRowsOfMigration(Database database) {
+ return database.countSql("select count(*) from schema_migrations");
+ }
+
+ private void assertDatabaseDropped(Database database) {
+ try {
+ countRowsOfMigration(database);
+ fail("Table 'schema_migrations' has not been dropped");
+ } catch (Exception e) {
+ // we expect the table to not exist
+ }
+ }
+
private static boolean isPortBound(boolean loopback, @Nullable Integer port) {
if (port == null) {
return false;
@@ -62,4 +119,19 @@ public class DataCenterEditionTest {
return true;
}
}
+
+ private static void dropAndCreate(DatabaseClient databaseClient) throws SQLException {
+ try (Connection connection = databaseClient.openRootConnection()) {
+ executeDdl(connection, databaseClient.getDropDdl());
+ executeDdl(connection, databaseClient.getCreateDdl());
+ }
+ }
+
+ private static void executeDdl(Connection connection, String... ddls) throws SQLException {
+ try (Statement stmt = connection.createStatement()) {
+ for (String ddl : ddls) {
+ stmt.executeUpdate(ddl);
+ }
+ }
+ }
}