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();
}
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();
}
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();
}
Aggregations