use of io.questdb.cairo.vm.MemorySRImpl in project questdb by bluestreak01.
the class BitmapIndexTest method testIntIndex.
@Test
public void testIntIndex() throws Exception {
final int plen = path.length();
final Rnd rnd = new Rnd();
int N = 100000000;
final int MOD = 1024;
TestUtils.assertMemoryLeak(() -> {
try (MemoryMAR mem = Vm.getMARInstance()) {
mem.wholeFile(configuration.getFilesFacade(), path.concat("x.dat").$(), MemoryTag.MMAP_DEFAULT);
for (int i = 0; i < N; i++) {
mem.putInt(rnd.nextPositiveInt() & (MOD - 1));
}
try (MemorySRImpl rwin = new MemorySRImpl()) {
rwin.of(mem, MemoryTag.MMAP_DEFAULT);
create(configuration, path.trimTo(plen), "x", N / MOD / 128);
try (BitmapIndexWriter writer = new BitmapIndexWriter()) {
writer.of(configuration, path.trimTo(plen), "x", configuration.getDataIndexKeyAppendPageSize(), configuration.getDataIndexValueAppendPageSize());
indexInts(rwin, writer, N);
}
}
}
});
}
use of io.questdb.cairo.vm.MemorySRImpl in project questdb by bluestreak01.
the class CairoMemoryTest method testSlidingWindowMemoryCannotMap.
@Test
public void testSlidingWindowMemoryCannotMap() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path()) {
path.of(temp.getRoot().getAbsolutePath());
final int N = 100000;
final Rnd rnd = new Rnd();
FilesFacade ff = new FilesFacadeImpl() {
int counter = 2;
@Override
public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
if (flags == Files.MAP_RO && --counter == 0) {
return -1;
}
return super.mmap(fd, len, offset, flags, memoryTag);
}
};
try (MemoryMA mem = Vm.getMAInstance()) {
mem.of(ff, path.concat("x.dat").$(), ff.getPageSize(), MemoryTag.MMAP_DEFAULT);
for (int i = 0; i < N; i++) {
mem.putLong(rnd.nextLong());
}
try (MemorySRImpl mem2 = new MemorySRImpl()) {
mem2.of(mem, MemoryTag.MMAP_DEFAULT);
try {
rnd.reset();
for (int i = 0; i < N; i++) {
Assert.assertEquals(rnd.nextLong(), mem2.getLong(i * 8));
}
Assert.fail();
} catch (CairoException e) {
TestUtils.assertContains(e.getMessage(), "could not mmap");
}
rnd.reset();
for (int i = 0; i < N; i++) {
Assert.assertEquals(rnd.nextLong(), mem2.getLong(i * 8));
}
}
}
}
});
}
use of io.questdb.cairo.vm.MemorySRImpl in project questdb by bluestreak01.
the class CairoMemoryTest method testSlidingWindowMemory.
@Test
public void testSlidingWindowMemory() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path()) {
path.of(temp.getRoot().getAbsolutePath());
final int N = 100000;
final Rnd rnd = new Rnd();
try (MemoryMA mem = Vm.getMAInstance()) {
mem.of(FF, path.concat("x.dat").$(), FF.getPageSize(), MemoryTag.MMAP_DEFAULT);
for (int i = 0; i < N; i++) {
mem.putLong(rnd.nextLong());
}
try (MemorySRImpl mem2 = new MemorySRImpl()) {
mem2.of(mem, MemoryTag.MMAP_DEFAULT);
// try to read outside of original page bounds
try {
mem2.getLong(N * 16);
Assert.fail();
} catch (CairoException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "Trying to map read-only page outside");
}
// make sure jump() is reported
try {
mem2.jumpTo(1024);
Assert.fail();
} catch (UnsupportedOperationException e) {
TestUtils.assertContains(e.getMessage(), "Cannot jump() read-only memory");
}
rnd.reset();
for (int i = 0; i < N; i++) {
Assert.assertEquals(rnd.nextLong(), mem2.getLong(i * 8));
}
}
}
}
});
}
Aggregations