Search in sources :

Example 41 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class TestAll method run.

private static void run(String... args) throws Exception {
    SelfDestructor.startCountdown(4 * 60);
    long time = System.nanoTime();
    printSystemInfo();
    // use lower values, to better test those cases,
    // and (for delays) to speed up the tests
    System.setProperty("h2.maxMemoryRows", "100");
    System.setProperty("h2.check2", "true");
    System.setProperty("h2.delayWrongPasswordMin", "0");
    System.setProperty("h2.delayWrongPasswordMax", "0");
    System.setProperty("h2.useThreadContextClassLoader", "true");
    // System.setProperty("h2.modifyOnWrite", "true");
    // speedup
    // System.setProperty("h2.syncMethod", "");
    /*

recovery tests with small freeList pages, page size 64

reopen org.h2.test.unit.TestPageStore
-Xmx1500m -D reopenOffset=3 -D reopenShift=1

power failure test
power failure test: MULTI_THREADED=TRUE
power failure test: larger binaries and additional index.
power failure test with randomly generating / dropping indexes and tables.

drop table test;
create table test(id identity, name varchar(100) default space(100));
@LOOP 10 insert into test select null, null from system_range(1, 100000);
delete from test;

documentation: review package and class level javadocs
documentation: rolling review at main.html

-------------

remove old TODO, move to roadmap

kill a test:
kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`

*/
    TestAll test = new TestAll();
    if (args.length > 0) {
        if ("travis".equals(args[0])) {
            test.travis = true;
            test.testAll();
        } else if ("vmlens".equals(args[0])) {
            test.vmlens = true;
            test.testAll();
        } else if ("reopen".equals(args[0])) {
            System.setProperty("h2.delayWrongPasswordMin", "0");
            System.setProperty("h2.check2", "false");
            System.setProperty("h2.analyzeAuto", "100");
            System.setProperty("h2.pageSize", "64");
            System.setProperty("h2.reopenShift", "5");
            FilePathRec.register();
            test.reopen = true;
            TestReopen reopen = new TestReopen();
            reopen.init();
            FilePathRec.setRecorder(reopen);
            test.runTests();
        } else if ("crash".equals(args[0])) {
            test.endless = true;
            new TestCrashAPI().runTest(test);
        } else if ("synth".equals(args[0])) {
            new TestSynth().runTest(test);
        } else if ("kill".equals(args[0])) {
            new TestKill().runTest(test);
        } else if ("random".equals(args[0])) {
            test.endless = true;
            new TestRandomSQL().runTest(test);
        } else if ("join".equals(args[0])) {
            new TestJoin().runTest(test);
            test.endless = true;
        } else if ("btree".equals(args[0])) {
            new TestBtreeIndex().runTest(test);
        } else if ("all".equals(args[0])) {
            test.testEverything();
        } else if ("codeCoverage".equals(args[0])) {
            test.codeCoverage = true;
            test.runCoverage();
        } else if ("multiThread".equals(args[0])) {
            new TestMulti().runTest(test);
        } else if ("halt".equals(args[0])) {
            new TestHaltApp().runTest(test);
        } else if ("timer".equals(args[0])) {
            new TestTimer().runTest(test);
        }
    } else {
        test.testAll();
    }
    System.out.println(TestBase.formatTime(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - time)) + " total");
}
Also used : TestBtreeIndex(org.h2.test.synth.TestBtreeIndex) TestCrashAPI(org.h2.test.synth.TestCrashAPI) TestHaltApp(org.h2.test.synth.TestHaltApp) TestJoin(org.h2.test.synth.TestJoin) TestTimer(org.h2.test.synth.TestTimer) TestMulti(org.h2.test.synth.thread.TestMulti) TestKill(org.h2.test.synth.TestKill) TestReopen(org.h2.test.unit.TestReopen) TestSynth(org.h2.test.synth.sql.TestSynth) TestRandomSQL(org.h2.test.synth.TestRandomSQL)

Example 42 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class TestMVTableEngine method testLowRetentionTime.

