use of org.sqlite.SQLite.SQLite3Context in project sqlite-jna by gwenn.
the class SqliteStatementTest method testQueryTimeout.
@Ignore
@Test
public void testQueryTimeout() throws Exception {
try (Statement stmt = conn.createStatement()) {
try {
stmt.setQueryTimeout(-1);
fail("negative timeout value allowed?");
} catch (SQLException e) {
}
((Conn) conn).getConn().createScalarFunction("delay", 0, FunctionFlags.SQLITE_UTF8, new ScalarCallback() {
@Override
public void func(SQLite3Context pCtx, SQLite3Values args) {
try {
Thread.currentThread().join(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
pCtx.setResultInt(0);
}
});
stmt.setQueryTimeout(1);
assertEquals(1, stmt.getQueryTimeout());
long startTime = System.currentTimeMillis();
try (ResultSet rs = stmt.executeQuery("SELECT *, delay() from test_table")) {
rs.next();
fail("Expected a timeout exception");
} catch (SQLTimeoutException e) {
long endTime = System.currentTimeMillis();
if (endTime - startTime < 1000) {
fail("Timeout expired early -- " + (endTime - startTime));
}
}
try {
stmt.execute("INSERT INTO test_table VALUES (2, delay())");
} catch (SQLiteException e) {
long endTime = System.currentTimeMillis();
if (endTime - startTime < 1000) {
fail("Timeout expired early -- " + (endTime - startTime));
}
}
}
}
Aggregations