@Test(expectedExceptions = NullPointerException.class) public void testNullFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() // Filename left as null .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = FileNotFoundException.class) public void testCantFindInitScript() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript("foo") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = NullPointerException.class) public void testNullFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() // Filename left as null .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = FileNotFoundException.class) public void testCantFindInitScript() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript("foo") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename("") .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = JdbcSQLException.class) public void testInitFromInvalidDdlThrows() throws Exception { File initScript = File.createTempFile("initscript", ".ddl"); try { String invalidDdl = "This isn't valid SQL"; asCharSink(initScript, UTF_8).write(invalidDdl); H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript(initScript.getAbsolutePath()) .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); } finally { initScript.delete(); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyFilenameThrows() throws Exception { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename("") .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); }
@Test(expectedExceptions = JdbcSQLException.class) public void testInitFromInvalidDdlThrows() throws Exception { File initScript = File.createTempFile("initscript", ".ddl"); try { String invalidDdl = "This isn't valid SQL"; asCharSink(initScript, UTF_8).write(invalidDdl); H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript(initScript.getAbsolutePath()) .setCipher(Cipher.AES) .setFilePassword("filePassword"); new H2EmbeddedDataSource(config); } finally { initScript.delete(); } }
.setCompressLob(CompressLob.NO) .setFilename("TestData") .setFilePassword("test123") .setInitScript("init.sql") .setMaxLengthInplaceLob(8192)
.setCompressLob(CompressLob.NO) .setFilename("TestData") .setFilePassword("test123") .setInitScript("init.sql") .setMaxLengthInplaceLob(8192)
@Test public void testInitFromFile() throws Exception { File initScript = File.createTempFile("initscript", ".ddl"); Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { URL url = Resources.getResource("io/airlift/dbpool/h2.ddl"); Resources.asByteSource(url).copyTo(Files.asByteSink(initScript)); H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript(initScript.getAbsolutePath()) .setCipher(Cipher.AES) .setFilePassword("filePassword"); H2EmbeddedDataSource dataSource = new H2EmbeddedDataSource(config); connection = dataSource.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery("select * from message"); } finally { initScript.delete(); closeQuietly(resultSet); closeQuietly(statement); closeQuietly(connection); } }
@Test public void testInitFromFile() throws Exception { File initScript = File.createTempFile("initscript", ".ddl"); Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { URL url = Resources.getResource("io/airlift/dbpool/h2.ddl"); Resources.asByteSource(url).copyTo(Files.asByteSink(initScript)); H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript(initScript.getAbsolutePath()) .setCipher(Cipher.AES) .setFilePassword("filePassword"); H2EmbeddedDataSource dataSource = new H2EmbeddedDataSource(config); connection = dataSource.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery("select * from message"); } finally { initScript.delete(); closeQuietly(resultSet); closeQuietly(statement); closeQuietly(connection); } }
@Test public void testInitFromResource() throws Exception { Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); H2EmbeddedDataSource dataSource = new H2EmbeddedDataSource(config); connection = dataSource.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery("select * from message"); } finally { closeQuietly(resultSet); closeQuietly(statement); closeQuietly(connection); } }
@Test public void testInitFromResource() throws Exception { Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { H2EmbeddedDataSourceConfig config = new H2EmbeddedDataSourceConfig() .setFilename(file.getAbsolutePath()) .setInitScript("io/airlift/dbpool/h2.ddl") .setCipher(Cipher.AES) .setFilePassword("filePassword"); H2EmbeddedDataSource dataSource = new H2EmbeddedDataSource(config); connection = dataSource.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery("select * from message"); } finally { closeQuietly(resultSet); closeQuietly(statement); closeQuietly(connection); } }
@Test public void testDefaults() { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(H2EmbeddedDataSourceConfig.class) .setAllowLiterals(AllowLiterals.ALL) .setCacheSize(16384) .setCipher(Cipher.NONE) .setCompressLob(CompressLob.LZF) .setFilename(null) .setFilePassword(null) .setInitScript(null) .setMaxLengthInplaceLob(1024) .setMaxMemoryRows(10000) .setMvccEnabled(true) .setMaxConnections(10) .setMaxConnectionWait(new Duration(500, TimeUnit.MILLISECONDS))); }
@Test public void testDefaults() { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(H2EmbeddedDataSourceConfig.class) .setAllowLiterals(AllowLiterals.ALL) .setCacheSize(16384) .setCipher(Cipher.NONE) .setCompressLob(CompressLob.LZF) .setFilename(null) .setFilePassword(null) .setInitScript(null) .setMaxLengthInplaceLob(1024) .setMaxMemoryRows(10000) .setMvccEnabled(true) .setMaxConnections(10) .setMaxConnectionWait(new Duration(500, TimeUnit.MILLISECONDS))); }