Search in sources :

Example 56 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class SymbolMapTest method testSimpleAdd.

@Test
public void testSimpleAdd() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1000000;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, false);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
                Rnd rnd = new Rnd();
                long prev = -1L;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 57 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class SymbolMapTest method testReaderWithShortHeader.

@Test
public void testReaderWithShortHeader() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(configuration.getRoot())) {
            int plen = path.length();
            Assert.assertTrue(configuration.getFilesFacade().touch(path.concat("x").put(".o").$()));
            try {
                new SymbolMapReaderImpl(configuration, path.trimTo(plen), "x", 0);
                Assert.fail();
            } catch (CairoException e) {
                Assert.assertTrue(Chars.contains(e.getMessage(), "too short"));
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 58 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReadFailTest method testReloadTimeout.

@Test
public void testReloadTimeout() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE).col("a", ColumnType.INT).col("b", ColumnType.LONG).timestamp()) {
            CairoTestUtils.create(model);
        }
        try (Path path = new Path();
            TableReader reader = new TableReader(configuration, "x");
            ReadWriteMemory mem = new ReadWriteMemory()) {
            final Rnd rnd = new Rnd();
            final int N = 1000;
            // home path at txn file
            path.of(configuration.getRoot()).concat("x").concat(TableUtils.TXN_FILE_NAME).$();
            try (TableWriter w = new TableWriter(configuration, "x")) {
                for (int i = 0; i < N; i++) {
                    TableWriter.Row r = w.newRow(0);
                    r.putInt(0, rnd.nextInt());
                    r.putLong(1, rnd.nextLong());
                    r.append();
                }
                w.commit();
            }
            Assert.assertTrue(reader.reload());
            RecordCursor cursor = reader.getCursor();
            rnd.reset();
            int count = 0;
            while (cursor.hasNext()) {
                Record r = cursor.next();
                Assert.assertEquals(rnd.nextInt(), r.getInt(0));
                Assert.assertEquals(rnd.nextLong(), r.getLong(1));
                count++;
            }
            Assert.assertEquals(N, count);
            mem.of(configuration.getFilesFacade(), path, configuration.getFilesFacade().getPageSize());
            // keep txn file parameters
            long offset = configuration.getFilesFacade().length(mem.getFd());
            long txn = mem.getLong(TableUtils.TX_OFFSET_TXN);
            // corrupt the txn file
            mem.jumpTo(TableUtils.TX_OFFSET_TXN);
            mem.putLong(123);
            mem.jumpTo(offset);
            mem.close();
            // this should time out
            try {
                reader.reload();
                Assert.fail();
            } catch (CairoException e) {
                TestUtils.assertContains(e.getMessage(), "timeout");
            }
            // restore txn file to its former glory
            mem.of(configuration.getFilesFacade(), path, configuration.getFilesFacade().getPageSize());
            mem.jumpTo(TableUtils.TX_OFFSET_TXN);
            mem.putLong(txn);
            mem.jumpTo(offset);
            mem.close();
            mem.close();
            // make sure reload functions correctly
            Assert.assertFalse(reader.reload());
            try (TableWriter w = new TableWriter(configuration, "x")) {
                // add more data
                for (int i = 0; i < N; i++) {
                    TableWriter.Row r = w.newRow(0);
                    r.putInt(0, rnd.nextInt());
                    r.putLong(1, rnd.nextLong());
                    r.append();
                }
                w.commit();
            }
            // does positive reload work?
            Assert.assertTrue(reader.reload());
            // can reader still see correct data?
            cursor = reader.getCursor();
            rnd.reset();
            count = 0;
            while (cursor.hasNext()) {
                Record r = cursor.next();
                Assert.assertEquals(rnd.nextInt(), r.getInt(0));
                Assert.assertEquals(rnd.nextLong(), r.getLong(1));
                count++;
            }
            Assert.assertEquals(2 * N, count);
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordCursor(com.questdb.common.RecordCursor) Rnd(com.questdb.std.Rnd) Record(com.questdb.common.Record) Test(org.junit.Test)

Example 59 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReaderMetadataCorruptionTest method assertMetaConstructorFailure.

private void assertMetaConstructorFailure(String[] names, int[] types, int columnCount, int partitionType, int timestampIndex, String contains, long pageSize) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path()) {
            path.of(root).concat("x");
            final int rootLen = path.length();
            if (FilesFacadeImpl.INSTANCE.mkdirs(path.put(Files.SEPARATOR).$(), 509) == -1) {
                throw CairoException.instance(FilesFacadeImpl.INSTANCE.errno()).put("Cannot create dir: ").put(path);
            }
            try (AppendMemory mem = new AppendMemory()) {
                mem.of(FilesFacadeImpl.INSTANCE, path.trimTo(rootLen).concat(TableUtils.META_FILE_NAME).$(), pageSize);
                mem.putInt(columnCount);
                mem.putInt(partitionType);
                mem.putInt(timestampIndex);
                mem.jumpTo(TableUtils.META_OFFSET_COLUMN_TYPES);
                for (int i = 0; i < names.length; i++) {
                    mem.putByte((byte) types[i]);
                    mem.putBool(false);
                    mem.skip(14);
                }
                for (int i = 0; i < names.length; i++) {
                    mem.putStr(names[i]);
                }
            }
            try {
                new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "x", path);
                Assert.fail();
            } catch (CairoException e) {
                TestUtils.assertContains(e.getMessage(), contains);
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path)

Example 60 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReaderMetadataCorruptionTest method assertTransitionIndexValidation.

private void assertTransitionIndexValidation(int columnCount) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path()) {
            CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
            path.of(root).concat("all").concat(TableUtils.META_FILE_NAME).$();
            long len = FilesFacadeImpl.INSTANCE.length(path);
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "x", path)) {
                try (AppendMemory mem = new AppendMemory()) {
                    mem.of(FilesFacadeImpl.INSTANCE, path, FilesFacadeImpl.INSTANCE.getPageSize());
                    mem.putInt(columnCount);
                    mem.skip(len - 4);
                }
                try {
                    metadata.createTransitionIndex();
                } catch (CairoException e) {
                    TestUtils.assertContains(e.getMessage(), "Incorrect columnCount");
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path)

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