Search in sources :

Example 26 with QueryCancelledException

use of com.infiniteautomation.mango.db.query.QueryCancelledException in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testBetweenExceptionInCallback.

/* Values Between Tests */
public void testBetweenExceptionInCallback() {
    MutableInt count = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp = new MutableLong(startTs);
    try {
        this.dao.getPointValuesCombined(vos, startTs, endTs, null, TimeOrder.ASCENDING, new Consumer<>() {

            int seriesIdCounter = 0;

            // Skip first 3
            int seriesId2Counter = 3;

            @Override
            public void accept(IdPointValueTime value) {
                mutableIndex.increment();
                count.increment();
                if (value.getTime() < timestamp.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp.setValue(value.getTime());
                if (value.getSeriesId() == vo2.getSeriesId()) {
                    // Check value
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
                    // Check time
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesId2Counter).getTime(), value.getTime());
                    seriesId2Counter++;
                } else {
                    // Check value
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
                    // Check time
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesIdCounter).getTime(), value.getTime());
                    seriesIdCounter++;
                }
                if (count.getValue() == 20)
                    throw new QueryCancelledException(new Exception("Exception Test"));
            }
        });
    } catch (QueryCancelledException e) {
    // noop
    }
    Assert.assertEquals(Integer.valueOf(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) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException)

Example 27 with QueryCancelledException

use of com.infiniteautomation.mango.db.query.QueryCancelledException in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testBookendExceptionInRowCallback.

public void testBookendExceptionInRowCallback() {
    MutableInt count = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp = new MutableLong(startTs - 1);
    try {
        // Skip first 3
        // Check value
        // Check time
        // Check value is null as no data exists before the startTs for series 1
        // Check time
        // Check value
        // Check time
        // Check value
        // Check time
        this.dao.wideBookendQueryCombined(vos, startTs - 1, endTs, null, new WideCallback<IdPointValueTime>() {

            int seriesIdCounter = 0;

            // Skip first 3
            int seriesId2Counter = 3;

            @Override
            public void firstValue(IdPointValueTime value, boolean bookend) {
                mutableIndex.increment();
                if (value.getTime() < timestamp.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp.setValue(value.getTime());
                if (value.getSeriesId() == vo2.getSeriesId()) {
                    // Check value
                    Assert.assertEquals(data.get(value.getSeriesId()).get(2).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                } 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.assertTrue(bookend);
            }

            @Override
            public void accept(IdPointValueTime value) {
                mutableIndex.increment();
                count.increment();
                if (value.getTime() < timestamp.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp.setValue(value.getTime());
                if (value.getSeriesId() == vo2.getSeriesId()) {
                    // Check value
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
                    // Check time
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesId2Counter).getTime(), value.getTime());
                    seriesId2Counter++;
                } else {
                    // Check value
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
                    // Check time
                    Assert.assertEquals(data.get(value.getSeriesId()).get(seriesIdCounter).getTime(), value.getTime());
                    seriesIdCounter++;
                }
                if (count.getValue() == 20)
                    throw new QueryCancelledException(new Exception("Exception Test"));
            }

            @Override
            public void lastValue(IdPointValueTime value, boolean bookend) {
                Assert.fail("Query cancelled, should not get last value");
            }
        });
    } catch (QueryCancelledException e) {
    // noop
    }
    Assert.assertEquals(Integer.valueOf(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) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException)

Example 28 with QueryCancelledException

use of com.infiniteautomation.mango.db.query.QueryCancelledException in project ma-modules-public by infiniteautomation.

the class AbstractMultiDataPointStatisticsQuantizerStream method writePeriodStats.

/**
 * Check limit and maybe write the period stats
 */
protected void writePeriodStats(DataPointRollupPeriodValue generator) throws QueryCancelledException {
    // Code limit
    try {
        if (info.getLimit() != null && count >= info.getLimit())
            return;
        this.writer.writeDataPointValue(generator);
        count++;
    } catch (IOException e) {
        throw new QueryCancelledException(e);
    }
}
Also used : IOException(java.io.IOException) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException)

Example 29 with QueryCancelledException

use of com.infiniteautomation.mango.db.query.QueryCancelledException in project ma-modules-public by infiniteautomation.

the class MultiDataPointDefaultRollupStatisticsQuantizerStream method accept.

@Override
public void accept(IdPointValueTime value) {
    try {
        if (!useSimplify) {
            super.accept(value);
            return;
        }
        updateQuantizers(value);
        DataPointStatisticsQuantizer<?> quantizer = this.quantizerMap.get(value.getSeriesId());
        quantizer.accept(value);
    } catch (IOException e) {
        throw new QueryCancelledException(e);
    }
}
Also used : IOException(java.io.IOException) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException)

Example 30 with QueryCancelledException

use of com.infiniteautomation.mango.db.query.QueryCancelledException in project ma-modules-public by infiniteautomation.

the class MultiDataPointStatisticsQuantizerStream method accept.

@Override
public void accept(IdPointValueTime value) {
    try {
        updateQuantizers(value);
        if (info.isSingleArray() && voMap.size() > 1) {
            // this will keep our periodStats to a minimum
            if (lastTime != null && value.getTime() != lastTime) {
                // Finish by forwarding to the point value time
                Iterator<Integer> it = this.currentValueTimeMap.keySet().iterator();
                while (it.hasNext()) {
                    Integer id = it.next();
                    DataPointStatisticsQuantizer<?> q = this.quantizerMap.get(id);
                    IdPointValueTimeRow row = this.currentValueTimeMap.get(id);
                    it.remove();
                    if (row == null) {
                        // No values in this sample period
                        q.fastForward(lastTime);
                    } else {
                        q.accept(row.value);
                    }
                }
                currentValueTimeMap.put(value.getSeriesId(), new IdPointValueTimeRow(value));
            } else {
                // cache the value so as not to trigger quantization until all values are ready
                currentValueTimeMap.put(value.getSeriesId(), new IdPointValueTimeRow(value));
            }
            lastTime = value.getTime();
        } else {
            DataPointStatisticsQuantizer<?> quantizer = this.quantizerMap.get(value.getSeriesId());
            quantizer.accept(value);
        }
    } catch (IOException e) {
        throw new QueryCancelledException(e);
    }
}
Also used : IOException(java.io.IOException) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException)

Aggregations

QueryCancelledException (com.infiniteautomation.mango.db.query.QueryCancelledException)65 MutableInt (org.apache.commons.lang3.mutable.MutableInt)56 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)50 NextTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster)48 ZonedDateTime (java.time.ZonedDateTime)48 Test (org.junit.Test)48 ArrayList (java.util.ArrayList)30 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)28 AnalogStatistics (com.infiniteautomation.mango.statistics.AnalogStatistics)17 StartsAndRuntimeList (com.infiniteautomation.mango.statistics.StartsAndRuntimeList)17 ValueChangeCounter (com.infiniteautomation.mango.statistics.ValueChangeCounter)17 StartsAndRuntime (com.infiniteautomation.mango.statistics.StartsAndRuntime)14 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)14 MutableLong (org.apache.commons.lang3.mutable.MutableLong)8 IOException (java.io.IOException)7 Map (java.util.Map)3 PointValueField (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField)2 PointValueTimeWriter (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeWriter)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 JsonEncoding (com.fasterxml.jackson.core.JsonEncoding)1