use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class CachingWriterFactoryTest method testLockNonExisting.
@Test
public void testLockNonExisting() throws Exception {
final JournalMetadata<?> x = new JournalStructure("x").$date("ts").$().build();
wf.lock(x.getName());
try {
wf.writer(x);
Assert.fail();
} catch (JournalLockedException ignored) {
}
wf.unlock(x.getName());
try (JournalWriter wx = wf.writer(x)) {
Assert.assertNotNull(wx);
}
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class CachingWriterFactoryTest method testOneThreadGetRelease.
@Test
public void testOneThreadGetRelease() throws Exception {
final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
JournalWriter x;
JournalWriter y;
x = wf.writer(m);
try {
Assert.assertEquals(0, wf.countFreeWriters());
Assert.assertNotNull(x);
Assert.assertTrue(x.isOpen());
Assert.assertTrue(x == wf.writer(m));
} finally {
x.close();
}
Assert.assertEquals(1, wf.countFreeWriters());
y = wf.writer(m);
try {
Assert.assertNotNull(y);
Assert.assertTrue(y.isOpen());
Assert.assertTrue(y == x);
} finally {
y.close();
}
Assert.assertEquals(1, wf.countFreeWriters());
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class CachingWriterFactoryTest method testAllocateAndClear.
@Test
public void testAllocateAndClear() throws Exception {
final JournalMetadata<?> m = new JournalStructure("z").$date("ts").$().build();
int n = 2;
final CyclicBarrier barrier = new CyclicBarrier(n);
final CountDownLatch halt = new CountDownLatch(n);
final AtomicInteger errors = new AtomicInteger();
final AtomicInteger writerCount = new AtomicInteger();
new Thread(() -> {
try {
for (int i = 0; i < 1000; i++) {
try (JournalWriter ignored = wf.writer(m)) {
writerCount.incrementAndGet();
} catch (WriterBusyException 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++) {
wf.releaseInactive();
LockSupport.parkNanos(10L);
}
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
} finally {
halt.countDown();
}
}).start();
halt.await();
Assert.assertTrue(writerCount.get() > 0);
Assert.assertEquals(0, errors.get());
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class CachingWriterFactoryTest method testFactoryCloseBeforeRelease.
@Test
public void testFactoryCloseBeforeRelease() throws Exception {
final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
JournalWriter x;
x = wf.writer(m);
try {
Assert.assertEquals(0, wf.countFreeWriters());
Assert.assertNotNull(x);
Assert.assertTrue(x.isOpen());
Assert.assertTrue(x == wf.writer(m));
wf.close();
} finally {
x.close();
}
Assert.assertFalse(x.isOpen());
try {
wf.writer(m);
} catch (FactoryClosedException ignored) {
}
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class AppendRawPartitioned method main.
public static void main(String[] args) throws JournalException, ParserException {
if (args.length < 1) {
System.out.println("Usage: AppendRawPartitioned <path>");
System.exit(1);
}
final String location = args[0];
// factory can be reused in application and must be explicitly closed when no longer needed.
try (Factory factory = new Factory(location, 1000, 1, 0)) {
// to populate it.
try (JournalWriter writer = factory.writer(new JournalStructure("customers").$int("id").$str("name").$ts("updateDate").partitionBy(PartitionBy.DAY).$())) {
Rnd rnd = new Rnd();
long timestamp = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
// enforce timestamp order
JournalEntryWriter ew = writer.entryWriter(timestamp);
// columns accessed by index
ew.putInt(0, rnd.nextPositiveInt());
ew.putStr(1, rnd.nextChars(25));
// increment timestamp by 30 seconds
timestamp += 30000;
// append record to journal
ew.append();
}
// commit all records at once
// there is no limit on how many records can be in the same transaction
writer.commit();
}
}
}
Aggregations