use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest method testPreviousKeyBeforeFirstReverse.
@Test
public void testPreviousKeyBeforeFirstReverse() {
FDate previousKey = cache.query().setFutureNullEnabled().getPreviousKey(FDate.MIN_DATE, entities.size());
Assertions.assertThat(previousKey).isEqualTo(FDate.MIN_DATE);
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(1);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(3);
previousKey = cache.query().setFutureEnabled().getPreviousKey(FDate.MIN_DATE, entities.size());
Assertions.assertThat(previousKey).isEqualTo(FDate.MIN_DATE);
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(1);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(4);
previousKey = cache.query().setFutureNullEnabled().getPreviousKey(FDate.MIN_DATE, entities.size());
Assertions.assertThat(previousKey).isEqualTo(FDate.MIN_DATE);
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(1);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(4);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest 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);
// random order
for (final FDate entity : new HashSet<FDate>(entities)) {
Assertions.assertThat(cache.query().getValue(entity.addDays(2))).isNotNull();
}
Assertions.assertThat(countReadAllValuesAscendingFrom).isEqualTo(21);
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(33);
Assertions.assertThat(countReadNewestValueTo).isEqualTo(11);
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest method testGetPreviousAndNextWithTable.
@Test
public void testGetPreviousAndNextWithTable() {
for (int i = 0; i < entities.size(); i++) {
final FDate value = table.getPreviousValue(KEY, 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 = table.getPreviousValue(KEY, 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 = table.getPreviousValue(KEY, FDate.MIN_DATE, i);
final FDate expectedValue = entities.get(0);
Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
}
for (int i = 0; i < entities.size(); i++) {
final FDate value = table.getNextValue(KEY, 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 = table.getNextValue(KEY, 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 = table.getNextValue(KEY, FDate.MAX_DATE, i);
final FDate expectedValue = entities.get(entities.size() - 1);
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 setUp.
@Override
public void setUp() throws Exception {
super.setUp();
final AHistoricalCache<TimeRange> segmentFinder = PeriodicalSegmentFinder.newCache(new Duration(2, FTimeUnit.YEARS), false);
table = new ALiveSegmentedTimeSeriesDB<String, FDate>(getClass().getSimpleName()) {
private FDate curTime = null;
@Override
public AHistoricalCache<TimeRange> getSegmentFinder(final String key) {
return segmentFinder;
}
@Override
protected ISerde<FDate> newValueSerde() {
return new TypeDelegateSerde<FDate>(FDate.class);
}
@Override
protected Integer newValueFixedLength() {
return null;
}
@Override
protected String innerHashKeyToString(final String key) {
return key;
}
@Override
protected File getBaseDirectory() {
return ContextProperties.TEMP_DIRECTORY;
}
@Override
protected ICloseableIterable<? extends FDate> downloadSegmentElements(final SegmentedKey<String> segmentedKey) {
return new ASkippingIterable<FDate>(WrapperCloseableIterable.maybeWrap(entities)) {
private final FDate from = segmentedKey.getSegment().getFrom();
private final FDate to = segmentedKey.getSegment().getTo();
@Override
protected boolean skip(final FDate element) {
return element.isBefore(from) || element.isAfter(to);
}
};
}
@Override
protected FDate extractEndTime(final FDate value) {
return value;
}
@Override
public FDate getFirstAvailableHistoricalSegmentFrom(final String key) {
if (entities.isEmpty() || curTime == null) {
return null;
}
final FDate firstTime = FDates.min(curTime, entities.get(0));
final TimeRange firstSegment = segmentFinder.query().getValue(firstTime);
if (firstSegment.getTo().isBeforeOrEqualTo(curTime)) {
return firstSegment.getFrom();
} else {
return segmentFinder.query().getValue(firstSegment.getFrom().addMilliseconds(-1)).getFrom();
}
}
@Override
public FDate getLastAvailableHistoricalSegmentTo(final String key, final FDate updateTo) {
if (entities.isEmpty() || curTime == null) {
return null;
}
final TimeRange lastSegment = segmentFinder.query().getValue(curTime);
if (lastSegment.getTo().isBeforeOrEqualTo(curTime)) {
return lastSegment.getTo();
} else {
return segmentFinder.query().getValue(lastSegment.getFrom().addMilliseconds(-1)).getTo();
}
}
@Override
public void putNextLiveValue(final String key, final FDate nextLiveValue) {
curTime = nextLiveValue;
super.putNextLiveValue(key, nextLiveValue);
}
@Override
protected String getElementsName() {
return "values";
}
};
for (final FDate entity : entities) {
table.putNextLiveValue(KEY, entity);
}
}
use of de.invesdwin.util.time.date.FDate in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithNoCacheTest 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(newEntity);
HistoricalCacheRefreshManager.forceRefresh();
final FDate correctValue = cache.query().getValue(newEntity);
Assertions.assertThat(correctValue).isEqualTo(newEntity);
}
Aggregations