From 3c76bd78ec3358155a1e0e475beec72c62632d4d Mon Sep 17 00:00:00 2001 From: Sid Narayan Date: Mon, 16 Nov 2020 13:28:42 -0800 Subject: [PATCH 1/2] Add PersistableSlidingWindow UT for multiple writes --- .../PersistableSlidingWindowTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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..04e651213 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,21 @@ 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(); + // This call to next removes the previous data from the window + 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() { From 036cbf0b2412bb3f8cd2c26a0233bb3b366c70a4 Mon Sep 17 00:00:00 2001 From: Sid Narayan Date: Mon, 16 Nov 2020 13:31:06 -0800 Subject: [PATCH 2/2] Remove unnecessary comment --- .../framework/api/aggregators/PersistableSlidingWindowTest.java | 1 - 1 file changed, 1 deletion(-) 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 04e651213..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 @@ -93,7 +93,6 @@ public void testMultipleWrites() throws IOException { long curTimestamp = Instant.now().toEpochMilli(); slidingWindow.next(new SlidingWindowData(curTimestamp, 10)); slidingWindow.write(); - // This call to next removes the previous data from the window slidingWindow.next(new SlidingWindowData(curTimestamp, 10)); slidingWindow.write(); PersistableSlidingWindow slidingWindow2 = new PersistableSlidingWindow(1, TimeUnit.SECONDS, persistFile);