use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testGetPreviousAndNextValue.
@Test
public void testGetPreviousAndNextValue() {
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().getPreviousValue(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().getPreviousValue(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().getPreviousValue(FDate.MIN_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 + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = cache.query().setFutureEnabled().getNextValue(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().getNextValue(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().getNextValue(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 testNewEntityIncomingAfterClear.
@Test
public void testNewEntityIncomingAfterClear() throws IncompleteUpdateFoundException {
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 wrongValue = cache.query().getValue(newEntity);
Assertions.assertThat(wrongValue).isEqualTo(entities.get(entities.size() - 2));
HistoricalCacheRefreshManager.forceRefresh();
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 testNextKeyWithAllValues.
@Test
public void testNextKeyWithAllValues() {
returnAllInReadAllValuesAscendingFrom = true;
FDate nextKey = cache.query().setFutureEnabled().getNextKey(FDate.MIN_DATE, entities.size());
Assertions.assertThat(nextKey).isEqualTo(entities.get(entities.size() - 1));
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(1);
// loading newest entity is faster than always loading all entities
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
nextKey = cache.query().setFutureEnabled().getNextKey(FDate.MIN_DATE, 1);
Assertions.assertThat(nextKey).isEqualTo(entities.get(1));
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(2);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(3);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithLimitedCacheTest method testPreviousValuesGetsFilledDownWithoutDistance.
@Test
public void testPreviousValuesGetsFilledDownWithoutDistance() {
final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(entities.get(0), entities.size()));
Assertions.assertThat(previousValues.size()).isEqualTo(1);
for (final FDate d : previousValues) {
Assertions.assertThat(d).isEqualTo(entities.get(0));
}
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 testPreviousValueWithQueryCacheWithIncrementingAlwaysOneValue.
@Test
public void testPreviousValueWithQueryCacheWithIncrementingAlwaysOneValue() {
for (int index = 1; index < entities.size(); index++) {
final FDate previousValue = cache.query().getPreviousValue(entities.get(index), 1);
final FDate expectedValue = entities.get(index - 1);
Assertions.assertThat(previousValue).isEqualTo(expectedValue);
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(2);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(2);
Assertions.assertThat(countInnerExtractKey).isEqualTo(2);
Assertions.assertThat(countAdjustKey).isEqualTo(0);
}
Aggregations