From 25e954167dc467546cc555e78b607423afbaaa48 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 2 Jul 2012 10:10:27 +0200 Subject: Replacing Derby with H2 --- pom.xml | 24 +- sonar-application/assembly.xml | 6 +- sonar-application/pom.xml | 4 +- .../src/main/assembly/conf/sonar.properties | 17 +- sonar-core/pom.xml | 17 +- .../sonar/core/persistence/DatabaseMigrator.java | 2 +- .../java/org/sonar/core/persistence/DdlUtils.java | 2 +- .../sonar/core/persistence/DefaultDatabase.java | 13 +- .../org/sonar/core/persistence/dialect/Derby.java | 101 --- .../core/persistence/dialect/DialectUtils.java | 2 +- .../org/sonar/core/persistence/dialect/H2.java | 67 ++ .../org/sonar/core/persistence/rows-derby.sql | 167 ----- .../org/sonar/core/persistence/rows-h2.sql | 167 +++++ .../org/sonar/core/persistence/schema-derby.ddl | 700 --------------------- .../org/sonar/core/persistence/schema-h2.ddl | 509 +++++++++++++++ .../sonar/core/config/ConfigurationUtilsTest.java | 4 +- .../org/sonar/core/persistence/DaoTestCase.java | 24 +- .../sonar/core/persistence/DatabaseCommands.java | 17 +- .../org/sonar/core/persistence/DdlUtilsTest.java | 47 +- .../core/persistence/DefaultDatabaseTest.java | 24 +- .../org/sonar/core/persistence/DerbyUtils.java | 52 -- .../org/sonar/core/persistence/H2Database.java | 129 ++++ .../org/sonar/core/persistence/H2DatabaseTest.java | 69 ++ .../sonar/core/persistence/InMemoryDatabase.java | 174 ----- .../core/persistence/InMemoryDatabaseTest.java | 73 --- .../org/sonar/core/persistence/MyBatisTest.java | 8 +- .../sonar/core/persistence/dialect/DerbyTest.java | 42 -- .../org/sonar/core/persistence/dialect/H2Test.java | 42 ++ .../org/sonar/jpa/test/AbstractDbUnitTestCase.java | 46 +- .../org/sonar/api/database/DatabaseProperties.java | 15 +- sonar-server/derby-start.bat | 2 - sonar-server/derby-start.sh | 3 - sonar-server/h2-start.bat | 2 + sonar-server/h2-start.sh | 3 + sonar-server/pom.xml | 30 +- sonar-server/src/dev/derby/conf/logback.xml | 44 -- sonar-server/src/dev/derby/conf/sonar.properties | 17 - sonar-server/src/dev/h2/conf/logback.xml | 44 ++ sonar-server/src/dev/h2/conf/sonar.properties | 17 + .../sonar/server/database/EmbeddedDatabase.java | 161 ++--- .../server/database/EmbeddedDatabaseFactory.java | 15 +- .../server/plugins/BatchResourcesServlet.java | 2 +- .../server/database/EmbeddedDatabaseTest.java | 113 +--- .../sonar/server/filters/FilterExecutorTest.java | 61 +- .../server/plugins/BatchResourcesServletTest.java | 4 +- sonar-testing-harness/pom.xml | 4 +- sonar-web-test/pom.xml | 12 + 47 files changed, 1286 insertions(+), 1812 deletions(-) delete mode 100644 sonar-core/src/main/java/org/sonar/core/persistence/dialect/Derby.java create mode 100644 sonar-core/src/main/java/org/sonar/core/persistence/dialect/H2.java delete mode 100644 sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql create mode 100644 sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql delete mode 100644 sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl create mode 100644 sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl delete mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/DerbyUtils.java create mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/H2Database.java create mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/H2DatabaseTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabase.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/dialect/DerbyTest.java create mode 100644 sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java delete mode 100644 sonar-server/derby-start.bat delete mode 100755 sonar-server/derby-start.sh create mode 100644 sonar-server/h2-start.bat create mode 100755 sonar-server/h2-start.sh delete mode 100644 sonar-server/src/dev/derby/conf/logback.xml delete mode 100644 sonar-server/src/dev/derby/conf/sonar.properties create mode 100644 sonar-server/src/dev/h2/conf/logback.xml create mode 100644 sonar-server/src/dev/h2/conf/sonar.properties create mode 100644 sonar-web-test/pom.xml diff --git a/pom.xml b/pom.xml index e1808668063..a59a5682301 100644 --- a/pom.xml +++ b/pom.xml @@ -81,13 +81,7 @@ - - 10.7.1.1 - + 1.3.167 6.1.25 sonar-gwt-api,sonar-core-gwt UTF-8 @@ -792,19 +786,9 @@ 0.9.30 - org.apache.derby - derbyclient - ${derby.version} - - - org.apache.derby - derby - ${derby.version} - - - org.apache.derby - derbynet - ${derby.version} + com.h2database + h2 + ${h2.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sonar-server/src/dev/derby/conf/sonar.properties b/sonar-server/src/dev/derby/conf/sonar.properties deleted file mode 100644 index 978f79ef7eb..00000000000 --- a/sonar-server/src/dev/derby/conf/sonar.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Derby -sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true -sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver -sonar.jdbc.defaultTransactionIsolation: 1 -sonar.jdbc.username: sonar -sonar.jdbc.password: sonar -sonar.jdbc.maxActive: 30 -sonar.jdbc.maxIdle: 10 -sonar.jdbc.minIdle: 2 -sonar.jdbc.maxWait: 5000 -sonar.jdbc.minEvictableIdleTimeMillis: 600000 -sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 - -sonar.runtime.mode: development - -sonar.derby.drda.portNumber: 1527 -sonar.derby.drda.host: localhost \ No newline at end of file diff --git a/sonar-server/src/dev/h2/conf/logback.xml b/sonar-server/src/dev/h2/conf/logback.xml new file mode 100644 index 00000000000..e17be7b8999 --- /dev/null +++ b/sonar-server/src/dev/h2/conf/logback.xml @@ -0,0 +1,44 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{20} %X - %msg%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-server/src/dev/h2/conf/sonar.properties b/sonar-server/src/dev/h2/conf/sonar.properties new file mode 100644 index 00000000000..a84bcbe53a5 --- /dev/null +++ b/sonar-server/src/dev/h2/conf/sonar.properties @@ -0,0 +1,17 @@ +# 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 +sonar.jdbc.maxActive: 30 +sonar.jdbc.maxIdle: 10 +sonar.jdbc.minIdle: 2 +sonar.jdbc.maxWait: 5000 +sonar.jdbc.minEvictableIdleTimeMillis: 600000 +sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 + +sonar.runtime.mode: development + +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)); diff --git a/sonar-testing-harness/pom.xml b/sonar-testing-harness/pom.xml index a66de638c53..ef72ba2be81 100644 --- a/sonar-testing-harness/pom.xml +++ b/sonar-testing-harness/pom.xml @@ -41,8 +41,8 @@ ${project.version} - org.apache.derby - derby + com.h2database + h2 org.dbunit diff --git a/sonar-web-test/pom.xml b/sonar-web-test/pom.xml new file mode 100644 index 00000000000..2a08592db00 --- /dev/null +++ b/sonar-web-test/pom.xml @@ -0,0 +1,12 @@ + + + 4.0.0 + + org.codehaus.sonar + sonar + 3.2-SNAPSHOT + + sonar-web-test + Sonar :: Web Test + Test of the web site + -- cgit v1.2.3