use of com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO in project ma-core-public by infiniteautomation.
the class DataPointRTTest method testIntervalOnChangeLogging.
/**
* Test Interval Logged Values w/ On Change Option
*/
@Test
public void testIntervalOnChangeLogging() {
PointValueDao dao = Common.databaseProxy.newPointValueDao();
MockPointLocatorVO plVo = new MockPointLocatorVO(DataTypes.NUMERIC, true);
DataPointVO dpVo = new DataPointVO();
dpVo.setId(1);
// 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);
MockDataSourceVO dsVo = new MockDataSourceVO();
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();
DataPointRT rt = new DataPointRT(dpVo, plRt, dsVo, initialCache, timer);
rt.initialize();
rt.initializeIntervalLogging(0, false);
// Test no changes
timer.fastForwardTo(5001);
PointValueTime value = dao.getLatestPointValue(dpVo.getId());
// 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.getId());
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.getId());
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.getId());
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());
}
use of com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO in project ma-core-public by infiniteautomation.
the class PublisherAuditTest method createPoints.
protected List<MockPublishedPointVO> createPoints() {
List<MockPublishedPointVO> points = new ArrayList<MockPublishedPointVO>(pointCount);
// Create data source?
MockDataSourceVO ds = new MockDataSourceVO();
ds.setXid("DS_TEST1");
ds.setName("TEST");
DataSourceDao.instance.save(ds);
for (int i = 1; i < pointCount + 1; i++) {
DataPointVO dp = new DataPointVO();
dp.setXid("DP_" + i);
dp.setPointLocator(new MockPointLocatorVO(DataTypes.NUMERIC, true));
dp.setDataSourceId(ds.getId());
DataPointDao.instance.save(dp);
MockPublishedPointVO vo = new MockPublishedPointVO();
vo.setDataPointId(i);
points.add(vo);
}
return points;
}
Aggregations