Search in sources :

Example 31 with Path

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

the class SqlParserTest method testTableNameCannotOpen.

@Test
public void testTableNameCannotOpen() throws Exception {
    final FilesFacade ff = new FilesFacadeImpl() {

        @Override
        public long openRO(LPSZ name) {
            if (Chars.endsWith(name, TableUtils.META_FILE_NAME)) {
                return -1;
            }
            return super.openRO(name);
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }
    };
    assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine)) {
            TableModel[] tableModels = new TableModel[] { modelOf("tab").col("x", ColumnType.INT) };
            try {
                try {
                    for (int i = 0, n = tableModels.length; i < n; i++) {
                        CairoTestUtils.create(tableModels[i]);
                    }
                    compiler.compile("select * from tab", sqlExecutionContext);
                    Assert.fail("Exception expected");
                } catch (SqlException e) {
                    Assert.assertEquals(14, e.getPosition());
                    TestUtils.assertContains(e.getFlyweightMessage(), "could not open");
                }
            } finally {
                for (int i = 0, n = tableModels.length; i < n; i++) {
                    TableModel tableModel = tableModels[i];
                    Path path = tableModel.getPath().of(tableModel.getConfiguration().getRoot()).concat(tableModel.getName()).slash$();
                    Assert.assertEquals(0, configuration.getFilesFacade().rmdir(path));
                    tableModel.close();
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 32 with Path

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

the class SqlParserTest method testTableNameLocked.

@Test
public void testTableNameLocked() throws Exception {
    assertMemoryLeak(() -> {
        CharSequence lockedReason = engine.lock(AllowAllCairoSecurityContext.INSTANCE, "tab", "testing");
        Assert.assertNull(lockedReason);
        try {
            TableModel[] tableModels = new TableModel[] { modelOf("tab").col("x", ColumnType.INT) };
            try {
                try {
                    for (int i = 0, n = tableModels.length; i < n; i++) {
                        CairoTestUtils.create(tableModels[i]);
                    }
                    compiler.compile("select * from tab", sqlExecutionContext);
                    Assert.fail("Exception expected");
                } catch (SqlException e) {
                    Assert.assertEquals(14, e.getPosition());
                    TestUtils.assertContains(e.getFlyweightMessage(), "table is locked");
                }
            } finally {
                for (int i = 0, n = tableModels.length; i < n; i++) {
                    TableModel tableModel = tableModels[i];
                    Path path = tableModel.getPath().of(tableModel.getConfiguration().getRoot()).concat(tableModel.getName()).slash$();
                    Assert.assertEquals(0, configuration.getFilesFacade().rmdir(path));
                    tableModel.close();
                }
            }
        } finally {
            engine.unlock(AllowAllCairoSecurityContext.INSTANCE, "tab", null, false);
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 33 with Path

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

the class TableRepairTest method testDeletePartitionInTheMiddle.

@Test
public void testDeletePartitionInTheMiddle() throws Exception {
    // this delete partition actually deletes files, simulating manual intervention
    assertMemoryLeak(() -> {
        compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 10000000l) t from long_sequence(100000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
        engine.releaseAllWriters();
        try (TableReader reader = new TableReader(configuration, "tst")) {
            Assert.assertEquals(100000, reader.size());
            try (Path path = new Path()) {
                path.of(configuration.getRoot()).concat("tst").concat("1970-01-09").$();
                Assert.assertEquals(0, Files.rmdir(path));
            }
            Assert.assertEquals(100000, reader.size());
            // repair by opening and closing writer
            new TableWriter(configuration, "tst").close();
            Assert.assertTrue(reader.reload());
            Assert.assertEquals(91360, reader.size());
        }
    });
}
Also used : Path(io.questdb.std.str.Path) TableWriter(io.questdb.cairo.TableWriter) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Example 34 with Path

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

the class TableRepairTest method testDeleteActivePartition.

@Test
public void testDeleteActivePartition() throws Exception {
    // this delete partition actually deletes files, simulating manual intervention
    assertMemoryLeak(() -> {
        compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 10000000l) t from long_sequence(100000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
        engine.releaseAllWriters();
        try (TableReader reader = new TableReader(configuration, "tst")) {
            Assert.assertEquals(100000, reader.size());
            // last and "active" partition is "1970-01-12"
            try (Path path = new Path()) {
                path.of(configuration.getRoot()).concat("tst").concat("1970-01-12").$();
                Assert.assertEquals(0, Files.rmdir(path));
            }
            Assert.assertEquals(100000, reader.size());
            try (TableWriter w = new TableWriter(configuration, "tst")) {
                Assert.assertTrue(reader.reload());
                Assert.assertEquals(95040, reader.size());
                Assert.assertEquals(950390000000L, w.getMaxTimestamp());
                TableWriter.Row row = w.newRow(w.getMaxTimestamp());
                row.putInt(0, 150);
                row.putDouble(1, 0.67);
                row.append();
                w.commit();
            }
            Assert.assertTrue(reader.reload());
            Assert.assertEquals(95041, reader.size());
        }
    });
}
Also used : Path(io.questdb.std.str.Path) TableWriter(io.questdb.cairo.TableWriter) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Example 35 with Path

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

the class TxSerializerTest method removeTestPath.

public static void removeTestPath(CharSequence root) {
    Path path = Path.getThreadLocal(root);
    Files.rmdir(path.slash$());
}
Also used : Path(io.questdb.std.str.Path)

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