|
12 | 12 | import org.epics.archiverappliance.data.ScalarValue; |
13 | 13 | import org.epics.archiverappliance.data.VectorValue; |
14 | 14 | import org.epics.archiverappliance.retrieval.CallableEventStream; |
| 15 | +import org.epics.archiverappliance.retrieval.ChangeInYearsException; |
15 | 16 | import org.epics.archiverappliance.retrieval.postprocessors.Optimized; |
16 | 17 | import org.epics.archiverappliance.utils.simulation.SimulationEvent; |
17 | 18 | import org.junit.jupiter.api.Assertions; |
@@ -322,4 +323,68 @@ static Stream<Arguments> testInclusionOfLastValueBeforeFirstBinIntoFirstBin_gene |
322 | 323 | Arguments.of(50000, 51000, Arrays.asList(50.0)), |
323 | 324 | Arguments.of(51000, 52000, Arrays.asList(50.0))); |
324 | 325 | } |
| 326 | + |
| 327 | + @Test |
| 328 | + public void testOptimizedCrossYearDetection() { |
| 329 | + String optimizedTestPVName = "Test_OptimizedCrossYearDetection"; |
| 330 | + |
| 331 | + YearSecondTimestamp start2024 = |
| 332 | + TimeUtils.convertToYearSecondTimestamp(TimeUtils.convertFromISO8601String("2024-12-31T23:59:50.000Z")); |
| 333 | + YearSecondTimestamp start2025 = |
| 334 | + TimeUtils.convertToYearSecondTimestamp(TimeUtils.convertFromISO8601String("2025-01-01T00:00:00.000Z")); |
| 335 | + |
| 336 | + double valueIn2024 = 1.0; |
| 337 | + double valueIn2025 = 2.0; |
| 338 | + |
| 339 | + ArrayListEventStream testData = new ArrayListEventStream( |
| 340 | + 2, |
| 341 | + new RemotableEventStreamDesc(ArchDBRTypes.DBR_SCALAR_DOUBLE, optimizedTestPVName, start2024.getYear())); |
| 342 | + |
| 343 | + // Add 1 first-year event |
| 344 | + testData.add(new SimulationEvent( |
| 345 | + start2024.getSecondsintoyear(), |
| 346 | + start2024.getYear(), |
| 347 | + ArchDBRTypes.DBR_SCALAR_DOUBLE, |
| 348 | + new ScalarValue<>(valueIn2024))); |
| 349 | + |
| 350 | + // Add 1 second-year event |
| 351 | + testData.add(new SimulationEvent( |
| 352 | + start2025.getSecondsintoyear(), |
| 353 | + start2025.getYear(), |
| 354 | + ArchDBRTypes.DBR_SCALAR_DOUBLE, |
| 355 | + new ScalarValue<>(valueIn2025))); |
| 356 | + |
| 357 | + Optimized optimizedPostProcessor = new Optimized(); |
| 358 | + try { |
| 359 | + optimizedPostProcessor.initialize("optimized_5760", optimizedTestPVName); |
| 360 | + } catch (IOException e) { |
| 361 | + throw new RuntimeException(e); |
| 362 | + } |
| 363 | + |
| 364 | + var callableEventStream = CallableEventStream.makeOneStreamCallable(testData, null, false); |
| 365 | + |
| 366 | + var callable = optimizedPostProcessor.wrap(callableEventStream); |
| 367 | + |
| 368 | + try { |
| 369 | + callable.call(); |
| 370 | + } catch (Exception e) { |
| 371 | + Assertions.fail( |
| 372 | + "An exception occurred when calling optimizedPostProcessor.wrap(callableEventStream).call()"); |
| 373 | + } |
| 374 | + |
| 375 | + EventStream eventStream = optimizedPostProcessor.getConsolidatedEventStream(); |
| 376 | + |
| 377 | + // First event is in 2024 - do not trigger the ChangeInYearsException |
| 378 | + Event first = eventStream.iterator().next(); |
| 379 | + Assertions.assertEquals(valueIn2024, first.getSampleValue().getValue()); |
| 380 | + |
| 381 | + // Second event is in 2025 - trigger the ChangeInYearsException |
| 382 | + ChangeInYearsException ex = Assertions.assertThrows( |
| 383 | + ChangeInYearsException.class, |
| 384 | + eventStream.iterator()::next, |
| 385 | + "Expected ChangeInYearsException when year changes"); |
| 386 | + |
| 387 | + Assertions.assertEquals(start2024.getYear(), ex.getPreviousYear()); |
| 388 | + Assertions.assertEquals(start2025.getYear(), ex.getCurrentYear()); |
| 389 | + } |
325 | 390 | } |
0 commit comments