Search in sources :

Example 26 with Path

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

the class SymbolMapTest method testReadEmptySymbolMap.

@Test
public void testReadEmptySymbolMap() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 10000;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, true);
            try (SymbolMapReaderImpl reader = new SymbolMapReaderImpl(configuration, path, "x", 0)) {
                Assert.assertEquals(N, reader.getSymbolCapacity());
                Assert.assertNull(reader.valueOf(-1));
                Assert.assertEquals(SymbolTable.VALUE_IS_NULL, reader.keyOf(null));
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 27 with Path

use of io.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, -1, NOOP_COLLECTOR)) {
                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(io.questdb.std.str.Path) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 28 with Path

use of io.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, -1, NOOP_COLLECTOR)) {
                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, -1, NOOP_COLLECTOR)) {
                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(io.questdb.std.str.Path) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 29 with Path

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

the class TxnScoreboardTest method testCrawl.

@Test
public void testCrawl() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (final Path shmPath = new Path()) {
            try (final TxnScoreboard scoreboard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 1024)) {
                for (int i = 0; i < 1500; i++) {
                    scoreboard.acquireTxn(i);
                    scoreboard.releaseTxn(i);
                }
                Assert.assertEquals(1499, scoreboard.getMin());
                // increase scoreboard size
                try (final TxnScoreboard scoreboard2 = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 2048)) {
                    Assert.assertEquals(1499, scoreboard2.getMin());
                    for (int i = 1500; i < 3000; i++) {
                        scoreboard2.acquireTxn(i);
                        scoreboard2.releaseTxn(i);
                    }
                    Assert.assertEquals(2999, scoreboard2.getMin());
                    Assert.assertEquals(2999, scoreboard.getMin());
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 30 with Path

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

the class TxnScoreboardTest method testDoesNotCleanOnNonExclusiveOpen.

@Test
public void testDoesNotCleanOnNonExclusiveOpen() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (final Path shmPath = new Path()) {
            try (final TxnScoreboard rootBoard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 2048)) {
                try (final TxnScoreboard scoreboard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 1024)) {
                    for (int i = 0; i < 1500; i++) {
                        scoreboard.acquireTxn(i);
                        scoreboard.releaseTxn(i);
                    }
                    Assert.assertEquals(1499, scoreboard.getMin());
                }
                try (final TxnScoreboard scoreboard2 = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 2048)) {
                    Assert.assertEquals(1499, scoreboard2.getMin());
                    for (int i = 1500; i < 3000; i++) {
                        scoreboard2.acquireTxn(i);
                        scoreboard2.releaseTxn(i);
                    }
                    Assert.assertEquals(2999, scoreboard2.getMin());
                }
                Assert.assertEquals(2999, rootBoard.getMin());
            }
        }
    });
}
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