Search in sources :

Example 71 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class ContinuousMemoryMTest method testTruncateRemapFailed.

@Test
public void testTruncateRemapFailed() {
    FilesFacade ff = new FilesFacadeImpl() {

        int counter = 1;

        boolean failTruncate = false;

        @Override
        public long mremap(long fd, long addr, long previousSize, long newSize, long offset, int mode, int memoryTag) {
            if (--counter < 0) {
                failTruncate = true;
                return -1;
            }
            return super.mremap(fd, addr, previousSize, newSize, offset, mode, memoryTag);
        }

        @Override
        public boolean truncate(long fd, long size) {
            if (failTruncate) {
                return false;
            }
            return super.truncate(fd, size);
        }
    };
    try (Path path = new Path().of(root).concat("tmp4").$()) {
        ff.touch(path);
        try {
            MemoryMARW mem = Vm.getMARWInstance();
            try {
                mem.of(ff, path, FilesFacadeImpl._16M, -1, MemoryTag.MMAP_DEFAULT);
                // this is larger than page size
                for (int i = 0; i < 3_000_000; i++) {
                    mem.putLong(i * 8, i + 1);
                }
                try {
                    mem.truncate();
                    Assert.fail();
                } catch (CairoException e) {
                    TestUtils.assertContains(e.getFlyweightMessage(), "could not remap file");
                }
            } finally {
                mem.close();
            }
            long fileLen = ff.length(path);
            Assert.assertNotEquals(0, fileLen);
            try (MemoryMR roMem = new MemoryCMRImpl(ff, path, fileLen, MemoryTag.MMAP_DEFAULT)) {
                Assert.assertEquals(fileLen, roMem.size());
                for (int i = 0; i < fileLen; i++) {
                    Assert.assertEquals(0, roMem.getByte(i));
                }
            }
        } finally {
            Assert.assertTrue(ff.remove(path));
        }
    }
}
Also used : Path(io.questdb.std.str.Path) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 72 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class ContinuousMemoryMTest method testTruncate.

@Test
public void testTruncate() {
    FilesFacade ff = FilesFacadeImpl.INSTANCE;
    try (Path path = new Path().of(root).concat("tmp1").$()) {
        ff.touch(path);
        try {
            MemoryMARW mem = Vm.getMARWInstance();
            try {
                mem.of(ff, path, FilesFacadeImpl._16M, -1, MemoryTag.MMAP_DEFAULT);
                // this is larger than page size
                for (int i = 0; i < 3_000_000; i++) {
                    mem.putLong(i * 8, i + 1);
                }
                mem.truncate();
                Assert.assertEquals(FilesFacadeImpl._16M, mem.size());
                Assert.assertEquals(0, mem.getAppendOffset());
            } finally {
                mem.close();
            }
            Assert.assertEquals(0, ff.length(path));
        } finally {
            Assert.assertTrue(ff.remove(path));
        }
    }
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 73 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class ContinuousMemoryMTest method testJumpToSetAppendPosition.

@Test
public void testJumpToSetAppendPosition() {
    FilesFacade ff = FilesFacadeImpl.INSTANCE;
    try (Path path = new Path().of(root).concat("tmp3").$()) {
        ff.touch(path);
        try {
            MemoryMARW mem = Vm.getMARWInstance();
            try {
                mem.of(ff, TableUtils.openRW(ff, path, LOG), null, -1, MemoryTag.MMAP_DEFAULT);
                mem.extend(ff.getMapPageSize() * 2);
                mem.putLong(ff.getMapPageSize(), 999);
                Assert.assertEquals(999, mem.getLong(ff.getMapPageSize()));
                mem.jumpTo(1024);
            } finally {
                mem.close();
            }
            Assert.assertEquals(ff.length(path), Files.PAGE_SIZE);
        } finally {
            Assert.assertTrue(ff.remove(path));
        }
    }
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 74 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class ContinuousMemoryMTest method testForcedExtend.

@Test
public void testForcedExtend() {
    FilesFacade ff = FilesFacadeImpl.INSTANCE;
    try (Path path = new Path().of(root).concat("tmp1").$()) {
        ff.touch(path);
        final long fd = TableUtils.openRW(ff, path, LOG);
        try {
            MemoryMARW mem = Vm.getMARWInstance();
            mem.of(ff, fd, null, -1, MemoryTag.MMAP_DEFAULT);
            mem.extend(ff.getMapPageSize() * 2);
            mem.putLong(ff.getMapPageSize(), 999);
            Assert.assertEquals(999, mem.getLong(ff.getMapPageSize()));
        } finally {
            ff.close(fd);
        }
    }
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 75 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class ContinuousMemoryMTest method testPageCountIsZeroAfterClose.

@Test
public void testPageCountIsZeroAfterClose() throws Exception {
    assertMemoryLeak(() -> {
        final FilesFacade ff = FilesFacadeImpl.INSTANCE;
        try (final Path path = Path.getThreadLocal(root).concat("t.d").$()) {
            rnd.reset();
            MemoryMARW rwMem = Vm.getMARWInstance(ff, path, ff.getMapPageSize(), 0, MemoryTag.MMAP_DEFAULT);
            rwMem.close();
            Assert.assertEquals(0, rwMem.getPageCount());
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Aggregations

Path (io.questdb.std.str.Path)141 Test (org.junit.Test)89 File (java.io.File)14 FilesFacade (io.questdb.std.FilesFacade)13 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)10 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)10 Rnd (io.questdb.std.Rnd)10 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)7 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)7 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)6 NativeLPSZ (io.questdb.std.str.NativeLPSZ)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)5 LPSZ (io.questdb.std.str.LPSZ)5 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RowCursor (io.questdb.cairo.sql.RowCursor)4 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)4 RingQueue (io.questdb.mp.RingQueue)4