Search in sources :

Example 66 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testNoStartBookendOrderByIdLimit.

public void testNoStartBookendOrderByIdLimit() {
    MutableInt count1 = new MutableInt();
    MutableInt count2 = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp1 = new MutableLong(startTs);
    MutableLong timestamp2 = new MutableLong(startTs);
    this.dao.wideBookendQuery(ids, startTs, endTs, true, 20, new BookendQueryCallback<IdPointValueTime>() {

        int seriesIdCounter = 0;

        int seriesId2Counter = 3;

        @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());
                Assert.assertEquals(data.get(seriesId2).get(seriesId2Counter++).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(startTs, value.getTime());
                Assert.assertEquals(false, bookend);
                count1.increment();
            } 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.assertEquals(data.get(seriesId).get(seriesIdCounter++).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(startTs, value.getTime());
                Assert.assertEquals(false, bookend);
                count2.increment();
            }
        }

        @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
                Assert.assertEquals(true, bookend);
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(--seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(endTs, value.getTime());
                count1.increment();
            } else {
                if (value.getTime() < timestamp1.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp1.setValue(value.getTime());
                Assert.assertEquals(true, bookend);
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(--seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(endTs, value.getTime());
                count2.increment();
            }
        }
    });
    Assert.assertEquals(new Integer(21), count1.getValue());
    Assert.assertEquals(new Integer(21), count2.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 67 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testLatestMultiplePointValuesLimitOffsetSeries.

public void testLatestMultiplePointValuesLimitOffsetSeries() {
    MutableInt count = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp = new MutableLong(series2EndTs + 1);
    this.dao.getLatestPointValues(ids, series2EndTs + 1, false, 20, 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--;
            }
        }
    });
    Assert.assertEquals(new Integer(20), count.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 68 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testBookendExceptionInLastValueCallback.

public void testBookendExceptionInLastValueCallback() {
    MutableInt count = new MutableInt();
    MutableInt lastValueCallCount = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp = new MutableLong(startTs - 1);
    this.dao.wideBookendQuery(ids, startTs - 1, endTs, false, null, new BookendQueryCallback<IdPointValueTime>() {

        int seriesIdCounter = 0;

        // Skip first 3
        int seriesId2Counter = 3;

        @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
                Assert.assertEquals(data.get(value.getId()).get(2).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(startTs - 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(startTs - 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 {
            lastValueCallCount.increment();
            Assert.assertEquals(mutableIndex.intValue(), index);
            mutableIndex.increment();
            if (value.getTime() < timestamp.getValue())
                Assert.fail("Timestamp out of order.");
            timestamp.setValue(value.getTime());
            throw new IOException("Last Value Callback Exception");
        }
    });
    // Since the exception is thrown in last value all the true values should have been sent out already
    Assert.assertEquals(new Integer(totalSampleCount * 2), count.getValue());
    // Ensure that last value is only called once due to the exception
    Assert.assertEquals(new Integer(1), lastValueCallCount.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 69 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testBookendMultiplePointValuesOrderByIdNoLimit.

public void testBookendMultiplePointValuesOrderByIdNoLimit() {
    MutableInt count = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp1 = new MutableLong(startTs - 1);
    MutableLong timestamp2 = new MutableLong(startTs - 1);
    this.dao.wideBookendQuery(ids, startTs - 1, endTs, true, null, new BookendQueryCallback<IdPointValueTime>() {

        int seriesIdCounter = 0;

        // Skip first 3
        int seriesId2Counter = 3;

        @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());
                // This has a value before the startTs
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(2).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(startTs - 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(startTs - 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 (index < data.get(seriesId).size() + 1) {
                // 1 for end bookend
                // 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());
                // 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());
                // 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
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(totalSampleCount + 2).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(endTs, value.getTime());
                Assert.assertEquals(true, bookend);
            } else {
                if (value.getTime() < timestamp1.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp1.setValue(value.getTime());
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(totalSampleCount - 1).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(endTs, value.getTime());
                Assert.assertEquals(true, bookend);
            }
        }
    });
    Assert.assertEquals(new Integer(totalSampleCount * 2), count.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 70 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testNoStartBookendLimit.

public void testNoStartBookendLimit() {
    MutableInt count1 = new MutableInt();
    MutableInt count2 = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp = new MutableLong(startTs);
    this.dao.wideBookendQuery(ids, startTs, endTs, false, 20, new BookendQueryCallback<IdPointValueTime>() {

        int seriesIdCounter = 0;

        int seriesId2Counter = 3;

        @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) {
                Assert.assertEquals(data.get(seriesId2).get(seriesId2Counter++).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(startTs, value.getTime());
                Assert.assertEquals(false, bookend);
                count1.increment();
            } else {
                // Check value is null as no data exists before the startTs for series 1
                Assert.assertEquals(data.get(seriesId).get(seriesIdCounter++).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(startTs, value.getTime());
                Assert.assertEquals(false, bookend);
                count2.increment();
            }
        }

        @Override
        public void row(IdPointValueTime value, int index) 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) {
                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 {
                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.getTime() < timestamp.getValue())
                Assert.fail("Timestamp out of order.");
            timestamp.setValue(value.getTime());
            if (value.getId() == seriesId2) {
                // This has a value before the startTs
                Assert.assertEquals(true, bookend);
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(--seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(endTs, value.getTime());
                count1.increment();
            } else {
                Assert.assertEquals(true, bookend);
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(--seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(endTs, value.getTime());
                count2.increment();
            }
        }
    });
    Assert.assertEquals(new Integer(11), count1.getValue());
    Assert.assertEquals(new Integer(11), count2.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Aggregations

IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)68 IOException (java.io.IOException)60 MutableInt (org.apache.commons.lang3.mutable.MutableInt)60 MutableLong (org.apache.commons.lang3.mutable.MutableLong)36 NextTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster)21 ZonedDateTime (java.time.ZonedDateTime)21 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)14 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)9 AnalogStatistics (com.infiniteautomation.mango.statistics.AnalogStatistics)7 StartsAndRuntime (com.infiniteautomation.mango.statistics.StartsAndRuntime)7 StartsAndRuntimeList (com.infiniteautomation.mango.statistics.StartsAndRuntimeList)7 ValueChangeCounter (com.infiniteautomation.mango.statistics.ValueChangeCounter)7 AnnotatedIdPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)6 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)2 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)2 HashMap (java.util.HashMap)2