Search in sources :

Example 21 with Delete

use of org.h2.command.dml.Delete 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 22 with Delete

use of org.h2.command.dml.Delete 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 23 with Delete

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

the class TestMVTableEngine method testReverseDeletePerformance.

private long testReverseDeletePerformance(boolean reverse) throws Exception {
    deleteDb(getTestName());
    String dbName = getTestName() + ";MV_STORE=TRUE";
    try (Connection conn = getConnection(dbName)) {
        Statement stat = conn.createStatement();
        stat.execute("CREATE TABLE test(id INT PRIMARY KEY, name VARCHAR) AS " + "SELECT x, x || space(1024) || x FROM system_range(1, 1000)");
        conn.setAutoCommit(false);
        PreparedStatement prep = conn.prepareStatement("DELETE FROM test WHERE id = ?");
        long start = System.nanoTime();
        for (int i = 0; i < 1000; i++) {
            prep.setInt(1, reverse ? 1000 - i : i);
            prep.execute();
        }
        long end = System.nanoTime();
        conn.commit();
        return TimeUnit.NANOSECONDS.toMillis(end - start);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) Savepoint(java.sql.Savepoint)

Example 24 with Delete

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

the class TestTransactionStore method testConcurrentTransactionsReadCommitted.

private void testConcurrentTransactionsReadCommitted() {
    MVStore s = MVStore.open(null);
    TransactionStore ts = new TransactionStore(s);
    ts.init();
    Transaction tx1, tx2;
    TransactionMap<String, String> m1, m2;
    tx1 = ts.begin();
    m1 = tx1.openMap("test");
    m1.put("1", "Hi");
    m1.put("3", ".");
    tx1.commit();
    tx1 = ts.begin();
    m1 = tx1.openMap("test");
    m1.put("1", "Hello");
    m1.put("2", "World");
    m1.remove("3");
    tx1.commit();
    // start new transaction to read old data
    tx2 = ts.begin();
    m2 = tx2.openMap("test");
    // start transaction tx1, update/delete/add
    tx1 = ts.begin();
    m1 = tx1.openMap("test");
    m1.put("1", "Hallo");
    m1.remove("2");
    m1.put("3", "!");
    assertEquals("Hello", m2.get("1"));
    assertEquals("World", m2.get("2"));
    assertNull(m2.get("3"));
    tx1.commit();
    assertEquals("Hallo", m2.get("1"));
    assertNull(m2.get("2"));
    assertEquals("!", m2.get("3"));
    tx1 = ts.begin();
    m1 = tx1.openMap("test");
    m1.put("2", "World");
    assertNull(m2.get("2"));
    assertFalse(m2.tryRemove("2"));
    assertFalse(m2.tryPut("2", "Welt"));
    tx2 = ts.begin();
    m2 = tx2.openMap("test");
    assertNull(m2.get("2"));
    m1.remove("2");
    assertNull(m2.get("2"));
    tx1.commit();
    tx1 = ts.begin();
    m1 = tx1.openMap("test");
    assertNull(m1.get("2"));
    m1.put("2", "World");
    m1.put("2", "Welt");
    tx1.rollback();
    tx1 = ts.begin();
    m1 = tx1.openMap("test");
    assertNull(m1.get("2"));
    ts.close();
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) TransactionStore(org.h2.mvstore.db.TransactionStore) Transaction(org.h2.mvstore.db.TransactionStore.Transaction)

Example 25 with Delete

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

the class TestConcurrentUpdate method test.

@Override
public void test() throws Exception {
    deleteDb("concurrent");
    final String url = getURL("concurrent;MULTI_THREADED=TRUE", true);
    Connection conn = getConnection(url);
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int primary key, name varchar)");
    Task[] tasks = new Task[THREADS];
    for (int i = 0; i < THREADS; i++) {
        final int threadId = i;
        Task t = new Task() {

            @Override
            public void call() throws Exception {
                Random r = new Random(threadId);
                Connection conn = getConnection(url);
                PreparedStatement insert = conn.prepareStatement("insert into test values(?, ?)");
                PreparedStatement update = conn.prepareStatement("update test set name = ? where id = ?");
                PreparedStatement delete = conn.prepareStatement("delete from test where id = ?");
                PreparedStatement select = conn.prepareStatement("select * from test where id = ?");
                while (!stop) {
                    try {
                        int x = r.nextInt(ROW_COUNT);
                        String data = "x" + r.nextInt(ROW_COUNT);
                        switch(r.nextInt(3)) {
                            case 0:
                                insert.setInt(1, x);
                                insert.setString(2, data);
                                insert.execute();
                                break;
                            case 1:
                                update.setString(1, data);
                                update.setInt(2, x);
                                update.execute();
                                break;
                            case 2:
                                delete.setInt(1, x);
                                delete.execute();
                                break;
                            case 4:
                                select.setInt(1, x);
                                ResultSet rs = select.executeQuery();
                                while (rs.next()) {
                                    rs.getString(2);
                                }
                                break;
                        }
                    } catch (SQLException e) {
                        handleException(e);
                    }
                }
                conn.close();
            }
        };
        tasks[i] = t;
        t.execute();
    }
    // test 2 seconds
    for (int i = 0; i < 200; i++) {
        Thread.sleep(10);
        for (Task t : tasks) {
            if (t.isFinished()) {
                i = 1000;
                break;
            }
        }
    }
    for (Task t : tasks) {
        t.get();
    }
    conn.close();
}
Also used : Task(org.h2.util.Task) Random(java.util.Random) SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Connection (java.sql.Connection)40 PreparedStatement (java.sql.PreparedStatement)39 Statement (java.sql.Statement)38 ResultSet (java.sql.ResultSet)36 JdbcConnection (org.h2.jdbc.JdbcConnection)25 SQLException (java.sql.SQLException)17 SimpleResultSet (org.h2.tools.SimpleResultSet)14 Savepoint (java.sql.Savepoint)13 StatementBuilder (org.h2.util.StatementBuilder)9 DbException (org.h2.message.DbException)8 Column (org.h2.table.Column)8 ValueString (org.h2.value.ValueString)7 Random (java.util.Random)6 Expression (org.h2.expression.Expression)5 ValueExpression (org.h2.expression.ValueExpression)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)4 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)4