Search in sources :

Example 1 with MockDataSourceRT

use of com.serotonin.m2m2.rt.dataSource.MockDataSourceRT in project ma-core-public by infiniteautomation.

the class DataPointRTTest method testIntervalOnChangeLogging.

/**
 * Test Interval Logged Values w/ On Change Option
 */
@Test
public void testIntervalOnChangeLogging() {
    MockDataSourceVO dsVo = new MockDataSourceVO();
    MockDataSourceRT dataSource = dsVo.createDataSourceRT();
    dataSource.initialize(false);
    PointValueDao dao = Common.getBean(PointValueDao.class);
    MockPointLocatorVO plVo = new MockPointLocatorVO(DataType.NUMERIC, true);
    DataPointVO dpVo = new DataPointVO();
    dpVo.setId(1);
    dpVo.setDataSourceId(dsVo.getId());
    // Configure Interval on change logging
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
    dpVo.setTolerance(0.5);
    dpVo.setIntervalLoggingPeriod(5);
    dpVo.setIntervalLoggingPeriodType(TimePeriods.SECONDS);
    dpVo.setPointLocator(plVo);
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
    MockPointLocatorRT plRt = new MockPointLocatorRT(plVo);
    // Setup some initial data
    List<PointValueTime> initialCache = new ArrayList<>();
    initialCache.add(new PointValueTime(1.0, 0));
    SimulationTimer timer = new SimulationTimer();
    DataPointWithEventDetectors dp = new DataPointWithEventDetectors(dpVo, new ArrayList<>());
    DataPointRT rt = new DataPointRT(dp, plRt, dataSource, initialCache, dao, Common.getBean(PointValueCache.class), timer);
    rt.initialize(false);
    // Test no changes
    timer.fastForwardTo(5001);
    PointValueTime value = dao.getLatestPointValue(dpVo).orElse(null);
    // Ensure database has interval logged value
    assertEquals(1.0, value.getDoubleValue(), 0.0001);
    assertEquals(5000, value.getTime());
    // Ensure cache does not have interval logged value
    assertEquals(1.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(0, rt.getPointValue().getTime());
    // Next interval
    timer.fastForwardTo(6000);
    rt.setPointValue(new PointValueTime(2.0, 6000), null);
    // Check Log On Change
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(6000, value.getTime());
    assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(6000, rt.getPointValue().getTime());
    // Interval is reset for 5000ms from now
    timer.fastForwardTo(11001);
    // Check Interval Log
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(11000, value.getTime());
    assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(6000, rt.getPointValue().getTime());
    // Test Tolerance (Should not get logged)
    timer.fastForwardTo(12000);
    rt.setPointValue(new PointValueTime(2.20, 12000), null);
    // Check Log On Change
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(11000, value.getTime());
    // Cache will have the set value
    assertEquals(2.2, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(12000, rt.getPointValue().getTime());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) SimulationTimer(com.serotonin.timer.SimulationTimer) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) BasicSQLPointValueDao(com.serotonin.m2m2.db.dao.BasicSQLPointValueDao) MockPointLocatorRT(com.serotonin.m2m2.rt.dataSource.MockPointLocatorRT) MockDataSourceRT(com.serotonin.m2m2.rt.dataSource.MockDataSourceRT) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) Test(org.junit.Test)

Example 2 with MockDataSourceRT

use of com.serotonin.m2m2.rt.dataSource.MockDataSourceRT in project ma-core-public by MangoAutomation.

the class DataPointRTTest method testIntervalOnChangeLogging.

/**
 * Test Interval Logged Values w/ On Change Option
 */
@Test
public void testIntervalOnChangeLogging() {
    MockDataSourceVO dsVo = new MockDataSourceVO();
    MockDataSourceRT dataSource = dsVo.createDataSourceRT();
    dataSource.initialize(false);
    PointValueDao dao = Common.getBean(PointValueDao.class);
    MockPointLocatorVO plVo = new MockPointLocatorVO(DataType.NUMERIC, true);
    DataPointVO dpVo = new DataPointVO();
    dpVo.setId(1);
    dpVo.setDataSourceId(dsVo.getId());
    // Configure Interval on change logging
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
    dpVo.setTolerance(0.5);
    dpVo.setIntervalLoggingPeriod(5);
    dpVo.setIntervalLoggingPeriodType(TimePeriods.SECONDS);
    dpVo.setPointLocator(plVo);
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
    MockPointLocatorRT plRt = new MockPointLocatorRT(plVo);
    // Setup some initial data
    List<PointValueTime> initialCache = new ArrayList<>();
    initialCache.add(new PointValueTime(1.0, 0));
    SimulationTimer timer = new SimulationTimer();
    DataPointWithEventDetectors dp = new DataPointWithEventDetectors(dpVo, new ArrayList<>());
    DataPointRT rt = new DataPointRT(dp, plRt, dataSource, initialCache, dao, Common.getBean(PointValueCache.class), timer);
    rt.initialize(false);
    // Test no changes
    timer.fastForwardTo(5001);
    PointValueTime value = dao.getLatestPointValue(dpVo).orElse(null);
    // Ensure database has interval logged value
    assertEquals(1.0, value.getDoubleValue(), 0.0001);
    assertEquals(5000, value.getTime());
    // Ensure cache does not have interval logged value
    assertEquals(1.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(0, rt.getPointValue().getTime());
    // Next interval
    timer.fastForwardTo(6000);
    rt.setPointValue(new PointValueTime(2.0, 6000), null);
    // Check Log On Change
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(6000, value.getTime());
    assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(6000, rt.getPointValue().getTime());
    // Interval is reset for 5000ms from now
    timer.fastForwardTo(11001);
    // Check Interval Log
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(11000, value.getTime());
    assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(6000, rt.getPointValue().getTime());
    // Test Tolerance (Should not get logged)
    timer.fastForwardTo(12000);
    rt.setPointValue(new PointValueTime(2.20, 12000), null);
    // Check Log On Change
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(11000, value.getTime());
    // Cache will have the set value
    assertEquals(2.2, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(12000, rt.getPointValue().getTime());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) SimulationTimer(com.serotonin.timer.SimulationTimer) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) BasicSQLPointValueDao(com.serotonin.m2m2.db.dao.BasicSQLPointValueDao) MockPointLocatorRT(com.serotonin.m2m2.rt.dataSource.MockPointLocatorRT) MockDataSourceRT(com.serotonin.m2m2.rt.dataSource.MockDataSourceRT) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) Test(org.junit.Test)

Aggregations

PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)2 BasicSQLPointValueDao (com.serotonin.m2m2.db.dao.BasicSQLPointValueDao)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 MockDataSourceRT (com.serotonin.m2m2.rt.dataSource.MockDataSourceRT)2 MockPointLocatorRT (com.serotonin.m2m2.rt.dataSource.MockPointLocatorRT)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 DataPointWithEventDetectors (com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)2 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)2 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)2 SimulationTimer (com.serotonin.timer.SimulationTimer)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2