Search in sources :

Example 6 with Path

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

the class TxnScoreboardTest method testWideRange.

@Test
public void testWideRange() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (final Path shmPath = new Path();
            final TxnScoreboard scoreboard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 1024)) {
            scoreboard.acquireTxn(15);
            scoreboard.releaseTxn(15);
            scoreboard.acquireTxn(900992);
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 7 with Path

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

the class TableWriterTest method testRemoveColumn.

private void testRemoveColumn(TableModel model) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        CairoTestUtils.create(model);
        long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
        Rnd rnd = new Rnd();
        try (TableWriter writer = new TableWriter(configuration, model.getName())) {
            // optional
            writer.warmUp();
            ts = append10KProducts(ts, rnd, writer);
            writer.removeColumn("supplier");
            final NativeLPSZ lpsz = new NativeLPSZ();
            try (Path path = new Path()) {
                path.of(root).concat(model.getName());
                final int plen = path.length();
                FF.iterateDir(path.$(), (file, type) -> {
                    lpsz.of(file);
                    if (type == Files.DT_DIR && !Files.isDots(lpsz)) {
                        Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.i").$()));
                        Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.d").$()));
                        Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.top").$()));
                    }
                });
            }
            ts = append10KNoSupplier(ts, rnd, writer);
            writer.commit();
            Assert.assertEquals(20000, writer.size());
        }
        try (TableWriter writer = new TableWriter(configuration, model.getName())) {
            append10KNoSupplier(ts, rnd, writer);
            writer.commit();
            Assert.assertEquals(30000, writer.size());
        }
    });
}
Also used : Path(io.questdb.std.str.Path) NativeLPSZ(io.questdb.std.str.NativeLPSZ)

Example 8 with Path

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

the class TableWriterTest method testOpenWriterMissingTxFile.

@Test
public void testOpenWriterMissingTxFile() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
        try (Path path = new Path()) {
            Assert.assertTrue(FF.remove(path.of(root).concat("all").concat(TableUtils.TXN_FILE_NAME).$()));
            try {
                new TableWriter(configuration, "all");
                Assert.fail();
            } catch (CairoException ignore) {
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 9 with Path

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

the class TxnTest method testFailedTxWriterDoesNotCorruptTable.

@Test
public void testFailedTxWriterDoesNotCorruptTable() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        FilesFacade errorFf = new FilesFacadeImpl() {

            @Override
            public long mremap(long fd, long addr, long previousSize, long newSize, long offset, int mode, int memoryTag) {
                return -1;
            }
        };
        FilesFacadeImpl cleanFf = new FilesFacadeImpl();
        assertMemoryLeak(() -> {
            String tableName = "txntest";
            try (Path path = new Path()) {
                try (MemoryMARW mem = Vm.getCMARWInstance();
                    TableModel model = new TableModel(configuration, tableName, PartitionBy.DAY)) {
                    model.timestamp();
                    TableUtils.createTable(configuration, mem, path, model, 1);
                }
            }
            try (Path path = new Path()) {
                path.of(configuration.getRoot()).concat(tableName);
                int testPartitionCount = 3000;
                try (TxWriter txWriter = new TxWriter(cleanFf, path, PartitionBy.DAY)) {
                    // Add lots of partitions
                    for (int i = 0; i < testPartitionCount; i++) {
                        txWriter.updatePartitionSizeByTimestamp(i * Timestamps.DAY_MICROS, i + 1);
                    }
                    txWriter.updateMaxTimestamp(testPartitionCount * Timestamps.DAY_MICROS + 1);
                    txWriter.finishPartitionSizeUpdate();
                    txWriter.commit(CommitMode.SYNC, new ObjList<>());
                }
                // Reopen without OS errors
                try (TxWriter txWriter = new TxWriter(cleanFf, path, PartitionBy.DAY)) {
                    // Read lots of partitions
                    Assert.assertEquals(testPartitionCount, txWriter.getPartitionCount());
                    for (int i = 0; i < testPartitionCount - 1; i++) {
                        Assert.assertEquals(i + 1, txWriter.getPartitionSize(i));
                    }
                }
                // Open with OS error to file extend
                try (TxWriter ignored = new TxWriter(errorFf, path, PartitionBy.DAY)) {
                    Assert.fail("Should not be able to extend on opening");
                } catch (CairoException ex) {
                // expected
                }
                // Reopen without OS errors
                try (TxWriter txWriter = new TxWriter(cleanFf, path, PartitionBy.DAY)) {
                    // Read lots of partitions
                    Assert.assertEquals(testPartitionCount, txWriter.getPartitionCount());
                    for (int i = 0; i < testPartitionCount - 1; i++) {
                        Assert.assertEquals(i + 1, txWriter.getPartitionSize(i));
                    }
                }
            }
        });
    });
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) MemoryMARW(io.questdb.cairo.vm.api.MemoryMARW) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 10 with Path

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

the class BitmapIndexTest method testWriterConstructorKeyMismatch.

@Test
public void testWriterConstructorKeyMismatch() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (MemoryA mem = openKey()) {
            mem.putByte(BitmapIndexUtils.SIGNATURE);
            mem.skip(20);
            mem.putLong(300);
            mem.skip(BitmapIndexUtils.KEY_FILE_RESERVED - mem.getAppendOffset());
        }
        // Memory impl will round truncate size to the OS page size.
        // Therefore, truncate file manually to below the expected file size
        final FilesFacade ff = FilesFacadeImpl.INSTANCE;
        try (Path path = new Path()) {
            path.of(configuration.getRoot()).concat("x").put(".k").$();
            long fd = TableUtils.openFileRWOrFail(ff, path);
            try {
                ff.truncate(fd, 64);
            } finally {
                ff.close(fd);
            }
        }
        assertWriterConstructorFail("Key count");
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Aggregations

Path (io.questdb.std.str.Path)141 Test (org.junit.Test)89 File (java.io.File)14 FilesFacade (io.questdb.std.FilesFacade)13 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)10 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)10 Rnd (io.questdb.std.Rnd)10 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)7 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)7 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)6 NativeLPSZ (io.questdb.std.str.NativeLPSZ)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)5 LPSZ (io.questdb.std.str.LPSZ)5 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RowCursor (io.questdb.cairo.sql.RowCursor)4 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)4 RingQueue (io.questdb.mp.RingQueue)4