use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest method testPreviousValueKeyBetweenReverse.
@Test
public void testPreviousValueKeyBetweenReverse() {
for (int i = entities.size() - 1; i >= 0; i--) {
final FDate entity = entities.get(i);
final FDate foundKey = cache.query().getPreviousKeyWithSameValueBetween(FDate.MIN_DATE, FDate.MAX_DATE, entity);
Assertions.assertThat(foundKey).isEqualTo(entity);
}
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest 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 ALiveSegmentedTimeSeriesDBWithNoCacheTest 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 ALiveSegmentedTimeSeriesDBWithNoCacheTest method testRandomizedPreviousValues.
@Test
public void testRandomizedPreviousValues() {
final List<Pair<Integer, Integer>> reproduce = new ArrayList<Pair<Integer, Integer>>();
try {
for (int i = 0; i < 100000; i++) {
final int keyIndex = RandomUtils.nextInt(0, entities.size());
final int shiftBackUnits = RandomUtils.nextInt(1, Math.max(1, keyIndex));
reproduce.add(Pair.of(keyIndex, shiftBackUnits));
final FDate key = entities.get(keyIndex);
final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
Assertions.assertThat(previousValues).isEqualTo(expectedValues);
if (i % 100 == 0) {
cache.clear();
reproduce.clear();
}
}
} catch (final Throwable t) {
// CHECKSTYLE:OFF
System.out.println(reproduce.size() + ". step: " + t.toString());
// CHECKSTYLE:ON
cache.clear();
for (int step = 1; step <= reproduce.size(); step++) {
final Pair<Integer, Integer> keyIndex_shiftBackUnits = reproduce.get(step - 1);
final int keyIndex = keyIndex_shiftBackUnits.getFirst();
final int shiftBackUnits = keyIndex_shiftBackUnits.getSecond();
final FDate key = entities.get(keyIndex);
final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
if (step == reproduce.size()) {
// CHECKSTYLE:OFF
System.out.println("now");
// CHECKSTYLE:ON
}
final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
Assertions.assertThat(previousValues).isEqualTo(expectedValues);
}
}
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest 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);
// random order
for (final FDate entity : new HashSet<FDate>(entities)) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(8);
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(12);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(11);
}
Aggregations