Search in sources :

Example 26 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class MultiColumnJoinTest method setUp.

@Before
public void setUp() throws Exception {
    getFactory().getConfiguration().exists("");
    try (JournalWriter a = getFactory().writer(new JournalStructure("a").$int("x").$str("y").$double("amount").$())) {
        try (JournalWriter b = getFactory().writer(new JournalStructure("b").$int("x").$str("y").$str("name").$())) {
            Rnd rnd = new Rnd();
            for (int i = 0; i < 10; i++) {
                int x = rnd.nextInt();
                String y = rnd.nextString(rnd.nextPositiveInt() % 15);
                JournalEntryWriter ewa = a.entryWriter();
                JournalEntryWriter ewb = b.entryWriter();
                ewa.putInt(0, x);
                ewa.putStr(1, y);
                ewa.putDouble(2, rnd.nextDouble());
                ewa.append();
                ewb.putInt(0, x);
                ewb.putStr(1, y);
                ewb.putStr(2, rnd.nextChars(rnd.nextPositiveInt() % 20));
                ewb.append();
            }
        }
    // a.commit();
    // b.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) Before(org.junit.Before)

Example 27 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class CachingReaderFactoryTest method testSerialOpenClose.

@Test
public void testSerialOpenClose() throws Exception {
    // create journal
    final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m).close();
    try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
        Journal firstReader = null;
        for (int i = 0; i < 1000; i++) {
            try (Journal reader = rf.reader(m)) {
                if (firstReader == null) {
                    firstReader = reader;
                }
                Assert.assertNotNull(reader);
                Assert.assertSame(firstReader, reader);
            }
        }
    }
}
Also used : JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 28 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class CachingReaderFactoryTest method testCloseWithActiveReader.

@Test
public void testCloseWithActiveReader() throws Exception {
    // create journal
    final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m).close();
    try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
        Journal reader = rf.reader(m);
        Assert.assertNotNull(reader);
        rf.close();
        Assert.assertTrue(reader.isOpen());
        reader.close();
        Assert.assertFalse(reader.isOpen());
    }
}
Also used : JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 29 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class CachingReaderFactoryTest method testAllocateAndClear.

@Test
public void testAllocateAndClear() throws Exception {
    final JournalMetadata<?> m = new JournalStructure("z").$date("ts").$().build();
    getFactory().writer(m).close();
    try (CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1, 2)) {
        int n = 2;
        final CyclicBarrier barrier = new CyclicBarrier(n);
        final CountDownLatch halt = new CountDownLatch(n);
        final AtomicInteger errors = new AtomicInteger();
        final AtomicInteger readerCount = new AtomicInteger();
        new Thread(() -> {
            try {
                for (int i = 0; i < 1000; i++) {
                    try (Journal ignored = rf.reader(m)) {
                        readerCount.incrementAndGet();
                    } catch (FactoryFullException ignored) {
                    }
                    if (i == 1) {
                        barrier.await();
                    }
                    LockSupport.parkNanos(10L);
                }
            } catch (Exception e) {
                e.printStackTrace();
                errors.incrementAndGet();
            } finally {
                halt.countDown();
            }
        }).start();
        new Thread(() -> {
            try {
                barrier.await();
                for (int i = 0; i < 1000; i++) {
                    rf.releaseInactive();
                    LockSupport.parkNanos(10L);
                }
            } catch (Exception e) {
                e.printStackTrace();
                errors.incrementAndGet();
            } finally {
                halt.countDown();
            }
        }).start();
        halt.await();
        Assert.assertTrue(readerCount.get() > 0);
        Assert.assertEquals(0, errors.get());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) CountDownLatch(java.util.concurrent.CountDownLatch) FactoryFullException(com.questdb.ex.FactoryFullException) JournalLockedException(com.questdb.ex.JournalLockedException) JournalException(com.questdb.std.ex.JournalException) FactoryFullException(com.questdb.ex.FactoryFullException) RetryLockException(com.questdb.ex.RetryLockException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 30 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class CachingReaderFactoryTest method testGetReadersBeforeFailure.

@SuppressWarnings("InfiniteLoopStatement")
@Test
public void testGetReadersBeforeFailure() throws Exception {
    // create journal
    final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m).close();
    try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
        ObjList<Journal> readers = new ObjList<>();
        try {
            do {
                readers.add(rf.reader(m));
            } while (true);
        } catch (FactoryFullException e) {
            Assert.assertEquals(rf.getMaxEntries(), readers.size());
        } finally {
            for (int i = 0, n = readers.size(); i < n; i++) {
                readers.getQuick(i).close();
            }
        }
    }
}
Also used : ObjList(com.questdb.std.ObjList) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) FactoryFullException(com.questdb.ex.FactoryFullException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

JournalStructure (com.questdb.store.factory.configuration.JournalStructure)74 JournalWriter (com.questdb.store.JournalWriter)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)47 Rnd (com.questdb.std.Rnd)43 Test (org.junit.Test)43 AbstractTest (com.questdb.test.tools.AbstractTest)40 BeforeClass (org.junit.BeforeClass)11 JournalException (com.questdb.std.ex.JournalException)9 Journal (com.questdb.store.Journal)9 JournalLockedException (com.questdb.ex.JournalLockedException)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 RetryLockException (com.questdb.ex.RetryLockException)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 FactoryFullException (com.questdb.ex.FactoryFullException)4 StringSink (com.questdb.std.str.StringSink)4 Factory (com.questdb.store.factory.Factory)4 FactoryClosedException (com.questdb.ex.FactoryClosedException)3