use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class BitmapIndexTest method testForwardReaderKeyUpdateFail.
@Test
public void testForwardReaderKeyUpdateFail() {
create(configuration, path.trimTo(plen), "x", 1024);
try (BitmapIndexWriter writer = new BitmapIndexWriter(configuration, path, "x")) {
writer.add(0, 1000);
}
try (BitmapIndexFwdReader reader = new BitmapIndexFwdReader(configuration, path.trimTo(plen), "x", 0)) {
// should have single value in cursor
RowCursor cursor = reader.getCursor(true, 0, 0, Long.MAX_VALUE);
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(1000, cursor.next());
Assert.assertFalse(cursor.hasNext());
try (Path path = new Path();
MemoryCMARW mem = Vm.getSmallCMARWInstance(configuration.getFilesFacade(), path.of(root).concat("x").put(".k").$(), MemoryTag.MMAP_DEFAULT)) {
// change sequence but not sequence check
long seq = mem.getLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE);
mem.putLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE, 22);
try {
reader.getCursor(true, 10, 0, Long.MAX_VALUE);
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "could not consistently"));
}
try {
reader.getCursor(true, 0, 0, Long.MAX_VALUE);
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "could not consistently"));
}
mem.putLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE, seq);
// test that index recovers
cursor = reader.getCursor(true, 0, 0, Long.MAX_VALUE);
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(1000, cursor.next());
Assert.assertFalse(cursor.hasNext());
}
}
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class BitmapIndexTest method openKey.
private MemoryA openKey() {
try (Path path = new Path()) {
MemoryMA mem = Vm.getSmallCMARWInstance(configuration.getFilesFacade(), path.of(configuration.getRoot()).concat("x").put(".k").$(), MemoryTag.MMAP_DEFAULT);
mem.toTop();
return mem;
}
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class BitmapIndexTest method testForwardCursorTimeout.
@Test
public void testForwardCursorTimeout() throws Exception {
TestUtils.assertMemoryLeak(() -> {
create(configuration, path.trimTo(plen), "x", 1024);
try (BitmapIndexWriter w = new BitmapIndexWriter(configuration, path.trimTo(plen), "x")) {
w.add(0, 10);
}
try (BitmapIndexFwdReader reader = new BitmapIndexFwdReader(configuration, path.trimTo(plen), "x", 0)) {
try (MemoryMARW mem = Vm.getMARWInstance()) {
try (Path path = new Path()) {
path.of(configuration.getRoot()).concat("x").put(".k").$();
mem.smallFile(configuration.getFilesFacade(), path, MemoryTag.MMAP_DEFAULT);
}
long offset = BitmapIndexUtils.getKeyEntryOffset(0);
mem.putLong(offset + BitmapIndexUtils.KEY_ENTRY_OFFSET_VALUE_COUNT, 10);
try {
reader.getCursor(true, 0, 0, Long.MAX_VALUE);
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "cursor could not consistently read index header"));
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testWriteAndReadWithReadOnlyMem.
@Test
public void testWriteAndReadWithReadOnlyMem() throws Exception {
long used = Unsafe.getMemUsed();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (MemoryCMARW mem = Vm.getCMARWInstance(FF, path, 2 * FF.getPageSize(), -1, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (MemoryMR mem = new MemoryCMRImpl(FF, path, 8L * N, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testWriteAndRead.
@Test
public void testWriteAndRead() throws Exception {
long used = Unsafe.getMemUsed();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (MemoryCMARW mem = Vm.getCMARWInstance(FF, path, 2 * FF.getPageSize(), -1, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
// read in place
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (MemoryCMARW mem = Vm.getSmallCMARWInstance(FF, path, MemoryTag.MMAP_DEFAULT)) {
final int M = (int) (mem.size() / Long.BYTES);
for (int i = 0; i < M; i++) {
Assert.assertEquals(i, mem.getLong(i * 8L));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
Aggregations