Search in sources :

Example 36 with Path

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

the class TableWriterTest method testSkipOverSpuriousDir.

@Test
public void testSkipOverSpuriousDir() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        create(FF, PartitionBy.DAY, 10);
        try (Path path = new Path()) {
            // create random directory
            path.of(configuration.getRoot()).concat(PRODUCT).concat("somethingortheother").put(Files.SEPARATOR).$();
            Assert.assertTrue(0 == configuration.getFilesFacade().mkdirs(path, configuration.getMkDirMode()));
            new TableWriter(configuration, PRODUCT).close();
            Assert.assertFalse(configuration.getFilesFacade().exists(path));
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 37 with Path

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

the class TableWriterTest method testIncorrectTodoCode.

@Test
public void testIncorrectTodoCode() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
        long buf = Unsafe.malloc(8);
        try {
            Unsafe.getUnsafe().putLong(buf, 89808823424L);
            try (Path path = new Path().of(root).concat("all").concat(TableUtils.TODO_FILE_NAME).$()) {
                long fd = Files.openRW(path);
                Assert.assertTrue(fd != -1);
                Assert.assertEquals(8, Files.write(fd, buf, 8, 0));
                Files.close(fd);
            }
        } finally {
            Unsafe.free(buf, 8);
        }
        try (TableWriter writer = new TableWriter(configuration, "all")) {
            Assert.assertNotNull(writer);
            Assert.assertTrue(writer.isOpen());
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 38 with Path

use of com.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 = DateFormatUtils.parseDateTime("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 && !Chars.equals(lpsz, '.') && !Chars.equals(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(com.questdb.std.str.Path) NativeLPSZ(com.questdb.std.str.NativeLPSZ)

Example 39 with Path

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

the class CairoLineProtoParserTest method testCannotCreateTable.

@Test
public void testCannotCreateTable() throws Exception {
    TestFilesFacade ff = new TestFilesFacade() {

        boolean called = false;

        @Override
        public int mkdirs(LPSZ path, int mode) {
            if (Chars.endsWith(path, "x" + Files.SEPARATOR)) {
                called = true;
                return -1;
            }
            return super.mkdirs(path, mode);
        }

        @Override
        public boolean wasCalled() {
            return called;
        }
    };
    final String expected = "sym\tdouble\tint\tbool\tstr\ttimestamp\n" + "zzz\t1.300000000000\t11\tfalse\tnice\t2017-10-03T10:00:00.000Z\n";
    String lines = "x,sym2=xyz double=1.6,int=15i,bool=true,str=\"string1\"\n" + "x,sym1=abc double=1.3,int=11i,bool=false,str=\"string2\"\n" + "y,sym=zzz double=1.3,int=11i,bool=false,str=\"nice\"\n";
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }

        @Override
        public MicrosecondClock getClock() {
            try {
                return new TestMicroClock(DateFormatUtils.parseDateTime("2017-10-03T10:00:00.000Z"), 10);
            } catch (NumericException e) {
                throw new RuntimeException(e);
            }
        }
    };
    assertThat(expected, lines, "y", configuration);
    Assert.assertTrue(ff.wasCalled());
    try (Path path = new Path()) {
        Assert.assertEquals(TableUtils.TABLE_DOES_NOT_EXIST, TableUtils.exists(ff, path, root, "all"));
    }
}
Also used : Path(com.questdb.std.str.Path) LPSZ(com.questdb.std.str.LPSZ) NumericException(com.questdb.common.NumericException) TestMicroClock(com.questdb.test.tools.TestMicroClock) Test(org.junit.Test)

Example 40 with Path

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

the class SqlLexerOptimiserTest method assertSyntaxError.

private static void assertSyntaxError(SqlLexerOptimiser parser, CairoEngine engine, String query, int position, String contains, TableModel... tableModels) {
    try {
        for (int i = 0, n = tableModels.length; i < n; i++) {
            CairoTestUtils.create(tableModels[i]);
        }
        parser.parse(query);
        Assert.fail("Exception expected");
    } catch (ParserException e) {
        Assert.assertEquals(position, e.getPosition());
        TestUtils.assertContains(e.getMessage(), contains);
    } finally {
        Assert.assertTrue(engine.releaseAllReaders());
        for (int i = 0, n = tableModels.length; i < n; i++) {
            TableModel tableModel = tableModels[i];
            Path path = tableModel.getPath().of(tableModel.getCairoCfg().getRoot()).concat(tableModel.getName()).put(Files.SEPARATOR).$();
            Assert.assertTrue(configuration.getFilesFacade().rmdir(path));
            tableModel.close();
        }
    }
}
Also used : Path(com.questdb.std.str.Path) CreateTableModel(com.questdb.griffin.lexer.model.CreateTableModel)

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