This is an automated email from the ASF dual-hosted git repository. jihao pushed a commit to branch anomalies-pagination in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit a9d4aea4e27122f9b103b4bdb813d97e5c77f8af Author: Jihao Zhang <jihzh...@linkedin.com> AuthorDate: Wed Jul 29 16:52:39 2020 -0700 unit tests --- .../v2/anomalies/AnomalySearchFilter.java | 18 ++++++ .../v2/anomalies/AnomalySearcherTest.java | 68 ++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearchFilter.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearchFilter.java index e995e5a..533c554 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearchFilter.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearchFilter.java @@ -1,5 +1,6 @@ package org.apache.pinot.thirdeye.dashboard.resources.v2.anomalies; +import java.util.Collections; import java.util.List; @@ -21,6 +22,23 @@ public class AnomalySearchFilter { * * @param startTime the start time * @param endTime the end time + */ + public AnomalySearchFilter(Long startTime, Long endTime) { + this.startTime = startTime; + this.endTime = endTime; + this.feedbacks = Collections.emptyList(); + this.subscriptionGroups = Collections.emptyList(); + this.detectionNames = Collections.emptyList(); + this.metrics = Collections.emptyList(); + this.datasets = Collections.emptyList(); + this.anomalyIds = Collections.emptyList(); + } + + /** + * Instantiates a new Anomaly search filter. + * + * @param startTime the start time + * @param endTime the end time * @param feedbacks the feedbacks * @param subscriptionGroups the subscription groups * @param detectionNames the detection names diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearcherTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearcherTest.java new file mode 100644 index 0000000..14a0f4b --- /dev/null +++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/dashboard/resources/v2/anomalies/AnomalySearcherTest.java @@ -0,0 +1,68 @@ +package org.apache.pinot.thirdeye.dashboard.resources.v2.anomalies; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.apache.pinot.thirdeye.datalayer.bao.DAOTestBase; +import org.apache.pinot.thirdeye.datalayer.bao.MergedAnomalyResultManager; +import org.apache.pinot.thirdeye.datalayer.dto.MergedAnomalyResultDTO; +import org.apache.pinot.thirdeye.datasource.DAORegistry; +import org.apache.pinot.thirdeye.detection.ConfigUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class AnomalySearcherTest { + private DAOTestBase testDAOProvider; + private MergedAnomalyResultManager anomalyDAO; + + @BeforeClass + public void beforeClass() { + testDAOProvider = DAOTestBase.getInstance(); + anomalyDAO = DAORegistry.getInstance().getMergedAnomalyResultDAO(); + MergedAnomalyResultDTO anomaly1 = new MergedAnomalyResultDTO(); + MergedAnomalyResultDTO anomaly2 = new MergedAnomalyResultDTO(); + MergedAnomalyResultDTO anomaly3 = new MergedAnomalyResultDTO(); + + anomaly1.setStartTime(1L); + anomaly1.setEndTime(2L); + anomaly1.setCollection("test_dataset_1"); + anomaly2.setStartTime(2L); + anomaly2.setEndTime(3L); + anomaly2.setCollection("test_dataset_2"); + anomaly3.setStartTime(5L); + anomaly3.setEndTime(6L); + anomalyDAO.save(anomaly1); + anomalyDAO.save(anomaly2); + anomalyDAO.save(anomaly3); + } + + @Test + public void testSearch() { + AnomalySearcher anomalySearcher = new AnomalySearcher(); + Map<String, Object> result = anomalySearcher.search(new AnomalySearchFilter(1L, 3L), 10, 0); + Assert.assertEquals(result.get("count"), 2L); + Assert.assertEquals(result.get("limit"), 10); + Assert.assertEquals(result.get("offset"), 0); + List<MergedAnomalyResultDTO> anomalies = ConfigUtils.getList(result.get("elements")); + Assert.assertEquals(anomalies.size(), 2); + Assert.assertEquals(anomalies.get(0), anomalyDAO.findById(1L)); + Assert.assertEquals(anomalies.get(1), anomalyDAO.findById(2L)); + } + + @Test + public void testSearchWithFilters() { + AnomalySearcher anomalySearcher = new AnomalySearcher(); + Map<String, Object> result = anomalySearcher.search( + new AnomalySearchFilter(1L, 3L, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), + Collections.emptyList(), Arrays.asList("test_dataset_1"), Collections.emptyList()), 10, 0); + Assert.assertEquals(result.get("count"), 1L); + Assert.assertEquals(result.get("limit"), 10); + Assert.assertEquals(result.get("offset"), 0); + List<MergedAnomalyResultDTO> anomalies = ConfigUtils.getList(result.get("elements")); + Assert.assertEquals(anomalies.size(), 1); + Assert.assertEquals(anomalies.get(0), anomalyDAO.findById(1L)); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org