use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.
the class ATimeSeriesDBWithCacheTest 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);
}
}
}
use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithUnlimitedCacheTest 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);
}
}
}
use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.
the class ATimeSeriesDBWithLimitedCacheTest 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);
}
}
}
use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.
the class ATimeSeriesDBWithUnlimitedCacheTest 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);
}
}
}
use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.
the class ALiveSegmentedTimeSeriesDBWithCacheTest 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);
}
}
}
Aggregations