diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/api/aggregators/PersistableSlidingWindowTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/api/aggregators/PersistableSlidingWindowTest.java index bcef18f71..71d9f4b70 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/api/aggregators/PersistableSlidingWindowTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/framework/api/aggregators/PersistableSlidingWindowTest.java @@ -84,7 +84,20 @@ public void testDifferentTimeUnits() throws Exception { Assert.assertEquals(1, slidingWindow.size()); } - + /** + * Tests that a PSW can call write() multiple times and still have its data read + */ + @Test + public void testMultipleWrites() throws IOException { + PersistableSlidingWindow slidingWindow = new PersistableSlidingWindow(1, TimeUnit.SECONDS, persistFile); + long curTimestamp = Instant.now().toEpochMilli(); + slidingWindow.next(new SlidingWindowData(curTimestamp, 10)); + slidingWindow.write(); + slidingWindow.next(new SlidingWindowData(curTimestamp, 10)); + slidingWindow.write(); + PersistableSlidingWindow slidingWindow2 = new PersistableSlidingWindow(1, TimeUnit.SECONDS, persistFile); + Assert.assertEquals(20, slidingWindow2.readSum(), 0.0); + } @AfterClass public static void tearDown() {