summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-12 13:46:59 +0200
committerDavid Gageot <david@gageot.net>2012-07-12 15:59:43 +0200
commitd4d8c241748e345b99f9fd6e2266d3c9e4b93498 (patch)
tree543c003991123bcb5070eeaecd235c9e446a7dd6
parent8fca583588123084b0484be56e8c5eb07f806477 (diff)
downloadsonarqube-d4d8c241748e345b99f9fd6e2266d3c9e4b93498.tar.gz
sonarqube-d4d8c241748e345b99f9fd6e2266d3c9e4b93498.zip
Support embedded in memory database
-rw-r--r--sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java14
-rw-r--r--sonar-server/src/test/java/org/sonar/server/database/EmbeddedDatabaseTest.java19
2 files changed, 28 insertions, 5 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java b/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java
index 1910ef96573..75fa1e40fb5 100644
--- a/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java
+++ b/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java
@@ -57,13 +57,17 @@ public class EmbeddedDatabase {
String port = getSetting(DatabaseProperties.PROP_EMBEDDED_PORT, DatabaseProperties.PROP_EMBEDDED_PORT_DEFAULT_VALUE);
String user = getSetting(DatabaseProperties.PROP_USER, DatabaseProperties.PROP_USER_DEFAULT_VALUE);
String password = getSetting(DatabaseProperties.PROP_PASSWORD, DatabaseProperties.PROP_PASSWORD_DEFAULT_VALUE);
+ String url = getSetting(DatabaseProperties.PROP_URL, DatabaseProperties.PROP_USER_DEFAULT_VALUE);
try {
- createDatabase(dbHome, user, password);
-
- server = Server.createTcpServer("-tcpPort", port, "-tcpAllowOthers", "-ifExists", "-baseDir", dbHome.getAbsolutePath());
-
- LOG.info("Starting embedded database on port " + server.getPort());
+ if (url.contains("/mem:")) {
+ server = Server.createTcpServer("-tcpPort", port, "-tcpAllowOthers", "-baseDir", dbHome.getAbsolutePath());
+ } else {
+ createDatabase(dbHome, user, password);
+ server = Server.createTcpServer("-tcpPort", port, "-tcpAllowOthers", "-ifExists", "-baseDir", dbHome.getAbsolutePath());
+ }
+
+ LOG.info("Starting embedded database on port " + server.getPort() + " with url " + url);
server.start();
LOG.info("Embedded database started. Data stored in: " + dbHome.getAbsolutePath());
diff --git a/sonar-server/src/test/java/org/sonar/server/database/EmbeddedDatabaseTest.java b/sonar-server/src/test/java/org/sonar/server/database/EmbeddedDatabaseTest.java
index ceace45b1f1..c6d43cdc6b9 100644
--- a/sonar-server/src/test/java/org/sonar/server/database/EmbeddedDatabaseTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/database/EmbeddedDatabaseTest.java
@@ -50,6 +50,25 @@ public class EmbeddedDatabaseTest {
database.stop();
}
+ @Test(timeout = 5000)
+ public void should_support_memory_database() throws IOException {
+ int port = freeServerPort();
+
+ EmbeddedDatabase database = new EmbeddedDatabase(settings(port)
+ .setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:tcp://localhost:" + port + "/mem:sonarIT;USER=sonar;PASSWORD=sonar"));
+ database.start();
+
+ try {
+ String driverUrl = String.format("jdbc:h2:tcp://localhost:%d/mem:sonarIT;USER=sonar;PASSWORD=sonar", port);
+ DriverManager.registerDriver(new Driver());
+ DriverManager.getConnection(driverUrl).close();
+ } catch (Exception ex) {
+ fail("Unable to connect after start");
+ }
+
+ database.stop();
+ }
+
static Settings settings(int port) {
return new Settings()
.setProperty(DatabaseProperties.PROP_USER, "login")