Search in sources :

Example 46 with Path

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());
        }
    }
}
Also used : Path(com.questdb.std.str.Path) RowCursor(com.questdb.common.RowCursor) Test(org.junit.Test)

Example 47 with Path

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());
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 48 with Path

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());
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 49 with Path

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());
}
Also used : Path(com.questdb.std.str.Path) LPSZ(com.questdb.std.str.LPSZ) Test(org.junit.Test)

Example 50 with Path

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());
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Aggregations

Path (com.questdb.std.str.Path)74 Test (org.junit.Test)46 File (java.io.File)8 Rnd (com.questdb.std.Rnd)7 LPSZ (com.questdb.std.str.LPSZ)6 NativeLPSZ (com.questdb.std.str.NativeLPSZ)5 NumericException (com.questdb.common.NumericException)3 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)3 DirectCharSequence (com.questdb.std.str.DirectCharSequence)3 StringSink (com.questdb.std.str.StringSink)3 RowCursor (com.questdb.common.RowCursor)2 CreateTableModel (com.questdb.griffin.lexer.model.CreateTableModel)2 ObjList (com.questdb.std.ObjList)2 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 ByteBuffer (java.nio.ByteBuffer)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 Chars (com.questdb.std.Chars)1 FilesFacade (com.questdb.std.FilesFacade)1