use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class BitmapIndexTest method testBackwardReaderKeyUpdateFail.
@Test
public void testBackwardReaderKeyUpdateFail() {
create(configuration, path.trimTo(plen), "x", 1024);
try (BitmapIndexWriter writer = new BitmapIndexWriter(configuration, path, "x")) {
writer.add(0, 1000);
}
try (BitmapIndexBackwardReader reader = new BitmapIndexBackwardReader(configuration, path.trimTo(plen), "x", 0)) {
// should have single value in cursor
RowCursor cursor = reader.getCursor(0, Long.MAX_VALUE);
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(1000, cursor.next());
Assert.assertFalse(cursor.hasNext());
try (Path path = new Path();
ReadWriteMemory mem = new ReadWriteMemory(configuration.getFilesFacade(), path.of(root).concat("x").put(".k").$(), configuration.getFilesFacade().getPageSize())) {
// change sequence but not sequence check
long seq = mem.getLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE);
mem.jumpTo(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE);
mem.putLong(22);
try {
reader.getCursor(10, Long.MAX_VALUE);
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "failed to consistently"));
}
try {
reader.getCursor(0, Long.MAX_VALUE);
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "failed to consistently"));
}
mem.jumpTo(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE);
mem.putLong(seq);
// test that index recovers
cursor = reader.getCursor(0, Long.MAX_VALUE);
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(1000, cursor.next());
Assert.assertFalse(cursor.hasNext());
}
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testAppendMemoryReuse.
@Test
public void testAppendMemoryReuse() throws Exception {
long used = Unsafe.getMemUsed();
try (AppendMemory mem = new AppendMemory()) {
for (int j = 0; j < 10; j++) {
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
mem.of(FF, path, 2 * FF.getPageSize());
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
try (ReadOnlyMemory ro = new ReadOnlyMemory(FF, path, FF.getPageSize(), 8L * N)) {
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, ro.getLong(i * 8));
}
}
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testAppendTruncateError.
@Test
public void testAppendTruncateError() throws Exception {
long used = Unsafe.getMemUsed();
class X extends FilesFacadeImpl {
int count = 2;
boolean allClear = false;
@Override
public boolean truncate(long fd, long size) {
if (allClear || --count > 0) {
return super.truncate(fd, size);
}
allClear = true;
return false;
}
}
X ff = new X();
long openFileCount = ff.getOpenFileCount();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (AppendMemory mem = new AppendMemory(ff, path, 2 * ff.getPageSize())) {
try {
for (int i = 0; i < N * 10; i++) {
mem.putLong(i);
}
Assert.fail();
} catch (CairoException ignore) {
}
Assert.assertTrue(mem.getAppendOffset() > 0);
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
Assert.assertEquals(openFileCount, ff.getOpenFileCount());
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testAppendAndCannotRead.
@Test
public void testAppendAndCannotRead() throws Exception {
long used = Unsafe.getMemUsed();
class X extends FilesFacadeImpl {
int count = 2;
@Override
public long openRO(LPSZ name) {
return --count > 0 ? -1 : super.openRO(name);
}
}
X ff = new X();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (AppendMemory mem = new AppendMemory(FF, path, 2 * FF.getPageSize())) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (ReadOnlyMemory mem = new ReadOnlyMemory()) {
// open non-existing
try {
mem.of(ff, path, ff.getPageSize(), 8L * N);
Assert.fail();
} catch (CairoException ignore) {
}
mem.of(ff, path, ff.getPageSize(), 8L * N);
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testAppendAndReadWithReadOnlyMem.
@Test
public void testAppendAndReadWithReadOnlyMem() throws Exception {
long used = Unsafe.getMemUsed();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (AppendMemory mem = new AppendMemory(FF, path, 2 * FF.getPageSize())) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (ReadOnlyMemory mem = new ReadOnlyMemory()) {
// open non-existing
try {
mem.of(FF, null, FF.getPageSize(), 8L * N);
Assert.fail();
} catch (CairoException ignore) {
}
mem.of(FF, path, FF.getPageSize(), 8L * N);
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
Aggregations