use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testNewEntityIncomingPushingAdjustKeyProviderWithoutInitialPush.
@Test
public void testNewEntityIncomingPushingAdjustKeyProviderWithoutInitialPush() throws IncompleteUpdateFoundException {
final APushingHistoricalCacheAdjustKeyProvider adjustKeyProvider = new APushingHistoricalCacheAdjustKeyProvider(cache) {
@Override
protected FDate getInitialHighestAllowedKey() {
return null;
}
@Override
protected boolean isPullingRecursive() {
return false;
}
};
cache.setAdjustKeyProvider(adjustKeyProvider);
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);
}
}
adjustKeyProvider.pushHighestAllowedKey(newEntity);
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 ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testGetPreviousAndNextKey.
@Test
public void testGetPreviousAndNextKey() {
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().getPreviousKey(entities.get(entities.size() - 1), i);
final FDate expectedValue = entities.get(entities.size() - i - 1);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().getPreviousKey(FDate.MAX_DATE, i);
final FDate expectedValue = entities.get(entities.size() - i - 1);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().setFutureEnabled().getPreviousKey(FDate.MIN_DATE, i);
// filtering query removes the result because it is not a previous result
final FDate expectedValue = FDate.MIN_DATE;
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().setFutureEnabled().getNextKey(entities.get(0), i);
final FDate expectedValue = entities.get(i);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().setFutureEnabled().getNextKey(FDate.MIN_DATE, i);
final FDate expectedValue = entities.get(i);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().setFutureEnabled().getNextKey(FDate.MAX_DATE, i);
// filtering query removes the result because it is not a previous result
final FDate expectedValue = null;
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testSubListWhenSwitchingFromNonFilterToFilter.
@Test
public void testSubListWhenSwitchingFromNonFilterToFilter() {
final FDate key = new FDate();
final FDate previousValue = cache.query().getPreviousValue(key, 4);
final FDate expectedValue = entities.get(entities.size() - 5);
Assertions.assertThat(previousValue).isEqualTo(expectedValue);
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(4);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
Assertions.assertThat(countInnerExtractKey).isEqualTo(4);
Assertions.assertThat(countAdjustKey).isEqualTo(0);
final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, 4));
final List<FDate> expectedValues = entities.subList(2, 6);
Assertions.assertThat(previousValues).isEqualTo(expectedValues);
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(4);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
Assertions.assertThat(countInnerExtractKey).isEqualTo(4);
Assertions.assertThat(countAdjustKey).isEqualTo(0);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest method testPreviousKey.
@Test
public void testPreviousKey() {
FDate previousKey = cache.query().getPreviousKey(new FDate(), entities.size());
Assertions.assertThat(previousKey).isEqualTo(entities.get(0));
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(6);
// loading newest entity is faster than always loading all entities
Assertions.assertThat(countReadNewestValueTo).isEqualTo(3);
previousKey = cache.query().getPreviousKey(new FDate(), 1);
Assertions.assertThat(previousKey).isEqualTo(entities.get(entities.size() - 2));
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(7);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(4);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest method testPreviousKeyWithAllValuesAndNullInReadNewestValueTo.
@Test
public void testPreviousKeyWithAllValuesAndNullInReadNewestValueTo() {
returnAllInReadAllValuesAscendingFrom = true;
returnNullInReadNewestValueTo = true;
FDate previousKey = cache.query().getPreviousKey(new FDate(), entities.size());
Assertions.assertThat(previousKey).isEqualTo(entities.get(0));
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(4);
// loading newest entity is faster than always loading all entities
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
previousKey = cache.query().getPreviousKey(new FDate(), 1);
Assertions.assertThat(previousKey).isEqualTo(entities.get(entities.size() - 2));
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(5);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
}
Aggregations