use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithCacheTest method testNewEntityIncomingPullingAdjustKeyProvider.
@Test
public void testNewEntityIncomingPullingAdjustKeyProvider() throws IncompleteUpdateFoundException {
cache.setAdjustKeyProvider(new APullingHistoricalCacheAdjustKeyProvider(cache) {
@Override
protected FDate innerGetHighestAllowedKey() {
return entities.get(entities.size() - 1);
}
@Override
protected boolean isPullingRecursive() {
return false;
}
});
final List<FDate> newEntities = new ArrayList<FDate>(entities);
final FDate newEntity = FDateBuilder.newDate(1996, 1, 1);
newEntities.add(newEntity);
for (final FDate entity : newEntities) {
final FDate value = cache.query().getValue(entity);
if (newEntity.equals(entity)) {
Assertions.assertThat(value).isNotEqualTo(newEntity);
Assertions.assertThat(value).isEqualTo(entities.get(entities.size() - 1));
} else {
Assertions.assertThat(value).isEqualTo(entity);
}
}
entities.add(newEntity);
table.putNextLiveValue(KEY, newEntity);
final FDate correctValue = cache.query().getValue(newEntity);
Assertions.assertThat(correctValue).isEqualTo(newEntity);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithCacheTest method testInverseOrderWithReturnMaxResults.
@Test
public void testInverseOrderWithReturnMaxResults() {
returnMaxResults = testReturnMaxResultsValue;
final List<FDate> ents = new ArrayList<FDate>(entities);
Collections.reverse(ents);
for (final FDate entity : ents) {
Assertions.assertThat(cache.query().getValue(entity)).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(4);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testGapsWithReturnMaxResults.
@Test
public void testGapsWithReturnMaxResults() {
returnMaxResults = testReturnMaxResultsValue;
// once through the complete list
final List<FDate> liste = new ArrayList<FDate>();
for (final FDate entity : entities) {
final FDate cachedEntity = cache.query().getValue(entity);
liste.add(cachedEntity);
Assertions.assertThat(cachedEntity).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(3);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
Assertions.assertThat(liste).isEqualTo(entities);
// new maxKey without new db results
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(5))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(9);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
// new minKey without new db limit
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().setFutureEnabled().getValue(entity.addYears(-5))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(10);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(7);
// again in the same limit
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(15);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(7);
// simulate cache eviction
cache.clear();
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
cache.clear();
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(27);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(11);
// random order
for (final FDate entity : new HashSet<FDate>(entities)) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isLessThanOrEqualTo(37);
Assertions.assertThat(countReadNewestValueTo).isLessThanOrEqualTo(27);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testNextValuesGetsFilledUpWithoutDistance.
@Test
public void testNextValuesGetsFilledUpWithoutDistance() {
final Collection<FDate> nextValues = asList(cache.query().setFutureEnabled().getNextValues(entities.get(entities.size() - 1), entities.size()));
Assertions.assertThat(nextValues.size()).isEqualTo(1);
for (final FDate d : nextValues) {
Assertions.assertThat(d).isEqualTo(entities.get(entities.size() - 1));
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(0);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testGaps.
@Test
public void testGaps() {
// once through the complete list
final List<FDate> liste = new ArrayList<FDate>();
for (final FDate entity : entities) {
final FDate cachedEntity = cache.query().getValue(entity);
liste.add(cachedEntity);
Assertions.assertThat(cachedEntity).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(1);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
Assertions.assertThat(liste).isEqualTo(entities);
// new maxKey without new db results
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(5))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(3);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
// new minKey without new db limit
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().setFutureEnabled().getValue(entity.addYears(-5))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(4);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(7);
// again in the same limit
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(5);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(7);
// simulate cache eviction
cache.clear();
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
cache.clear();
for (final FDate entity : entities) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(9);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(11);
// random order
for (final FDate entity : new HashSet<FDate>(entities)) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isLessThanOrEqualTo(14);
Assertions.assertThat(countReadNewestValueTo).isLessThanOrEqualTo(19);
}
Aggregations