Search in sources :

Example 11 with FilesFacade

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

the class SqlCompilerTest method testCreateAsSelectIOError2.

@Test
public void testCreateAsSelectIOError2() throws Exception {
    String sql = "create table y as (" + "select rnd_symbol(4,4,4,2) a from long_sequence(10000)" + "), cast(a as STRING)";
    final FilesFacade ff = new FilesFacadeImpl() {

        int mapCount = 0;

        @Override
        public long getMapPageSize() {
            return getPageSize();
        }

        @Override
        public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
            // and then fails to close txMem
            if (mapCount++ > 2) {
                return -1;
            }
            return super.mmap(fd, len, offset, flags, memoryTag);
        }
    };
    assertFailure(ff, sql, "Could not create table. See log for details");
}
Also used : FilesFacade(io.questdb.std.FilesFacade) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 12 with FilesFacade

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

the class SqlCompilerTest method testCreateAsSelectIOError.

@Test
public void testCreateAsSelectIOError() throws Exception {
    String sql = "create table y as (" + "select rnd_symbol(4,4,4,2) a from long_sequence(10000)" + "), cast(a as STRING)";
    final FilesFacade ff = new FilesFacadeImpl() {

        int mapCount = 0;

        @Override
        public long getMapPageSize() {
            return getPageSize();
        }

        @Override
        public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
            if (mapCount++ > 5) {
                return -1;
            }
            return super.mmap(fd, len, offset, flags, memoryTag);
        }
    };
    assertFailure(ff, sql, "Could not create table. See log for details");
}
Also used : FilesFacade(io.questdb.std.FilesFacade) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 13 with FilesFacade

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

the class SampleByTest method testSampleFillLinearConstructorFail.

@Test
public void testSampleFillLinearConstructorFail() 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 = 4;

            @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 {
                    compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext);
                    Assert.fail();
                } catch (SqlException 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) SqlException(io.questdb.griffin.SqlException) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 14 with FilesFacade

use of io.questdb.std.FilesFacade 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 15 with FilesFacade

use of io.questdb.std.FilesFacade 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)

Aggregations

FilesFacade (io.questdb.std.FilesFacade)29 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)14 Test (org.junit.Test)14 Path (io.questdb.std.str.Path)13 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)6 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 LPSZ (io.questdb.std.str.LPSZ)3 MemoryCMARWImpl (io.questdb.cairo.vm.MemoryCMARWImpl)2 Rnd (io.questdb.std.Rnd)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 TableModel (io.questdb.cairo.TableModel)1 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)1 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)1 SqlException (io.questdb.griffin.SqlException)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 File (java.io.File)1