Search in sources :

Example 1 with ALiveSegmentedTimeSeriesDB

use of de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB in project invesdwin-context-persistence by subes.

the class FileLiveSegmentTest method testInverseOrder.

@Test
public void testInverseOrder() {
    final Map<Integer, FDate> extractTime = new HashMap<>();
    final SegmentedKey<FDate> segmentedKey = new SegmentedKey<FDate>(FDate.MIN_DATE, new TimeRange(FDate.MIN_DATE, FDate.MAX_DATE));
    final ALiveSegmentedTimeSeriesDB<FDate, Integer> timeSeriesDB = new ALiveSegmentedTimeSeriesDB<FDate, Integer>("testInverseOrder") {

        @Override
        protected File getBaseDirectory() {
            return ContextProperties.getCacheDirectory();
        }

        @Override
        protected ICloseableIterable<? extends Integer> downloadSegmentElements(final SegmentedKey<FDate> segmentedKey) {
            throw new UnsupportedOperationException();
        }

        @Override
        public AHistoricalCache<TimeRange> getSegmentFinder(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected Integer newValueFixedLength() {
            return null;
        }

        @Override
        protected ISerde<Integer> newValueSerde() {
            return IntegerSerde.GET;
        }

        @Override
        protected FDate extractEndTime(final Integer value) {
            return extractTime.get(value);
        }

        @Override
        protected String innerHashKeyToString(final FDate key) {
            return key.toString(FDate.FORMAT_UNDERSCORE_DATE_TIME_MS);
        }

        @Override
        public FDate getFirstAvailableHistoricalSegmentFrom(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        public FDate getLastAvailableHistoricalSegmentTo(final FDate key, final FDate updateTo) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected String getElementsName() {
            throw new UnsupportedOperationException();
        }
    };
    @SuppressWarnings("unchecked") final ALiveSegmentedTimeSeriesDB<FDate, Integer>.HistoricalSegmentTable historicalSegmentTable = Reflections.field("historicalSegmentTable").ofType(HistoricalSegmentTable.class).in(timeSeriesDB).get();
    final FileLiveSegment<FDate, Integer> rangeTable = new FileLiveSegment<FDate, Integer>(segmentedKey, historicalSegmentTable);
    final FDate now = FDateBuilder.newDate(2000);
    final FDate oneDate = now.addDays(1);
    final FDate twoDate = now.addDays(2);
    final FDate threeDate = now.addDays(3);
    rangeTable.putNextLiveValue(oneDate, 1);
    extractTime.put(1, oneDate);
    rangeTable.putNextLiveValue(twoDate, 2);
    extractTime.put(2, twoDate);
    rangeTable.putNextLiveValue(threeDate, 3);
    extractTime.put(3, threeDate);
    final ICloseableIterator<Integer> range3 = rangeTable.rangeValues(now, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(range3.next()).isEqualTo(1);
    Assertions.assertThat(range3.next()).isEqualTo(2);
    Assertions.assertThat(range3.next()).isEqualTo(3);
    Assertions.assertThat(range3.hasNext()).isFalse();
    try {
        range3.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    // should already be closed but should not cause an error when calling again
    range3.close();
    final ICloseableIterator<Integer> rangeNone = rangeTable.rangeValues(null, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeNone.next()).isEqualTo(1);
    Assertions.assertThat(rangeNone.next()).isEqualTo(2);
    Assertions.assertThat(rangeNone.next()).isEqualTo(3);
    Assertions.assertThat(rangeNone.hasNext()).isFalse();
    try {
        rangeNone.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> rangeMin = rangeTable.rangeValues(FDate.MIN_DATE, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeMin.next()).isEqualTo(1);
    Assertions.assertThat(rangeMin.next()).isEqualTo(2);
    Assertions.assertThat(rangeMin.next()).isEqualTo(3);
    Assertions.assertThat(rangeMin.hasNext()).isFalse();
    try {
        rangeMin.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> rangeMax = rangeTable.rangeValues(FDate.MAX_DATE, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeMax.hasNext()).isFalse();
    try {
        rangeMax.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> range2 = rangeTable.rangeValues(twoDate, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(range2.next()).isEqualTo(2);
    Assertions.assertThat(range2.next()).isEqualTo(3);
    Assertions.assertThat(range2.hasNext()).isFalse();
    try {
        range2.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    testReverse(rangeTable, oneDate, twoDate, threeDate);
    testGetLatestForRange(rangeTable, oneDate, twoDate, threeDate);
    rangeTable.close();
}
Also used : ALiveSegmentedTimeSeriesDB(de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB) HashMap(java.util.HashMap) FDate(de.invesdwin.util.time.date.FDate) TimeRange(de.invesdwin.util.time.range.TimeRange) SegmentedKey(de.invesdwin.context.persistence.timeseriesdb.segmented.SegmentedKey) NoSuchElementException(java.util.NoSuchElementException) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 2 with ALiveSegmentedTimeSeriesDB

use of de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB in project invesdwin-context-persistence by subes.

the class RangeTableLiveSegmentTest method testInverseOrder.

@Test
public void testInverseOrder() {
    final Map<Integer, FDate> extractTime = new HashMap<>();
    final SegmentedKey<FDate> segmentedKey = new SegmentedKey<FDate>(FDate.MIN_DATE, new TimeRange(FDate.MIN_DATE, FDate.MAX_DATE));
    final ALiveSegmentedTimeSeriesDB<FDate, Integer> timeSeriesDB = new ALiveSegmentedTimeSeriesDB<FDate, Integer>("testInverseOrder") {

        @Override
        protected File getBaseDirectory() {
            return ContextProperties.getCacheDirectory();
        }

        @Override
        protected ICloseableIterable<? extends Integer> downloadSegmentElements(final SegmentedKey<FDate> segmentedKey) {
            throw new UnsupportedOperationException();
        }

        @Override
        public AHistoricalCache<TimeRange> getSegmentFinder(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected Integer newValueFixedLength() {
            return null;
        }

        @Override
        protected ISerde<Integer> newValueSerde() {
            return IntegerSerde.GET;
        }

        @Override
        protected FDate extractEndTime(final Integer value) {
            return extractTime.get(value);
        }

        @Override
        protected String innerHashKeyToString(final FDate key) {
            return key.toString(FDate.FORMAT_UNDERSCORE_DATE_TIME_MS);
        }

        @Override
        public FDate getFirstAvailableHistoricalSegmentFrom(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        public FDate getLastAvailableHistoricalSegmentTo(final FDate key, final FDate updateTo) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected String getElementsName() {
            throw new UnsupportedOperationException();
        }
    };
    @SuppressWarnings("unchecked") final ALiveSegmentedTimeSeriesDB<FDate, Integer>.HistoricalSegmentTable historicalSegmentTable = Reflections.field("historicalSegmentTable").ofType(HistoricalSegmentTable.class).in(timeSeriesDB).get();
    final RangeTableLiveSegment<FDate, Integer> rangeTable = new RangeTableLiveSegment<FDate, Integer>(segmentedKey, historicalSegmentTable);
    final FDate now = FDateBuilder.newDate(2000);
    final FDate oneDate = now.addDays(1);
    final FDate twoDate = now.addDays(2);
    final FDate threeDate = now.addDays(3);
    rangeTable.putNextLiveValue(oneDate, 1);
    extractTime.put(1, oneDate);
    rangeTable.putNextLiveValue(twoDate, 2);
    extractTime.put(2, twoDate);
    rangeTable.putNextLiveValue(threeDate, 3);
    extractTime.put(3, threeDate);
    final ICloseableIterator<Integer> range3 = rangeTable.rangeValues(now, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(range3.next()).isEqualTo(1);
    Assertions.assertThat(range3.next()).isEqualTo(2);
    Assertions.assertThat(range3.next()).isEqualTo(3);
    Assertions.assertThat(range3.hasNext()).isFalse();
    try {
        range3.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    // should already be closed but should not cause an error when calling again
    range3.close();
    final ICloseableIterator<Integer> rangeNone = rangeTable.rangeValues(null, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeNone.next()).isEqualTo(1);
    Assertions.assertThat(rangeNone.next()).isEqualTo(2);
    Assertions.assertThat(rangeNone.next()).isEqualTo(3);
    Assertions.assertThat(rangeNone.hasNext()).isFalse();
    try {
        rangeNone.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> rangeMin = rangeTable.rangeValues(FDate.MIN_DATE, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeMin.next()).isEqualTo(1);
    Assertions.assertThat(rangeMin.next()).isEqualTo(2);
    Assertions.assertThat(rangeMin.next()).isEqualTo(3);
    Assertions.assertThat(rangeMin.hasNext()).isFalse();
    try {
        rangeMin.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> rangeMax = rangeTable.rangeValues(FDate.MAX_DATE, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeMax.hasNext()).isFalse();
    try {
        rangeMax.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> range2 = rangeTable.rangeValues(twoDate, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(range2.next()).isEqualTo(2);
    Assertions.assertThat(range2.next()).isEqualTo(3);
    Assertions.assertThat(range2.hasNext()).isFalse();
    try {
        range2.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    testReverse(rangeTable, oneDate, twoDate, threeDate);
    testGetLatestForRange(rangeTable, oneDate, twoDate, threeDate);
    rangeTable.close();
}
Also used : ALiveSegmentedTimeSeriesDB(de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB) HashMap(java.util.HashMap) FDate(de.invesdwin.util.time.date.FDate) TimeRange(de.invesdwin.util.time.range.TimeRange) SegmentedKey(de.invesdwin.context.persistence.timeseriesdb.segmented.SegmentedKey) NoSuchElementException(java.util.NoSuchElementException) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 3 with ALiveSegmentedTimeSeriesDB

use of de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB in project invesdwin-context-persistence by subes.

the class HeapLiveSegmentTest method testInverseOrder.

@Test
public void testInverseOrder() {
    final Map<Integer, FDate> extractTime = new HashMap<>();
    final SegmentedKey<FDate> segmentedKey = new SegmentedKey<FDate>(FDate.MIN_DATE, new TimeRange(FDate.MIN_DATE, FDate.MAX_DATE));
    final ALiveSegmentedTimeSeriesDB<FDate, Integer> timeSeriesDB = new ALiveSegmentedTimeSeriesDB<FDate, Integer>("testInverseOrder") {

        @Override
        protected File getBaseDirectory() {
            return ContextProperties.getCacheDirectory();
        }

        @Override
        protected ICloseableIterable<? extends Integer> downloadSegmentElements(final SegmentedKey<FDate> segmentedKey) {
            throw new UnsupportedOperationException();
        }

        @Override
        public AHistoricalCache<TimeRange> getSegmentFinder(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected Integer newValueFixedLength() {
            return null;
        }

        @Override
        protected ISerde<Integer> newValueSerde() {
            return IntegerSerde.GET;
        }

        @Override
        protected FDate extractEndTime(final Integer value) {
            return extractTime.get(value);
        }

        @Override
        protected String innerHashKeyToString(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        public FDate getFirstAvailableHistoricalSegmentFrom(final FDate key) {
            throw new UnsupportedOperationException();
        }

        @Override
        public FDate getLastAvailableHistoricalSegmentTo(final FDate key, final FDate updateTo) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected String getElementsName() {
            throw new UnsupportedOperationException();
        }
    };
    @SuppressWarnings("unchecked") final ALiveSegmentedTimeSeriesDB<FDate, Integer>.HistoricalSegmentTable historicalSegmentTable = Reflections.field("historicalSegmentTable").ofType(HistoricalSegmentTable.class).in(timeSeriesDB).get();
    final HeapLiveSegment<FDate, Integer> rangeTable = new HeapLiveSegment<FDate, Integer>(segmentedKey, historicalSegmentTable);
    final FDate now = FDateBuilder.newDate(2000);
    final FDate oneDate = now.addDays(1);
    final FDate twoDate = now.addDays(2);
    final FDate threeDate = now.addDays(3);
    rangeTable.putNextLiveValue(oneDate, 1);
    extractTime.put(1, oneDate);
    rangeTable.putNextLiveValue(twoDate, 2);
    extractTime.put(2, twoDate);
    rangeTable.putNextLiveValue(threeDate, 3);
    extractTime.put(3, threeDate);
    final ICloseableIterator<Integer> range3 = rangeTable.rangeValues(now, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(range3.next()).isEqualTo(1);
    Assertions.assertThat(range3.next()).isEqualTo(2);
    Assertions.assertThat(range3.next()).isEqualTo(3);
    Assertions.assertThat(range3.hasNext()).isFalse();
    try {
        range3.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    // should already be closed but should not cause an error when calling again
    range3.close();
    final ICloseableIterator<Integer> rangeNone = rangeTable.rangeValues(null, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeNone.next()).isEqualTo(1);
    Assertions.assertThat(rangeNone.next()).isEqualTo(2);
    Assertions.assertThat(rangeNone.next()).isEqualTo(3);
    Assertions.assertThat(rangeNone.hasNext()).isFalse();
    try {
        rangeNone.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> rangeMin = rangeTable.rangeValues(FDate.MIN_DATE, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeMin.next()).isEqualTo(1);
    Assertions.assertThat(rangeMin.next()).isEqualTo(2);
    Assertions.assertThat(rangeMin.next()).isEqualTo(3);
    Assertions.assertThat(rangeMin.hasNext()).isFalse();
    try {
        rangeMin.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> rangeMax = rangeTable.rangeValues(FDate.MAX_DATE, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(rangeMax.hasNext()).isFalse();
    try {
        rangeMax.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    final ICloseableIterator<Integer> range2 = rangeTable.rangeValues(twoDate, null, DisabledLock.INSTANCE, null).iterator();
    Assertions.assertThat(range2.next()).isEqualTo(2);
    Assertions.assertThat(range2.next()).isEqualTo(3);
    Assertions.assertThat(range2.hasNext()).isFalse();
    try {
        range2.next();
        Fail.fail("Exception expected!");
    } catch (final NoSuchElementException e) {
        Assertions.assertThat(e).isNotNull();
    }
    testReverse(rangeTable, oneDate, twoDate, threeDate);
    testGetLatestForRange(rangeTable, oneDate, twoDate, threeDate);
    rangeTable.close();
}
Also used : ALiveSegmentedTimeSeriesDB(de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB) HashMap(java.util.HashMap) FDate(de.invesdwin.util.time.date.FDate) TimeRange(de.invesdwin.util.time.range.TimeRange) SegmentedKey(de.invesdwin.context.persistence.timeseriesdb.segmented.SegmentedKey) NoSuchElementException(java.util.NoSuchElementException) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Aggregations

SegmentedKey (de.invesdwin.context.persistence.timeseriesdb.segmented.SegmentedKey)3 ALiveSegmentedTimeSeriesDB (de.invesdwin.context.persistence.timeseriesdb.segmented.live.ALiveSegmentedTimeSeriesDB)3 ATest (de.invesdwin.context.test.ATest)3 FDate (de.invesdwin.util.time.date.FDate)3 TimeRange (de.invesdwin.util.time.range.TimeRange)3 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)3 Test (org.junit.jupiter.api.Test)3