Search in sources :

Example 21 with FilesFacadeImpl

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

the class MimeTypesCacheTest method testCannotRead1.

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

        @Override
        public boolean close(long fd) {
            closeCount.incrementAndGet();
            return true;
        }

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

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

        @Override
        public long read(long fd, long buf, long len, long offset) {
            return -1;
        }
    }, "could not read");
    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 22 with FilesFacadeImpl

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

the class MimeTypesCacheTest method testWrongFileSize4.

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

        @Override
        public long length(long fd) {
            return 1024 * 1024 * 2;
        }

        @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 23 with FilesFacadeImpl

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

the class MimeTypesCacheTest method testWrongFileSize.

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

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

        @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 24 with FilesFacadeImpl

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

the class MimeTypesCacheTest method testCannotRead2.

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

        @Override
        public boolean close(long fd) {
            closeCount.incrementAndGet();
            return true;
        }

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

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

        @Override
        public long read(long fd, long buf, long len, long offset) {
            return 128;
        }
    }, "could not read");
    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 25 with FilesFacadeImpl

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

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