Search in sources :

Example 31 with FDate

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

Example 32 with FDate

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

Example 33 with FDate

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

Example 34 with FDate

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

Example 35 with FDate

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);
}
Also used : ArrayList(java.util.ArrayList) FDate(de.invesdwin.util.time.date.FDate) HashSet(java.util.HashSet) 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