use of de.invesdwin.context.persistence.ezdb.table.range.ADelegateRangeTable in project invesdwin-context-persistence by subes.
the class RangeTableDBPerformanceTest method testLevelDbPerformance.
@Test
public void testLevelDbPerformance() throws InterruptedException {
final ADelegateRangeTable<String, FDate, FDate> table = new ADelegateRangeTable<String, FDate, FDate>("testLevelDbPerformance") {
@Override
protected File getBaseDirectory() {
return ContextProperties.TEMP_DIRECTORY;
}
@Override
protected ISerde<FDate> newValueSerde() {
return FDateSerde.GET;
}
@Override
protected ISerde<FDate> newRangeKeySerde() {
return FDateSerde.GET;
}
};
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
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) {
try {
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
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);
readIterator(table);
readGet(table);
readGetLatest(table);
}
use of de.invesdwin.context.persistence.ezdb.table.range.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 ISerde<FDate> newRangeKeySerde() {
return FDateSerde.GET;
}
@Override
protected boolean allowHasNext() {
return true;
}
@Override
protected File getBaseDirectory() {
return ContextProperties.TEMP_DIRECTORY;
}
};
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 DelegateRangeTableIterator<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 DelegateRangeTableIterator<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 DelegateRangeTableIterator<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 DelegateRangeTableIterator<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 DelegateRangeTableIterator<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