use of de.invesdwin.context.persistence.leveldb.ezdb.ADelegateRangeTable in project invesdwin-context-persistence by subes.
the class DatabasePerformanceTest method testLevelDbPerformance.
@Test
public void testLevelDbPerformance() {
final ADelegateRangeTable<String, FDate, FDate> table = new ADelegateRangeTable<String, FDate, FDate>("testLevelDbPerformance") {
@Override
protected File getDirectory() {
return new File(ContextProperties.getCacheDirectory(), ADelegateRangeTable.class.getSimpleName());
}
@Override
protected Serde<FDate> newValueSerde() {
return FDateSerde.GET;
}
@Override
protected Serde<FDate> newRangeKeySerde() {
return FDateSerde.GET;
}
};
RangeBatch<String, FDate, FDate> batch = table.newRangeBatch();
final Instant writesStart = new Instant();
int i = 0;
for (final FDate date : newValues()) {
batch.put(HASH_KEY, date, date);
i++;
if (i % FLUSH_INTERVAL == 0) {
printProgress("Writes", writesStart, i, VALUES);
try {
batch.flush();
batch.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
batch = table.newRangeBatch();
}
}
try {
batch.flush();
batch.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
printProgress("WritesFinished", writesStart, VALUES, VALUES);
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
final ICloseableIterator<FDate> range = table.rangeValues(HASH_KEY);
int count = 0;
while (true) {
try {
final FDate value = range.next();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
} catch (final NoSuchElementException e) {
break;
}
}
Assertions.checkEquals(count, VALUES);
printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
}
printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.context.persistence.leveldb.ezdb.ADelegateRangeTable in project invesdwin-context-persistence by subes.
the class LevelDBTest method testInverseOrder.
@Test
public void testInverseOrder() {
final ADelegateRangeTable<String, FDate, Integer> rangeTable = new ADelegateRangeTable<String, FDate, Integer>("testInverseOrder") {
@Override
protected Serde<FDate> newRangeKeySerde() {
return FDateSerde.GET;
}
@Override
protected boolean allowHasNext() {
return true;
}
@Override
protected boolean allowPutWithoutBatch() {
return true;
}
};
final FDate now = FDateBuilder.newDate(2000);
final FDate oneDate = now.addDays(1);
final FDate twoDate = now.addDays(2);
final FDate threeDate = now.addDays(3);
rangeTable.put(HASHKEY, oneDate, 1);
rangeTable.put(HASHKEY, twoDate, 2);
rangeTable.put(HASHKEY, threeDate, 3);
final DelegateTableIterator<String, FDate, Integer> range3 = rangeTable.range(HASHKEY, now);
Assertions.assertThat(range3.next().getValue()).isEqualTo(1);
Assertions.assertThat(range3.next().getValue()).isEqualTo(2);
Assertions.assertThat(range3.next().getValue()).isEqualTo(3);
Assertions.assertThat(range3.hasNext()).isFalse();
try {
range3.next();
Fail.fail("Exception expected!");
} catch (final NoSuchElementException e) {
Assertions.assertThat(e).isNotNull();
}
// should already be closed but should not cause an error when calling again
range3.close();
final DelegateTableIterator<String, FDate, Integer> rangeNone = rangeTable.range(HASHKEY);
Assertions.assertThat(rangeNone.next().getValue()).isEqualTo(1);
Assertions.assertThat(rangeNone.next().getValue()).isEqualTo(2);
Assertions.assertThat(rangeNone.next().getValue()).isEqualTo(3);
Assertions.assertThat(rangeNone.hasNext()).isFalse();
try {
rangeNone.next();
Fail.fail("Exception expected!");
} catch (final NoSuchElementException e) {
Assertions.assertThat(e).isNotNull();
}
final DelegateTableIterator<String, FDate, Integer> rangeMin = rangeTable.range(HASHKEY, FDate.MIN_DATE);
Assertions.assertThat(rangeMin.next().getValue()).isEqualTo(1);
Assertions.assertThat(rangeMin.next().getValue()).isEqualTo(2);
Assertions.assertThat(rangeMin.next().getValue()).isEqualTo(3);
Assertions.assertThat(rangeMin.hasNext()).isFalse();
try {
rangeMin.next();
Fail.fail("Exception expected!");
} catch (final NoSuchElementException e) {
Assertions.assertThat(e).isNotNull();
}
final DelegateTableIterator<String, FDate, Integer> rangeMax = rangeTable.range(HASHKEY, FDate.MAX_DATE);
Assertions.assertThat(rangeMax.hasNext()).isFalse();
try {
rangeMax.next();
Fail.fail("Exception expected!");
} catch (final NoSuchElementException e) {
Assertions.assertThat(e).isNotNull();
}
final DelegateTableIterator<String, FDate, Integer> range2 = rangeTable.range(HASHKEY, twoDate);
Assertions.assertThat(range2.next().getValue()).isEqualTo(2);
Assertions.assertThat(range2.next().getValue()).isEqualTo(3);
Assertions.assertThat(range2.hasNext()).isFalse();
try {
range2.next();
Fail.fail("Exception expected!");
} catch (final NoSuchElementException e) {
Assertions.assertThat(e).isNotNull();
}
testReverse(rangeTable, oneDate, twoDate, threeDate);
testGetLatestForRange(rangeTable, oneDate, twoDate, threeDate);
rangeTable.deleteTable();
}
Aggregations