Search in sources :

Example 1 with RandomGen

use of org.h2.test.synth.sql.RandomGen in project h2database by h2database.

the class TestCrashAPI method testCase.

private void testCase(int seed) throws SQLException {
    printTime("seed: " + seed);
    callCount = 0;
    openCount = 0;
    random = new RandomGen();
    random.setSeed(seed);
    Connection c1 = getConnection(seed, true);
    Connection conn = null;
    for (int i = 0; i < 2000 && !stopped; i++) {
        if (objects.size() == 0) {
            try {
                conn = getConnection(seed, false);
            } catch (SQLException e) {
                if ("08004".equals(e.getSQLState())) {
                    // Wrong user/password [08004]
                    try {
                        c1.createStatement().execute("SET PASSWORD ''");
                    } catch (Throwable t) {
                        // power off or so
                        break;
                    }
                    try {
                        conn = getConnection(seed, false);
                    } catch (Throwable t) {
                        printIfBad(seed, -i, -1, t);
                    }
                } else if ("90098".equals(e.getSQLState())) {
                    // The database has been closed
                    break;
                } else {
                    printIfBad(seed, -i, -1, e);
                }
            }
            objects.add(conn);
        }
        int objectId = random.getInt(objects.size());
        if (random.getBoolean(1)) {
            objects.remove(objectId);
            continue;
        }
        if (random.getInt(2000) == 0 && conn != null) {
            ((JdbcConnection) conn).setPowerOffCount(random.getInt(50));
        }
        Object o = objects.get(objectId);
        if (o == null) {
            objects.remove(objectId);
            continue;
        }
        Class<?> in = getJdbcInterface(o);
        ArrayList<Method> methods = classMethods.get(in);
        Method m = methods.get(random.getInt(methods.size()));
        Object o2 = callRandom(seed, i, objectId, o, m);
        if (o2 != null) {
            objects.add(o2);
        }
    }
    try {
        if (conn != null) {
            conn.close();
        }
        c1.close();
    } catch (Throwable t) {
        printIfBad(seed, -101010, -1, t);
        try {
            deleteDb();
        } catch (Throwable t2) {
            printIfBad(seed, -101010, -1, t2);
        }
    }
    objects.clear();
}
Also used : RandomGen(org.h2.test.synth.sql.RandomGen) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) JdbcConnection(org.h2.jdbc.JdbcConnection) Method(java.lang.reflect.Method) Savepoint(java.sql.Savepoint)

Example 2 with RandomGen

use of org.h2.test.synth.sql.RandomGen in project h2database by h2database.

the class TestSimpleIndex method test.

@Override
public void test() throws SQLException {
    deleteDb("simpleIndex");
    conn = getConnection("simpleIndex");
    random = new RandomGen();
    stat = conn.createStatement();
    for (int i = 0; i < 10000; i++) {
        testIndex(i);
    }
}
Also used : RandomGen(org.h2.test.synth.sql.RandomGen)

Aggregations

RandomGen (org.h2.test.synth.sql.RandomGen)2 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Savepoint (java.sql.Savepoint)1 JdbcConnection (org.h2.jdbc.JdbcConnection)1