Search in sources :

Example 51 with Path

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

the class SymbolMapTest method testMapDoesNotExist.

@Test
public void testMapDoesNotExist() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(configuration.getRoot())) {
            try {
                new SymbolMapWriter(configuration, path, "x", 0);
                Assert.fail();
            } catch (CairoException e) {
                Assert.assertTrue(Chars.contains(e.getMessage(), "does not exist"));
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 52 with Path

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

the class SymbolMapTest method testRollback.

@Test
public void testRollback() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1024;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, true);
            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;
                }
                writer.rollback(N / 2);
                prev = N / 2 - 1;
                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 53 with Path

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

the class SymbolMapTest method testShortHeader.

@Test
public void testShortHeader() 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 SymbolMapWriter(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 54 with Path

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

the class SymbolMapTest method testTransactionalRead.

@Test
public void testTransactionalRead() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1000000;
        Rnd rnd = new Rnd();
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, false);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
                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);
                    prev = key;
                }
                rnd.reset();
                try (SymbolMapReaderImpl reader = new SymbolMapReaderImpl(configuration, path, "x", N)) {
                    for (int i = 0; i < N; i++) {
                        CharSequence cs = rnd.nextChars(10);
                        TestUtils.assertEquals(cs, reader.value(i));
                        Assert.assertEquals(i, reader.getQuick(cs));
                    }
                    Assert.assertNull(reader.value(N));
                    Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.getQuick("hola"));
                    Assert.assertEquals(N, writer.put("XYZ"));
                    // must not be able to read new symbol
                    Assert.assertNull(reader.value(N));
                    Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.getQuick("XYZ"));
                    reader.updateSymbolCount(N + 1);
                    TestUtils.assertEquals("XYZ", reader.value(N));
                    Assert.assertEquals(N, reader.getQuick("XYZ"));
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 55 with Path

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

the class SymbolMapTest method testAppend.

@Test
public void testAppend() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1000;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, true);
            Rnd rnd = new Rnd();
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
                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;
                }
            }
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", N)) {
                long prev = N - 1;
                // append second batch and check that symbol keys start with N
                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;
                }
                // try append first batch - this should return symbol keys starting with 0
                rnd.reset();
                prev = -1;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    prev = key;
                }
                Assert.assertEquals(SymbolTable.VALUE_IS_NULL, writer.put(null));
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Rnd(com.questdb.std.Rnd) 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