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));
}
}
}
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));
}
}
}
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));
}
}
}
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);
}
}
}
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());
}
});
}
Aggregations