Search in sources :

Example 1 with BrownianPointValueGenerator

use of com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator in project ma-core-public by infiniteautomation.

the class MigrationPointValueDaoTest method generatedBrownian.

@Test
public void generatedBrownian() throws ExecutionException, InterruptedException, TimeoutException {
    var dataSource = createMockDataSource();
    var point = createMockDataPoint(dataSource, new MockPointLocatorVO());
    TemporalAmount testDuration = Duration.ofDays(30);
    ZonedDateTime from = ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 0, 0), ZoneOffset.UTC);
    ZonedDateTime to = from.plus(testDuration);
    Duration period = Duration.ofHours(1L);
    long expectedSamples = Duration.between(from, to).dividedBy(period);
    // migration stops at the current time
    timer.setStartTime(to.toInstant().toEpochMilli());
    BrownianPointValueGenerator generator = new BrownianPointValueGenerator(from.toInstant(), to.toInstant(), period);
    source.savePointValues(generator.apply(point));
    // sanity check
    assertEquals(expectedSamples, source.dateRangeCount(point, null, null));
    migrationPointValueDao.startMigration();
    migrationPointValueDao.migrationFinished().get(30, TimeUnit.SECONDS);
    List<IdPointValueTime> destinationValues;
    try (var stream = destination.streamPointValues(point, null, null, null, TimeOrder.ASCENDING)) {
        destinationValues = stream.collect(Collectors.toList());
    }
    assertEquals(expectedSamples, destinationValues.size());
    for (int i = 0; i < expectedSamples; i++) {
        var destinationValue = destinationValues.get(i);
        assertEquals(point.getSeriesId(), destinationValue.getSeriesId());
        assertEquals(from.plus(period.multipliedBy(i)).toInstant().toEpochMilli(), destinationValue.getTime());
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) TemporalAmount(java.time.temporal.TemporalAmount) BrownianPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator) Duration(java.time.Duration) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Test(org.junit.Test)

Example 2 with BrownianPointValueGenerator

use of com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator in project ma-core-public by infiniteautomation.

the class MigrationPointValueDaoTest method multipleDataPoints.

@Test
public void multipleDataPoints() throws ExecutionException, InterruptedException, TimeoutException {
    var dataSource = createMockDataSource();
    var points = createMockDataPoints(dataSource, 100);
    TemporalAmount testDuration = Period.ofMonths(6);
    ZonedDateTime from = ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 0, 0), ZoneOffset.UTC);
    ZonedDateTime to = from.plus(testDuration);
    Duration period = Duration.ofHours(1L);
    long expectedSamples = Duration.between(from, to).dividedBy(period);
    // migration stops at the current time
    timer.setStartTime(to.toInstant().toEpochMilli());
    BrownianPointValueGenerator generator = new BrownianPointValueGenerator(from.toInstant(), to.toInstant(), period);
    for (var point : points) {
        source.savePointValues(generator.apply(point));
        // sanity check
        assertEquals(expectedSamples, source.dateRangeCount(point, null, null));
    }
    migrationPointValueDao.startMigration();
    migrationPointValueDao.migrationFinished().get(30, TimeUnit.SECONDS);
    for (var point : points) {
        List<IdPointValueTime> destinationValues;
        try (var stream = destination.streamPointValues(point, null, null, null, TimeOrder.ASCENDING)) {
            destinationValues = stream.collect(Collectors.toList());
        }
        assertEquals(expectedSamples, destinationValues.size());
        for (int i = 0; i < expectedSamples; i++) {
            var destinationValue = destinationValues.get(i);
            assertEquals(point.getSeriesId(), destinationValue.getSeriesId());
            assertEquals(from.plus(period.multipliedBy(i)).toInstant().toEpochMilli(), destinationValue.getTime());
        }
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) TemporalAmount(java.time.temporal.TemporalAmount) BrownianPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator) Duration(java.time.Duration) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) Test(org.junit.Test)

Aggregations

BrownianPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator)2 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)2 Duration (java.time.Duration)2 ZonedDateTime (java.time.ZonedDateTime)2 TemporalAmount (java.time.temporal.TemporalAmount)2 Test (org.junit.Test)2 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)1