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());
}
}
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());
}
}
}
Aggregations