Search in sources :

Example 51 with FDate

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 + "]");
    }
}
Also used : FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 52 with FDate

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);
}
Also used : ArrayList(java.util.ArrayList) FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 53 with FDate

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);
}
Also used : FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 54 with FDate

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);
}
Also used : FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 55 with FDate

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);
}
Also used : FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Aggregations

FDate (de.invesdwin.util.time.date.FDate)1046 Test (org.junit.jupiter.api.Test)942 ATest (de.invesdwin.context.test.ATest)921 ArrayList (java.util.ArrayList)255 IEvaluateGenericFDate (de.invesdwin.util.math.expression.lambda.IEvaluateGenericFDate)97 Instant (de.invesdwin.util.time.Instant)78 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)63 APushingHistoricalCacheAdjustKeyProvider (de.invesdwin.util.collections.loadingcache.historical.key.APushingHistoricalCacheAdjustKeyProvider)54 HashSet (java.util.HashSet)36 NoSuchElementException (java.util.NoSuchElementException)34 TimeRange (de.invesdwin.util.time.range.TimeRange)27 File (java.io.File)26 ICloseableIterable (de.invesdwin.util.collections.iterable.ICloseableIterable)20 List (java.util.List)20 Pair (de.invesdwin.util.bean.tuple.Pair)18 APullingHistoricalCacheAdjustKeyProvider (de.invesdwin.util.collections.loadingcache.historical.key.APullingHistoricalCacheAdjustKeyProvider)18 Collection (java.util.Collection)18 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)15 Duration (de.invesdwin.util.time.duration.Duration)13