From 7d3bfd5c131f0d0d2d34aa613004bcf9b000dcb5 Mon Sep 17 00:00:00 2001 From: Clemens Zagler Date: Thu, 16 Jan 2025 17:04:21 +0100 Subject: [PATCH] wip unit tests for new period handling --- .../bdp/writer/DataRetrievalITTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/writer/src/test/java/com/opendatahub/timeseries/bdp/writer/DataRetrievalITTest.java b/writer/src/test/java/com/opendatahub/timeseries/bdp/writer/DataRetrievalITTest.java index 2de87f32..c59730a4 100644 --- a/writer/src/test/java/com/opendatahub/timeseries/bdp/writer/DataRetrievalITTest.java +++ b/writer/src/test/java/com/opendatahub/timeseries/bdp/writer/DataRetrievalITTest.java @@ -164,5 +164,48 @@ public void testDuplicateMeasurements() { DataMapDto.build(provenance.getUuid(), station.getStationcode(), type.getCname(), values)); assertEquals(HttpStatus.CREATED, result.getStatusCode()); } + + @Test + public void testPushRecords(){ + DataType tCount = new DataType(PREFIX + "reccount", "", "Fake type", "test"); + em.getTransaction().begin(); + em.persist(tCount); + em.getTransaction().commit(); + + List recs = new ArrayList<>(); + long ts = 1737041440; + + // Just insert records in order + recs.add(new SimpleRecordDto(ts, 1.0, 600)); + recs.add(new SimpleRecordDto(ts+1, 1.1, 600)); + recs.add(new SimpleRecordDto(ts+2, 1.2, 600)); + var dmResult = dataManager.pushRecords(STATION_TYPE, null, DataMapDto.build(provenance.getUuid(), station.getStationcode(), tCount.getCname(), recs)); + assertEquals(HttpStatus.CREATED, dmResult.getStatusCode()); + + var qResult = em.createQuery("select count(*) from MeasurementHistory where type.id = " + tCount.getId(), Long.class).getSingleResult(); + // all there + assertEquals(3L, qResult.intValue()); + + // Should ignore the timestamp duplicate + recs.clear(); + recs.add(new SimpleRecordDto(ts, 1.3, 600)); + recs.add(new SimpleRecordDto(ts+3, 1.3, 600)); + dmResult = dataManager.pushRecords(STATION_TYPE, null, DataMapDto.build(provenance.getUuid(), station.getStationcode(), tCount.getCname(), recs)); + assertEquals(HttpStatus.CREATED, dmResult.getStatusCode()); + qResult = em.createQuery("select count(*) from MeasurementHistory where type.id = " + tCount.getId(), Long.class).getSingleResult(); + assertEquals(4L, qResult.intValue()); + + // Insert different periods, should ignore one record for each period because of timestamp + recs.clear(); + recs.add(new SimpleRecordDto(ts, 1.3, 600)); + recs.add(new SimpleRecordDto(ts, 1.3, 10)); + recs.add(new SimpleRecordDto(ts+1, 1.3, 10)); + recs.add(new SimpleRecordDto(ts+4, 1.3, 600)); + recs.add(new SimpleRecordDto(ts, 1.3, 10)); + dmResult = dataManager.pushRecords(STATION_TYPE, null, DataMapDto.build(provenance.getUuid(), station.getStationcode(), tCount.getCname(), recs)); + assertEquals(HttpStatus.CREATED, dmResult.getStatusCode()); + qResult = em.createQuery("select count(*) from MeasurementHistory where type.id = " + tCount.getId(), Long.class).getSingleResult(); + assertEquals(7, qResult.intValue()); + } }