use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.
the class NumericPointValueDaoTestHelper method testBookendMultiplePointValuesLimitOffsetSeries.
public void testBookendMultiplePointValuesLimitOffsetSeries() {
MutableInt count = new MutableInt();
MutableInt mutableIndex = new MutableInt();
MutableLong timestamp = new MutableLong(series2StartTs - 1);
this.dao.wideBookendQuery(ids, series2StartTs - 1, series2EndTs + 1, false, 20, new BookendQueryCallback<IdPointValueTime>() {
int seriesIdCounter = 0;
int seriesId2Counter = 0;
@Override
public void firstValue(IdPointValueTime value, int index, boolean bookend) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
if (value.getTime() < timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value is null as no data exists before the start Ts for series 2
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(series2StartTs - 1, value.getTime());
Assert.assertEquals(true, bookend);
} else {
// Check value is null as no data exists before the startTs for series 1
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(series2StartTs - 1, value.getTime());
Assert.assertEquals(true, bookend);
}
}
@Override
public void row(IdPointValueTime value, int index) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
count.increment();
if (value.getTime() < timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
seriesId2Counter++;
} else {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getTime(), value.getTime());
seriesIdCounter++;
}
}
@Override
public void lastValue(IdPointValueTime value, int index, boolean bookend) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
if (value.getTime() < timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// This has a value before the startTs
// Limited query bookend
Assert.assertEquals(true, bookend);
// Check value
Assert.assertEquals(data.get(value.getId()).get(--seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(series2EndTs + 1, value.getTime());
} else {
// Ensure bookend
Assert.assertEquals(true, bookend);
// Check value
Assert.assertEquals(data.get(value.getId()).get(--seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(series2EndTs + 1, value.getTime());
// Limited queries do not have bookends
}
}
});
Assert.assertEquals(new Integer(20), count.getValue());
}
use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.
the class NumericPointValueDaoTestHelper method testBookendMultiplePointValuesOrderByIdLimitOffsetSeries.
public void testBookendMultiplePointValuesOrderByIdLimitOffsetSeries() {
MutableInt count1 = new MutableInt();
MutableInt count2 = new MutableInt();
MutableInt mutableIndex = new MutableInt();
MutableLong timestamp1 = new MutableLong(series2StartTs - 1);
MutableLong timestamp2 = new MutableLong(series2StartTs - 1);
this.dao.wideBookendQuery(ids, series2StartTs - 1, series2EndTs + 1, true, 20, new BookendQueryCallback<IdPointValueTime>() {
int seriesIdCounter = 0;
int seriesId2Counter = 0;
@Override
public void firstValue(IdPointValueTime value, int index, boolean bookend) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
if (value.getId() == seriesId2) {
if (value.getTime() < timestamp2.getValue())
Assert.fail("Timestamp out of order.");
timestamp2.setValue(value.getTime());
// Check value is null as no data exists before the start Ts for series 2
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(series2StartTs - 1, value.getTime());
Assert.assertEquals(true, bookend);
} else {
if (value.getTime() < timestamp1.getValue())
Assert.fail("Timestamp out of order.");
timestamp1.setValue(value.getTime());
// Check value is null as no data exists before the startTs for series 1
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(series2StartTs - 1, value.getTime());
Assert.assertEquals(true, bookend);
}
}
@Override
public void row(IdPointValueTime value, int index) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
if (index < 20 + 1) {
// Should be first id
Assert.assertEquals((int) seriesId, value.getId());
} else {
Assert.assertEquals((int) seriesId2, value.getId());
}
if (value.getId() == seriesId2) {
if (value.getTime() < timestamp2.getValue())
Assert.fail("Timestamp out of order.");
timestamp2.setValue(value.getTime());
count2.increment();
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
seriesId2Counter++;
} else {
if (value.getTime() < timestamp1.getValue())
Assert.fail("Timestamp out of order.");
timestamp1.setValue(value.getTime());
count1.increment();
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getTime(), value.getTime());
seriesIdCounter++;
}
}
@Override
public void lastValue(IdPointValueTime value, int index, boolean bookend) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
if (value.getId() == seriesId2) {
if (value.getTime() < timestamp2.getValue())
Assert.fail("Timestamp out of order.");
timestamp2.setValue(value.getTime());
// This has a value before the startTs
// Limited but has bookend
Assert.assertEquals(true, bookend);
// Check value
Assert.assertEquals(data.get(value.getId()).get(--seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(series2EndTs + 1, value.getTime());
} else {
if (value.getTime() < timestamp1.getValue())
Assert.fail("Timestamp out of order.");
timestamp1.setValue(value.getTime());
// Limited but has bookend
Assert.assertEquals(true, bookend);
// Check value
Assert.assertEquals(data.get(value.getId()).get(--seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(series2EndTs + 1, value.getTime());
}
}
});
Assert.assertEquals(new Integer(20), count1.getValue());
Assert.assertEquals(new Integer(20), count2.getValue());
}
use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.
the class NumericPointValueDaoTestHelper method testLatestMultiplePointValuesNoLimitOffsetSeries.
/**
* Test where point 2 has more data than point 1
*/
public void testLatestMultiplePointValuesNoLimitOffsetSeries() {
MutableInt count = new MutableInt();
MutableInt mutableIndex = new MutableInt();
MutableLong timestamp = new MutableLong(series2EndTs + 1);
this.dao.getLatestPointValues(ids, series2EndTs + 1, false, null, new PVTQueryCallback<IdPointValueTime>() {
int seriesIdCounter = data.get(seriesId).size() - 1;
int seriesId2Counter = data.get(seriesId2).size() - 1;
@Override
public void row(IdPointValueTime value, int index) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
count.increment();
if (value.getTime() > timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
seriesId2Counter--;
} else {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getTime(), value.getTime());
seriesIdCounter--;
}
}
});
// Total is all samples + the extra 3 at the beginning of series2
Assert.assertEquals(new Integer(totalSampleCount * 2 + 6), count.getValue());
}
use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.
the class NumericPointValueDaoTestHelper method testBookendNoDataInOneSeries.
public void testBookendNoDataInOneSeries() {
MutableInt count = new MutableInt();
MutableInt mutableIndex = new MutableInt();
MutableLong timestamp = new MutableLong(0);
this.dao.wideBookendQuery(ids, 0, startTs, false, null, new BookendQueryCallback<IdPointValueTime>() {
int seriesId2Counter = 0;
@Override
public void firstValue(IdPointValueTime value, int index, boolean bookend) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
count.increment();
if (value.getTime() < timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value is null as no data exists before time 0
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(0, value.getTime());
Assert.assertEquals(true, bookend);
} else {
// Check value is null as no data exists before time 0
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(0, value.getTime());
Assert.assertEquals(true, bookend);
}
}
@Override
public void row(IdPointValueTime value, int index) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
count.increment();
if (value.getTime() < timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
seriesId2Counter++;
} else {
Assert.fail("Should not get data for series 1");
}
}
@Override
public void lastValue(IdPointValueTime value, int index, boolean bookend) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
count.increment();
if (value.getTime() < timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value
Assert.assertEquals(data.get(value.getId()).get(2).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(startTs, value.getTime());
Assert.assertEquals(true, bookend);
} else {
// Check value
Assert.assertNull(value.getValue());
// Check time
Assert.assertEquals(startTs, value.getTime());
Assert.assertEquals(true, bookend);
}
}
});
// Total is all samples + the extra 3 at the beginning of series2
Assert.assertEquals(new Integer(7), count.getValue());
}
use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.
the class NumericPointValueDaoTestHelper method testLatestMultiplePointValuesLimit.
public void testLatestMultiplePointValuesLimit() {
MutableInt count = new MutableInt();
MutableInt mutableIndex = new MutableInt();
MutableLong timestamp = new MutableLong(endTs);
this.dao.getLatestPointValues(ids, endTs, false, 20, new PVTQueryCallback<IdPointValueTime>() {
int seriesIdCounter = data.get(seriesId).size() - 1;
int seriesId2Counter = data.get(seriesId2).size() - 4;
@Override
public void row(IdPointValueTime value, int index) throws IOException {
Assert.assertEquals(mutableIndex.intValue(), index);
mutableIndex.increment();
count.increment();
if (value.getTime() > timestamp.getValue())
Assert.fail("Timestamp out of order.");
timestamp.setValue(value.getTime());
if (value.getId() == seriesId2) {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
seriesId2Counter--;
} else {
// Check value
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
// Check time
Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getTime(), value.getTime());
seriesIdCounter--;
}
}
});
Assert.assertEquals(new Integer(20), count.getValue());
}
Aggregations