Search in sources :

Example 26 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class SampleByTest method testSampleFillLinearFail.

@Test
public void testSampleFillLinearFail() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
        FilesFacade ff = new FilesFacadeImpl() {

            int count = 10;

            @Override
            public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
                if (count-- > 0) {
                    return super.mmap(fd, len, offset, flags, memoryTag);
                }
                return -1;
            }
        };
        CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        try (CairoEngine engine = new CairoEngine(configuration)) {
            try (SqlCompiler compiler = new SqlCompiler(engine)) {
                try {
                    try (RecordCursorFactory factory = compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext).getRecordCursorFactory()) {
                        // with mmap count = 5 we should get failure in cursor
                        factory.getCursor(sqlExecutionContext);
                    }
                    Assert.fail();
                } catch (CairoException e) {
                    Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
                }
                Assert.assertEquals(0, engine.getBusyReaderCount());
                Assert.assertEquals(0, engine.getBusyWriterCount());
            }
        }
    });
}
Also used : FilesFacade(io.questdb.std.FilesFacade) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 27 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class SampleByTest method testGroupByFail.

@Test
public void testGroupByFail() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " x," + " rnd_double(0) d," + " rnd_symbol('XY','ZP', null, 'UU') c" + " from" + " long_sequence(1000000)" + ")", sqlExecutionContext);
        engine.clear();
        final FilesFacade ff = new FilesFacadeImpl() {

            int count = 10;

            @Override
            public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
                if (count-- > 0) {
                    return super.mmap(fd, len, offset, flags, memoryTag);
                }
                return -1;
            }
        };
        final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        try (CairoEngine engine = new CairoEngine(configuration)) {
            try (SqlCompiler compiler = new SqlCompiler(engine)) {
                try {
                    try (RecordCursorFactory factory = compiler.compile("select c, sum_t(d) from x", sqlExecutionContext).getRecordCursorFactory()) {
                        factory.getCursor(sqlExecutionContext);
                    }
                    Assert.fail();
                } catch (CairoException e) {
                    TestUtils.assertContains(e.getFlyweightMessage(), "could not mmap");
                }
                Assert.assertEquals(0, engine.getBusyReaderCount());
                Assert.assertEquals(0, engine.getBusyWriterCount());
            }
            engine.clear();
        }
    });
}
Also used : FilesFacade(io.questdb.std.FilesFacade) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 28 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class MimeTypesCacheTest method testWrongFileSize2.

@Test()
public void testWrongFileSize2() throws Exception {
    AtomicInteger closeCount = new AtomicInteger(0);
    testFailure(new FilesFacadeImpl() {

        @Override
        public long length(long fd) {
            return -1;
        }

        @Override
        public long openRO(LPSZ name) {
            return 123L;
        }

        @Override
        public boolean close(long fd) {
            closeCount.incrementAndGet();
            return true;
        }
    }, "wrong file size");
    Assert.assertEquals(1, closeCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 29 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class LineTcpConnectionContextTest method testCairoExceptionOnCreateTable.

@Test
public void testCairoExceptionOnCreateTable() throws Exception {
    String table = "cairoEx";
    runInContext(new FilesFacadeImpl() {

        @Override
        public long openRW(LPSZ name) {
            if (Chars.endsWith(name, "broken.d")) {
                return -1;
            }
            return super.openRW(name);
        }
    }, () -> {
        recvBuffer = table + ",location=us-eastcoast temperature=81,broken=23 1465839830101400200\n" + table + ",location=us-midwest temperature=82 1465839830100400200\n" + table + ",location=us-midwest temperature=83 1465839830100500200\n" + table + ",location=us-midwest temperature=85 1465839830102300200\n" + table + ",location=us-eastcoast temperature=89 1465839830102400200\n" + table + ",location=us-eastcoast temperature=80 1465839830102400200\n" + table + ",location=us-westcost temperature=82 1465839830102500200\n";
        do {
            handleContextIO();
            Assert.assertFalse(disconnected);
        } while (recvBuffer.length() > 0);
        closeContext();
        String expected = "location\ttemperature\tbroken\ttimestamp\n";
        assertTable(expected, table);
    }, null, null);
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 30 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class TxnScoreboardTest method testCleanFailsNoResourceLeak.

@Test
public void testCleanFailsNoResourceLeak() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        FilesFacade ff = new FilesFacadeImpl() {

            @Override
            public long openCleanRW(LPSZ name, long fd) {
                return -1;
            }
        };
        assertMemoryLeak(() -> {
            try (final Path shmPath = new Path()) {
                try (TxnScoreboard ignored = new TxnScoreboard(ff, shmPath.of(root), 2048)) {
                    Assert.fail();
                } catch (CairoException ex) {
                    TestUtils.assertContains(ex.getFlyweightMessage(), "could not open read-write with clean allocation");
                }
            }
        });
    });
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Aggregations

FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)48 Test (org.junit.Test)46 LPSZ (io.questdb.std.str.LPSZ)35 FilesFacade (io.questdb.std.FilesFacade)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Path (io.questdb.std.str.Path)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)1 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)1 SqlException (io.questdb.griffin.SqlException)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 Rnd (io.questdb.std.Rnd)1 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 File (java.io.File)1