use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestTools method testBackupRestore.
private void testBackupRestore() throws SQLException {
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/testBackupRestore";
String user = "sa", password = "abc";
final String fileName = getBaseDir() + "/b2.zip";
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testBackupRestore", "-quiet");
Connection conn = getConnection(url, user, password);
conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.close();
Backup.main("-file", fileName, "-dir", getBaseDir(), "-db", "testBackupRestore", "-quiet");
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testBackupRestore", "-quiet");
Restore.main("-file", fileName, "-dir", getBaseDir(), "-db", "testBackupRestore", "-quiet");
conn = getConnection("jdbc:h2:" + getBaseDir() + "/testBackupRestore", "sa", "abc");
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
assertTrue(rs.next());
assertFalse(rs.next());
new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) {
@Override
public void test() throws SQLException {
// must fail when the database is in use
Backup.main("-file", fileName, "-dir", getBaseDir(), "-db", "testBackupRestore");
}
};
conn.close();
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testBackupRestore", "-quiet");
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestTools method testChangeFileEncryptionWithWrongPassword.
private void testChangeFileEncryptionWithWrongPassword() throws SQLException {
if (config.mvStore) {
// doesn't detect wrong passwords
return;
}
org.h2.Driver.load();
final String dir = getBaseDir();
// TODO: this doesn't seem to work in MVSTORE mode yet
String url = "jdbc:h2:" + dir + "/testChangeFileEncryption;CIPHER=AES";
DeleteDbFiles.execute(dir, "testChangeFileEncryption", true);
Connection conn = getConnection(url, "sa", "abc 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) " + "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
conn.close();
// try with wrong password, this used to have a bug where it kept the
// file handle open
new AssertThrows(SQLException.class) {
@Override
public void test() throws SQLException {
ChangeFileEncryption.execute(dir, "testChangeFileEncryption", "AES", "wrong".toCharArray(), "def".toCharArray(), true);
}
};
ChangeFileEncryption.execute(dir, "testChangeFileEncryption", "AES", "abc".toCharArray(), "def".toCharArray(), true);
conn = getConnection(url, "sa", "def 123");
stat = conn.createStatement();
stat.execute("SELECT * FROM TEST");
conn.close();
String[] args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption", "-quiet" };
DeleteDbFiles.main(args);
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestTraceSystem method testAdapter.
private void testAdapter() {
TraceSystem ts = new TraceSystem(null);
ts.setName("test");
ts.setLevelFile(TraceSystem.ADAPTER);
ts.getTrace("test").debug("test");
ts.getTrace("test").info("test");
ts.getTrace("test").error(new Exception(), "test");
// The used SLF4J-nop logger has all log levels disabled,
// so this should be reflected in the trace system.
assertFalse(ts.isEnabled(TraceSystem.INFO));
assertFalse(ts.getTrace("test").isInfoEnabled());
ts.close();
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestPgServer method createPgServer.
private Server createPgServer(String... args) throws SQLException {
Server server = Server.createPgServer(args);
int failures = 0;
for (; ; ) {
try {
server.start();
return server;
} catch (SQLException e) {
// the sleeps are too mitigate "port in use" exceptions on Jenkins
if (e.getErrorCode() != ErrorCode.EXCEPTION_OPENING_PORT_2 || ++failures > 10) {
throw e;
}
println("Sleeping");
try {
Thread.sleep(100);
} catch (InterruptedException e2) {
throw new RuntimeException(e2);
}
}
}
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestReader method test.
@Override
public void test() throws Exception {
String s = "\u00ef\u00f6\u00fc";
StringReader r = new StringReader(s);
InputStream in = new ReaderInputStream(r);
byte[] buff = IOUtils.readBytesAndClose(in, 0);
InputStream in2 = new ByteArrayInputStream(buff);
Reader r2 = IOUtils.getBufferedReader(in2);
String s2 = IOUtils.readStringAndClose(r2, Integer.MAX_VALUE);
assertEquals(s, s2);
}
Aggregations