private void testLowRetentionTime() throws SQLException {
    deleteDb(getTestName());
    Connection conn = getConnection(getTestName() + ";RETENTION_TIME=10;WRITE_DELAY=10");
    Statement stat = conn.createStatement();
    Connection conn2 = getConnection(getTestName());
    Statement stat2 = conn2.createStatement();
    stat.execute("create alias sleep as " + "$$void sleep(int ms) throws Exception { Thread.sleep(ms); }$$");
    stat.execute("create table test(id identity, name varchar) " + "as select x, 'Init' from system_range(0, 1999)");
    for (int i = 0; i < 10; i++) {
        stat.execute("insert into test values(null, 'Hello')");
        // create and delete a large table: this will force compaction
        stat.execute("create table temp(id identity, name varchar) as " + "select x, space(1000000) from system_range(0, 10)");
        stat.execute("drop table temp");
    }
    ResultSet rs = stat2.executeQuery("select *, sleep(1) from test order by id");
    for (int i = 0; i < 2000 + 10; i++) {
        assertTrue(rs.next());
        assertEquals(i, rs.getInt(1));
    }
    assertFalse(rs.next());
    conn2.close();
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) ResultSet(java.sql.ResultSet) Savepoint(java.sql.Savepoint)

Example 43 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class TestMVTableEngine method testManyTransactions.

private void testManyTransactions() throws Exception {
    deleteDb(getTestName());
    Connection conn = getConnection(getTestName());
    Statement stat = conn.createStatement();
    stat.execute("create table test()");
    conn.setAutoCommit(false);
    stat.execute("insert into test values()");
    Connection conn2 = getConnection(getTestName());
    Statement stat2 = conn2.createStatement();
    for (long i = 0; i < 100000; i++) {
        stat2.execute("insert into test values()");
    }
    conn2.close();
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection)

Example 44 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class TestMVTableEngine method testGarbageCollectionForLOB.

private void testGarbageCollectionForLOB() throws SQLException {
    if (config.memory) {
        return;
    }
    Connection conn;
    Statement stat;
    deleteDb(getTestName());
    String url = getTestName() + ";MV_STORE=TRUE";
    url = getURL(url, true);
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int, data blob)");
    stat.execute("insert into test select x, repeat('0', 10000) " + "from system_range(1, 10)");
    stat.execute("drop table test");
    stat.execute("create table test2(id int, data blob)");
    PreparedStatement prep = conn.prepareStatement("insert into test2 values(?, ?)");
    prep.setInt(1, 1);
    assertThrows(ErrorCode.IO_EXCEPTION_1, prep).setBinaryStream(1, createFailingStream(new IOException()));
    prep.setInt(1, 2);
    assertThrows(ErrorCode.IO_EXCEPTION_1, prep).setBinaryStream(1, createFailingStream(new IllegalStateException()));
    conn.close();
    MVStore s = MVStore.open(getBaseDir() + "/" + getTestName() + ".mv.db");
    assertTrue(s.hasMap("lobData"));
    MVMap<Long, byte[]> lobData = s.openMap("lobData");
    assertEquals(0, lobData.sizeAsLong());
    assertTrue(s.hasMap("lobMap"));
    MVMap<Long, byte[]> lobMap = s.openMap("lobMap");
    assertEquals(0, lobMap.sizeAsLong());
    assertTrue(s.hasMap("lobRef"));
    MVMap<Long, byte[]> lobRef = s.openMap("lobRef");
    assertEquals(0, lobRef.sizeAsLong());
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 45 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class TestMVTableEngine method testRecover.

private void testRecover() throws Exception {
    if (config.memory) {
        return;
    }
    Connection conn;
    Statement stat;
    deleteDb(getTestName());
    String url = getTestName() + ";MV_STORE=TRUE";
    url = getURL(url, true);
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int primary key, name varchar)");
    stat.execute("insert into test values(1, 'Hello')");
    stat.execute("create table test2(name varchar)");
    stat.execute("insert into test2 values('Hello World')");
    conn.close();
    Recover.execute(getBaseDir(), getTestName());
    deleteDb(getTestName());
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("runscript from '" + getBaseDir() + "/" + getTestName() + ".h2.sql'");
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    rs = stat.executeQuery("select * from test2");
    assertTrue(rs.next());
    assertEquals("Hello World", rs.getString(1));
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) ResultSet(java.sql.ResultSet)

Aggregations

Statement (java.sql.Statement)215 ResultSet (java.sql.ResultSet)204 PreparedStatement (java.sql.PreparedStatement)201 Connection (java.sql.Connection)199 JdbcConnection (org.h2.jdbc.JdbcConnection)97 SimpleResultSet (org.h2.tools.SimpleResultSet)64 SQLException (java.sql.SQLException)56 JdbcStatement (org.h2.jdbc.JdbcStatement)46 JdbcPreparedStatement (org.h2.jdbc.JdbcPreparedStatement)35 Savepoint (java.sql.Savepoint)32 Random (java.util.Random)28 Value (org.h2.value.Value)28 DbException (org.h2.message.DbException)27 Task (org.h2.util.Task)17 Column (org.h2.table.Column)16 ValueString (org.h2.value.ValueString)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 StringReader (java.io.StringReader)12 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)11