aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/h2-start.bat (renamed from sonar-server/derby-start.bat)2
-rwxr-xr-xsonar-server/h2-start.sh (renamed from sonar-server/derby-start.sh)2
-rw-r--r--sonar-server/pom.xml30
-rw-r--r--sonar-server/src/dev/h2/conf/logback.xml (renamed from sonar-server/src/dev/derby/conf/logback.xml)0
-rw-r--r--sonar-server/src/dev/h2/conf/sonar.properties (renamed from sonar-server/src/dev/derby/conf/sonar.properties)10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java161
-rw-r--r--sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabaseFactory.java15
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/database/EmbeddedDatabaseTest.java113
-rw-r--r--sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java61
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java4
11 files changed, 116 insertions, 284 deletions
diff --git a/sonar-server/derby-start.bat b/sonar-server/h2-start.bat
index 0961d6bc42b..51138689916 100644
--- a/sonar-server/derby-start.bat
+++ b/sonar-server/h2-start.bat
@@ -1,2 +1,2 @@
set MAVEN_OPTS='-Xmx768m -XX:MaxPermSize=128m'
-mvn clean jetty:run -Pstart-dev-server,derby
+mvn clean jetty:run -Pstart-dev-server,h2
diff --git a/sonar-server/derby-start.sh b/sonar-server/h2-start.sh
index 15903cacab7..f5bc557f462 100755
--- a/sonar-server/derby-start.sh
+++ b/sonar-server/h2-start.sh
@@ -1,3 +1,3 @@
#!/bin/sh
export MAVEN_OPTS='-Xmx768m -XX:MaxPermSize=128m'
-mvn clean jetty:run -Pstart-dev-server,derby
+mvn clean jetty:run -Pstart-dev-server,h2
diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml
index b690863fd84..a569ec71996 100644
--- a/sonar-server/pom.xml
+++ b/sonar-server/pom.xml
@@ -52,11 +52,6 @@
<artifactId>sonar-update-center-common</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbyclient</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${project.version}</version>
@@ -76,12 +71,8 @@
<artifactId>commons-configuration</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbynet</artifactId>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
@@ -613,9 +604,9 @@
</profile>
<profile>
- <id>derby</id>
+ <id>h2</id>
<properties>
- <jdbcDialect>derby</jdbcDialect>
+ <jdbcDialect>h2</jdbcDialect>
</properties>
<build>
<plugins>
@@ -632,7 +623,7 @@
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<resources>
<resource>
- <directory>${basedir}/src/dev/derby</directory>
+ <directory>${basedir}/src/dev/h2</directory>
<filtering>false</filtering>
</resource>
</resources>
@@ -653,10 +644,9 @@
<configuration>
<overWriteIfNewer>true</overWriteIfNewer>
<overWriteReleases>true</overWriteReleases>
- <includeGroupIds>org.apache.derby</includeGroupIds>
- <includeArtifactIds>derbyclient</includeArtifactIds>
- <outputDirectory>${project.build.directory}/sonar-dev-home/extensions/jdbc-driver/derby/
- </outputDirectory>
+ <includeGroupIds>com.h2database</includeGroupIds>
+ <includeArtifactIds>h2</includeArtifactIds>
+ <outputDirectory>${project.build.directory}/sonar-dev-home/extensions/jdbc-driver/h2/</outputDirectory>
</configuration>
</execution>
</executions>
@@ -665,8 +655,8 @@
</build>
<dependencies>
<dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbyclient</artifactId>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
</dependency>
</dependencies>
</profile>
diff --git a/sonar-server/src/dev/derby/conf/logback.xml b/sonar-server/src/dev/h2/conf/logback.xml
index e17be7b8999..e17be7b8999 100644
--- a/sonar-server/src/dev/derby/conf/logback.xml
+++ b/sonar-server/src/dev/h2/conf/logback.xml
diff --git a/sonar-server/src/dev/derby/conf/sonar.properties b/sonar-server/src/dev/h2/conf/sonar.properties
index 978f79ef7eb..a84bcbe53a5 100644
--- a/sonar-server/src/dev/derby/conf/sonar.properties
+++ b/sonar-server/src/dev/h2/conf/sonar.properties
@@ -1,6 +1,6 @@
-# Derby
-sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true
-sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver
+# H2
+sonar.jdbc.url: jdbc:h2:tcp://localhost:9092/sonar
+sonar.jdbc.driverClassName: org.h2.Driver
sonar.jdbc.defaultTransactionIsolation: 1
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
@@ -13,5 +13,5 @@ sonar.jdbc.timeBetweenEvictionRunsMillis: 30000
sonar.runtime.mode: development
-sonar.derby.drda.portNumber: 1527
-sonar.derby.drda.host: localhost \ No newline at end of file
+sonar.embeddedDatabase.port: 9092
+
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 1c41d228f56..e678f5551ba 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
@@ -19,171 +19,86 @@
*/
package org.sonar.server.database;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.derby.drda.NetworkServerControl;
+import org.h2.tools.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
-import org.sonar.api.utils.Logs;
import org.sonar.api.utils.SonarException;
import org.sonar.server.platform.ServerStartException;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.InetAddress;
-import java.util.Properties;
+import java.sql.DriverManager;
+import java.sql.SQLException;
public class EmbeddedDatabase {
+ private static final Logger LOG = LoggerFactory.getLogger(EmbeddedDatabase.class);
- private static final String DEFAULT_USER = "sonar";
- private static final String DEFAULT_PWD = "sonar";
-
- private NetworkServerControl serverControl = null;
-
- private File dbHome;
- private Properties dbProps;
- private PrintWriter dbLog;
+ private final Settings settings;
+ private Server server;
public EmbeddedDatabase(Settings settings) {
- this.dbHome = getDataDirectory(settings);
- this.dbProps = getDefaultProperties(settings);
- }
-
- public EmbeddedDatabase(File dbHome, Properties dbProps) {
- this.dbHome = dbHome;
- this.dbProps = dbProps;
- }
-
- public File getDataDir() {
- return dbHome;
- }
-
- protected File getDataDirectory(Settings settings) {
- String dirName = settings.getString(DatabaseProperties.PROP_EMBEDDED_DATA_DIR);
- if (StringUtils.isBlank(dirName)) {
- File sonarHome = new File(settings.getString(CoreProperties.SONAR_HOME));
- if (!sonarHome.isDirectory() || !sonarHome.exists()) {
- throw new ServerStartException("Sonar home directory does not exist");
- }
- return new File(sonarHome, "data");
- }
- return new File(dirName);
- }
-
- public void setDbLog(PrintWriter dbLog) {
- this.dbLog = dbLog;
+ this.settings = settings;
}
public void start() {
+ File dbHome = getDataDirectory(settings);
if (dbHome.exists() && !dbHome.isDirectory()) {
throw new SonarException("Database home " + dbHome.getPath() + " is not a directory");
}
if (!dbHome.exists()) {
dbHome.mkdirs();
}
- System.setProperty("derby.system.home", dbHome.getPath());
- saveDerbyPropertiesFile();
- startListening();
- Logs.INFO.info("Embedded database started. Data stored in: " + dbHome.getAbsolutePath());
- }
+ 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);
- private void startListening() {
try {
- int port = Integer.parseInt(dbProps.getProperty("derby.drda.portNumber"));
- String host = dbProps.getProperty("derby.drda.host");
- serverControl = new NetworkServerControl(InetAddress.getByName(host), port, DEFAULT_USER, DEFAULT_PWD);
- Logs.INFO.info("Starting embedded database on port " + port);
- serverControl.start(dbLog);
- ensureServerIsUp();
- } catch (Exception e) {
- throw new SonarException(e);
- }
- }
+ createDatabase(dbHome, user, password);
- private void saveDerbyPropertiesFile() {
- FileOutputStream output = null;
- try {
- File derbyProps = new File(dbHome.getPath() + "/derby.properties");
- output = new FileOutputStream(derbyProps);
- dbProps.store(output, "GENERATED FILE, DO NOT EDIT ME UNLESS YOU WANT TO LOOSE YOUR TIME ;O)");
+ Server server = Server.createTcpServer("-tcpPort", port, "-tcpAllowOthers", "-ifExists", "-baseDir", dbHome.getAbsolutePath());
- } catch (IOException e) {
- throw new SonarException(e);
+ LOG.info("Starting embedded database on port " + server.getPort());
+ server.start();
- } finally {
- IOUtils.closeQuietly(output);
+ LOG.info("Embedded database started. Data stored in: " + dbHome.getAbsolutePath());
+ } catch (Exception e) {
+ throw new SonarException("Unable to start database", e);
}
}
public void stop() {
- if (serverControl != null) {
- try {
- serverControl.shutdown();
- ensureServerIsDown();
- serverControl = null;
- Logs.INFO.info("Embedded database stopped");
-
- } catch (Exception e) {
- throw new SonarException(e);
- }
+ if (server != null) {
+ server.stop();
+ server = null;
+ LOG.info("Embedded database stopped");
}
}
- private void ensureServerIsUp() {
- for (int retry = 0; retry < 100; retry++) {
- try {
- serverControl.ping();
- return;
-
- } catch (Exception ex) {
- sleep(300);
- }
- }
- throw new SonarException("Embedded database does not respond to ping requests");
+ private String getSetting(String name, String defaultValue) {
+ return StringUtils.defaultIfBlank(settings.getString(name), defaultValue);
}
- private void ensureServerIsDown() {
- for (int retry = 0; retry < 100; retry++) {
- try {
- serverControl.ping();
- sleep(300);
-
- } catch (SonarException se) {
- throw se;
+ private void createDatabase(File dbHome, String user, String password) throws SQLException {
+ String url = String.format("jdbc:h2:%s/sonar;USER=%s;PASSWORD=%s", dbHome.getAbsolutePath(), user, password);
- } catch (Exception e) {
- // normal case: the database does not respond to ping
- return;
- }
- }
- throw new SonarException("Fail to stop embedded database");
+ DriverManager.getConnection(url).close();
}
+ private static File getDataDirectory(Settings settings) {
+ String dirName = settings.getString(DatabaseProperties.PROP_EMBEDDED_DATA_DIR);
+ if (!StringUtils.isBlank(dirName)) {
+ return new File(dirName);
+ }
- private void sleep(long time) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- throw new SonarException("Fail to ping embedded database", e);
+ File sonarHome = new File(settings.getString(CoreProperties.SONAR_HOME));
+ if (sonarHome.isDirectory() && sonarHome.exists()) {
+ return new File(sonarHome, "data");
}
- }
- public static Properties getDefaultProperties(Settings settings) {
- Properties props = new Properties();
- props.setProperty("derby.drda.startNetworkServer", "true");
- props.setProperty("derby.drda.host", StringUtils.defaultIfBlank(settings.getString("sonar.derby.drda.host"), "localhost"));
- props.setProperty("derby.drda.portNumber", StringUtils.defaultIfBlank(settings.getString("sonar.derby.drda.portNumber"), "1527"));
- props.setProperty("derby.drda.maxThreads", StringUtils.defaultIfBlank(settings.getString("sonar.derby.drda.maxThreads"), "20"));
- props.setProperty("derby.drda.minThreads", StringUtils.defaultIfBlank(settings.getString("sonar.derby.drda.minThreads"), "2"));
- props.setProperty("derby.drda.logConnections", StringUtils.defaultIfBlank(settings.getString("sonar.derby.drda.logConnections"), "false"));
- props.setProperty("derby.stream.error.logSeverityLevel", StringUtils.defaultIfBlank(settings.getString("sonar.derby.stream.error.logSeverityLevel"), "20000"));
- props.setProperty("derby.connection.requireAuthentication", "true");
- props.setProperty("derby.user." + DEFAULT_USER, DEFAULT_PWD);
- return props;
+ throw new ServerStartException("Sonar home directory does not exist");
}
-
}
diff --git a/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabaseFactory.java b/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabaseFactory.java
index b0f442c390c..c887d1aaf29 100644
--- a/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabaseFactory.java
+++ b/sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabaseFactory.java
@@ -21,20 +21,25 @@ package org.sonar.server.database;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
+import org.sonar.core.persistence.dialect.H2;
public class EmbeddedDatabaseFactory {
- private Settings settings;
+ private final Settings settings;
+ private final H2 dialect;
private EmbeddedDatabase embeddedDatabase;
public EmbeddedDatabaseFactory(Settings settings) {
this.settings = settings;
+ dialect = new H2();
}
public void start() {
- String jdbcUrl = settings.getString(DatabaseProperties.PROP_URL);
- if (jdbcUrl != null && jdbcUrl.startsWith("jdbc:derby://") && jdbcUrl.contains("create=true") && embeddedDatabase == null) {
- embeddedDatabase = new EmbeddedDatabase(settings);
- embeddedDatabase.start();
+ if (embeddedDatabase == null) {
+ String jdbcUrl = settings.getString(DatabaseProperties.PROP_URL);
+ if (dialect.matchesJdbcURL(jdbcUrl)) {
+ embeddedDatabase = new EmbeddedDatabase(settings);
+ embeddedDatabase.start();
+ }
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java b/sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java
index 812ff0f3502..c3c4d65d06b 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/BatchResourcesServlet.java
@@ -97,7 +97,7 @@ public class BatchResourcesServlet extends HttpServlet {
return libs;
}
- private static final String[] IGNORE = { "derby", "jtds", "mysql", "postgresql", "jruby", "jfreechart", "eastwood", "jetty" };
+ private static final String[] IGNORE = {"h2", "jtds", "mysql", "postgresql", "jruby", "jfreechart", "eastwood", "jetty"};
/**
* Dirty hack to disable downloading for certain files.
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 4f1eccc77b1..301bfab68cd 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
@@ -19,120 +19,45 @@
*/
package org.sonar.server.database;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.SystemUtils;
-import org.apache.derby.jdbc.ClientDriver;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.core.persistence.InMemoryDatabase;
+import org.sonar.api.database.DatabaseProperties;
-import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
-import java.sql.Connection;
import java.sql.DriverManager;
-import java.util.Properties;
import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertTrue;
public class EmbeddedDatabaseTest {
+ @Test(timeout = 5000)
+ public void should_start_and_stop() throws IOException {
+ int port = freeServerPort();
- private final static String TEST_ROOT_DIR = "./target/";
- private final static String TEST_DB_DIR_PREFIX = "testDB";
-
- private EmbeddedDatabase database;
- private String driverUrl;
- private Properties defaultProps;
- private static String testPort;
-
- @Before
- public void setUp() throws Exception {
- // This test doesn't work if InMemoryDatabase is active
- try {
- InMemoryDatabase.stopDatabase();
- } catch (Exception e) {
- }
-
- windowsCleanup();
- if (testPort == null) {
- testPort = Integer.toString(findFreeServerPort());
- }
- defaultProps = EmbeddedDatabase.getDefaultProperties(new Settings());
- defaultProps.put("derby.drda.portNumber", testPort); // changing the default port
- driverUrl = "jdbc:derby://localhost:" + testPort + "/sonar;create=true;user=sonar;password=sonar";
- }
-
- private void windowsCleanup() {
- String os = System.getProperty("os.name");
- if (os.toLowerCase().contains("windows")) {
- File testRoot = new File(TEST_ROOT_DIR);
- File[] files = testRoot.listFiles();
- for (File file : files) {
- if (file.isDirectory() &&
- file.getName().startsWith(TEST_DB_DIR_PREFIX)) {
- try {
- FileUtils.deleteDirectory(file);
- } catch (IOException e) {
- }
- }
- }
- }
- }
-
- private int findFreeServerPort() throws IOException, InterruptedException {
- ServerSocket srv = new ServerSocket(0);
- int port = srv.getLocalPort();
- srv.close();
- Thread.sleep(1500);
- return port;
- }
-
- @Test
- public void shouldStartAndStop() throws Exception {
- database = new EmbeddedDatabase(new File(TEST_ROOT_DIR + TEST_DB_DIR_PREFIX + testPort), defaultProps);
+ EmbeddedDatabase database = new EmbeddedDatabase(settings(port));
database.start();
- ClientDriver.class.newInstance();
- Connection conn;
+
try {
- conn = DriverManager.getConnection(driverUrl);
- conn.close();
+ String driverUrl = String.format("jdbc:h2:tcp://localhost:%d/sonar;USER=login;PASSWORD=pwd", port);
+ DriverManager.getConnection(driverUrl).close();
} catch (Exception ex) {
fail("Unable to connect after start");
}
- try {
- conn = DriverManager.getConnection("jdbc:derby://localhost:" + testPort + "/sonar;user=foo;password=bar");
- conn.close();
- fail("Able to connect with wrong username and password");
- } catch (Exception ex) {
- }
-
- File testDb = new File(database.getDataDir(), "sonar");
- assertTrue(testDb.exists());
- assertTrue(testDb.isDirectory());
database.stop();
-
- try {
- conn = DriverManager.getConnection(driverUrl);
- conn.close();
- fail("Able to connect after stop");
- } catch (Exception ex) {
- }
}
- @After
- public void tearDown() throws IOException {
- if (database.getDataDir().exists()) {
- if (!SystemUtils.IS_OS_WINDOWS) {
- // avoid an issue with file lock issue under windows..
- // thank you mr microsoft
- // solution : no really good solution found.., the db home is not deleted under windows on teardown but only during test startup
- FileUtils.deleteDirectory(database.getDataDir());
- }
- }
+ static Settings settings(int port) {
+ return new Settings()
+ .setProperty(DatabaseProperties.PROP_USER, "login")
+ .setProperty(DatabaseProperties.PROP_PASSWORD, "pwd")
+ .setProperty(DatabaseProperties.PROP_EMBEDDED_PORT, "" + port)
+ .setProperty(DatabaseProperties.PROP_EMBEDDED_DATA_DIR, "./target/testDB");
}
+ static int freeServerPort() throws IOException {
+ ServerSocket srv = new ServerSocket(0);
+ srv.close();
+ return srv.getLocalPort();
+ }
}
diff --git a/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java b/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java
index 22c8d9ade94..8ed6c98b2bc 100644
--- a/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java
@@ -23,7 +23,7 @@ import com.google.common.collect.Sets;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
-import org.sonar.core.persistence.dialect.Derby;
+import org.sonar.core.persistence.dialect.H2;
import org.sonar.core.persistence.dialect.MsSql;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -39,7 +39,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void mustDefineAtLeastOneQualifier() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(new Filter());
assertThat(result.size()).isEqualTo(0);// no qualifiers
}
@@ -47,7 +47,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterOnScopes() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setScopes(Sets.newHashSet(Resource.SCOPE_SPACE)));
assertSnapshotIds(result, 4);
}
@@ -55,7 +55,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterOnQualifiers() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(new Filter().setQualifiers(Sets.newHashSet(Resource.QUALIFIER_PROJECT, Resource.QUALIFIER_MODULE)));
assertSnapshotIds(result, 2, 3);
}
@@ -63,7 +63,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterOnLanguages() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setLanguages(Sets.newHashSet("java")));
assertSnapshotIds(result, 2, 4);
}
@@ -71,7 +71,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterOnDate() throws ParseException {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2008-12-26 00:00");
FilterResult result = executor.execute(Filter.createForAllQualifiers().setDateCriterion(new DateCriterion(">", date)));
assertSnapshotIds(result, 3);
@@ -80,7 +80,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterOnDateIncludesTime() throws ParseException {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2008-12-25 03:00");
FilterResult result = executor.execute(Filter.createForAllQualifiers().setDateCriterion(new DateCriterion("<", date)));
assertSnapshotIds(result, 2, 4);
@@ -89,7 +89,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterOnBaseSnapshot() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setPath(2, 2, ""));
assertSnapshotIds(result, 4);
}
@@ -97,7 +97,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByName() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setSortedByName());
assertSortedSnapshotIds(result, 2, 4, 3);
}
@@ -105,7 +105,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByKey() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setSortedByKey());
assertSortedSnapshotIds(result, 3, 2, 4);
}
@@ -113,7 +113,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByDate() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setSortedByDate());
assertSortedSnapshotIds(result, 2, 4, 3);
}
@@ -121,7 +121,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByDescendingDate() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setSortedByDate().setAscendingSort(false));
assertSortedSnapshotIds(result, 3, 4, 2);
}
@@ -129,7 +129,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByAscendingDate() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setSortedByDate().setAscendingSort(true));
assertSortedSnapshotIds(result, 2, 4, 3);
}
@@ -137,7 +137,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByAscendingMeasureValue() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.setSortedMetricId(2, true, false);
@@ -149,7 +149,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByDecendingMeasureValue() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.setSortedMetricId(2, true, false)
@@ -162,7 +162,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void applySingleMeasureCriterion() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(2, ">", 50.0, false));
@@ -174,7 +174,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void applyManyMeasureCriteria() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(2, ">", 50.0, false))
@@ -187,7 +187,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void criteriaAreExclusive() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(2, ">", 50.0, false))
@@ -200,7 +200,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortAndFilterMeasures() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(2, ">", 5.0, false))
@@ -214,7 +214,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortDescendingAndFilterMeasures() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(2, ">", 5.0, false)) // filter on coverage
@@ -229,7 +229,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterByResourceKey() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setKeyRegexp("*:org.sonar.*"));
assertSnapshotIds(result, 4);
}
@@ -237,7 +237,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterByResourceKeyIsCaseInsensitive() {
setupData("shared");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
FilterResult result = executor.execute(Filter.createForAllQualifiers().setKeyRegexp("*:ORG.SonAR.*"));
assertSnapshotIds(result, 4);
}
@@ -245,7 +245,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterByMissingMeasureValue() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(3, ">", 0.0, false)); // filter on duplicated lines
@@ -257,7 +257,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterByMissingMeasureValues() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(1, ">", 0.0, false)) // filter on lines
@@ -270,7 +270,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void sortByMissingMeasureValue() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.setSortedMetricId(3, true, false); // sort by duplicated lines
@@ -282,7 +282,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void filterByMeasureValueAndSortOnOtherMetric() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(1, ">", 0.0, false)) // lines > 0
@@ -295,7 +295,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void intersectionOfCriteriaOnSameMetric() {
setupData("shared", "measures");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.CLASS))
.addMeasureCriterion(new MeasureCriterion(1, ">", 400.0, false)) // lines > 400
@@ -308,7 +308,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void ignoreProjectCopiesOfViews() {
setupData("views");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setQualifiers(Sets.newHashSet(Qualifiers.PROJECT));
@@ -319,7 +319,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
@Test
public void loadProjectCopiesIfPathIsAView() {
setupData("views");
- FilterExecutor executor = new FilterExecutor(getSession(), new Derby());
+ FilterExecutor executor = new FilterExecutor(getSession(), new H2());
Filter filter = new Filter()
.setPath(2, 2, "")
.setQualifiers(Sets.newHashSet(Qualifiers.SUBVIEW, Qualifiers.PROJECT));
@@ -335,11 +335,10 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
String sql = new FilterExecutor(getSession(), new MsSql()).toSql(filter);
assertThat(sql).contains(" WITH (INDEX(measures_sid_metric)) ");
- sql = new FilterExecutor(getSession(), new Derby()).toSql(filter);
+ sql = new FilterExecutor(getSession(), new H2()).toSql(filter);
assertThat(sql).doesNotContain(" WITH (INDEX(measures_sid_metric)) ");
}
-
private void assertSnapshotIds(FilterResult result, int... snapshotIds) {
assertThat(result.size()).isEqualTo(snapshotIds.length);
for (int snapshotId : snapshotIds) {
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java
index e5cb732418a..ea633db07f8 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/BatchResourcesServletTest.java
@@ -79,9 +79,7 @@ public class BatchResourcesServletTest {
@Test
public void shouldIgnore() {
assertThat(BatchResourcesServlet.isIgnored("sonar-batch-2.6-SNAPSHOT.jar"), is(false));
- assertThat(BatchResourcesServlet.isIgnored("derby-10.6.1.0.jar"), is(true));
- assertThat(BatchResourcesServlet.isIgnored("derbyclient-10.6.1.0.jar"), is(true));
- assertThat(BatchResourcesServlet.isIgnored("derbynet-10.6.1.0.jar"), is(true));
+ assertThat(BatchResourcesServlet.isIgnored("h2-1.3.166.jar"), is(true));
assertThat(BatchResourcesServlet.isIgnored("mysql-connector-java-5.1.13.jar"), is(true));
assertThat(BatchResourcesServlet.isIgnored("postgresql-9.0-801.jdbc3.jar"), is(true));
assertThat(BatchResourcesServlet.isIgnored("jtds-1.2.4.jar"), is(true));