Search in sources :

Example 1 with BindVariableService

use of io.questdb.cairo.sql.BindVariableService in project questdb by bluestreak01.

the class MemoryLeakTest method testQuestDbForLeaks.

@Test
public void testQuestDbForLeaks() throws Exception {
    assertMemoryLeak(() -> {
        int N = 1_000_000;
        populateUsersTable(engine, N);
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            final BindVariableService bindVariableService = new BindVariableServiceImpl(configuration);
            bindVariableService.setLong("low", 0L);
            bindVariableService.setLong("high", 0L);
            try (final SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null)) {
                StringSink sink = new StringSink();
                sink.clear();
                sink.put("users");
                sink.put(" latest by id where sequence > :low and sequence < :high");
                try (RecordCursorFactory rcf = compiler.compile(sink, executionContext).getRecordCursorFactory()) {
                    bindVariableService.setLong("low", 0);
                    bindVariableService.setLong("high", N + 1);
                    Misc.free(rcf.getCursor(executionContext));
                }
            }
        } finally {
            Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
            engine.clear();
            Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) BindVariableService(io.questdb.cairo.sql.BindVariableService) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Aggregations

BindVariableService (io.questdb.cairo.sql.BindVariableService)1 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 StringSink (io.questdb.std.str.StringSink)1 Test (org.junit.Test)1