use of com.serotonin.m2m2.db.dao.BatchPointValueImpl in project ma-core-public by infiniteautomation.
the class NumericPointValueDaoTestHelper method before.
/**
* Insert some test data.
* Call before every test.
*/
public void before() {
List<BatchPointValue<PointValueTime>> values = new ArrayList<>();
// Start back 30 days
endTs = System.currentTimeMillis();
startTs = endTs - (30L * 24L * 60L * 60L * 1000L);
// Insert a few samples for series 2 before our time
series2StartTs = startTs - (1000 * 60 * 15);
long time = series2StartTs;
PointValueTime p2vt = new PointValueTime(-3.0, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
time = startTs - (1000 * 60 * 10);
p2vt = new PointValueTime(-2.0, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
time = startTs - (1000 * 60 * 5);
p2vt = new PointValueTime(-1.0, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
time = startTs;
// Insert a sample every 5 minutes
double value = 0.0;
while (time < endTs) {
PointValueTime pvt = new PointValueTime(value, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo1, pvt));
values.add(new BatchPointValueImpl<PointValueTime>(vo2, pvt));
time = time + 1000 * 60 * 5;
totalSampleCount++;
value++;
}
// Add a few more samples for series 2 after our time
p2vt = new PointValueTime(value++, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
time = time + (1000 * 60 * 5);
p2vt = new PointValueTime(value++, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
time = time + (1000 * 60 * 5);
p2vt = new PointValueTime(value, time);
values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
this.series2EndTs = time;
dao.savePointValues(values.stream().peek(v -> {
data.computeIfAbsent(v.getPoint().getSeriesId(), k -> new ArrayList<>()).add(v.getValue());
}), 10000);
}
use of com.serotonin.m2m2.db.dao.BatchPointValueImpl in project ma-core-public by infiniteautomation.
the class MigrationPointValueDaoTest method singleValue.
@Test
public void singleValue() throws ExecutionException, InterruptedException, TimeoutException {
var dataSource = createMockDataSource();
var point = createMockDataPoint(dataSource, new MockPointLocatorVO());
Instant from = Instant.ofEpochMilli(0L);
var sourceValues = List.of(new PointValueTime(0.0D, from.toEpochMilli()));
var batchInsertValues = sourceValues.stream().map(v -> new BatchPointValueImpl<>(point, v)).collect(Collectors.toList());
source.savePointValues(batchInsertValues.stream());
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(sourceValues.size(), destinationValues.size());
for (int i = 0; i < sourceValues.size(); i++) {
var sourceValue = sourceValues.get(i);
var destinationValue = destinationValues.get(i);
assertEquals(point.getSeriesId(), destinationValue.getSeriesId());
assertEquals(sourceValue.getTime(), destinationValue.getTime());
assertEquals(sourceValue.getValue(), destinationValue.getValue());
}
}
use of com.serotonin.m2m2.db.dao.BatchPointValueImpl in project ma-core-public by MangoAutomation.
the class NumericPointValueDaoTestHelper method before.
/**
* Insert some test data.
* Call before every test.
*/
public void before() {
List<BatchPointValue> values = new ArrayList<>();
// Start back 30 days
endTs = System.currentTimeMillis();
startTs = endTs - (30L * 24L * 60L * 60L * 1000L);
// Insert a few samples for series 2 before our time
series2StartTs = startTs - (1000 * 60 * 15);
long time = series2StartTs;
PointValueTime p2vt = new PointValueTime(-3.0, time);
values.add(new BatchPointValueImpl(vo2, p2vt));
time = startTs - (1000 * 60 * 10);
p2vt = new PointValueTime(-2.0, time);
values.add(new BatchPointValueImpl(vo2, p2vt));
time = startTs - (1000 * 60 * 5);
p2vt = new PointValueTime(-1.0, time);
values.add(new BatchPointValueImpl(vo2, p2vt));
time = startTs;
// Insert a sample every 5 minutes
double value = 0.0;
while (time < endTs) {
PointValueTime pvt = new PointValueTime(value, time);
values.add(new BatchPointValueImpl(vo1, pvt));
values.add(new BatchPointValueImpl(vo2, pvt));
time = time + 1000 * 60 * 5;
totalSampleCount++;
value++;
}
// Add a few more samples for series 2 after our time
p2vt = new PointValueTime(value++, time);
values.add(new BatchPointValueImpl(vo2, p2vt));
time = time + (1000 * 60 * 5);
p2vt = new PointValueTime(value++, time);
values.add(new BatchPointValueImpl(vo2, p2vt));
time = time + (1000 * 60 * 5);
p2vt = new PointValueTime(value, time);
values.add(new BatchPointValueImpl(vo2, p2vt));
this.series2EndTs = time;
dao.savePointValues(values.stream().peek(v -> {
data.computeIfAbsent(v.getVo().getSeriesId(), k -> new ArrayList<>()).add(v.getPointValue());
}), 10000);
}
Aggregations