From fc0c47762f5735b9acdf11ddf337ebc669aa49d5 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Mon, 26 Feb 2024 10:32:02 +0400 Subject: [PATCH] [TH2-5165] getPages(start, end, order) can handle start > end case --- .../main/java/com/exactpro/cradle/BookInfo.java | 15 +++------------ .../java/com/exactpro/cradle/BookInfoTest.java | 8 ++++++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cradle-core/src/main/java/com/exactpro/cradle/BookInfo.java b/cradle-core/src/main/java/com/exactpro/cradle/BookInfo.java index 52f86b88..f9747fe4 100644 --- a/cradle-core/src/main/java/com/exactpro/cradle/BookInfo.java +++ b/cradle-core/src/main/java/com/exactpro/cradle/BookInfo.java @@ -181,10 +181,8 @@ public Iterator getPages(@Nullable Instant leftBoundTimestamp, if (leftBoundTimestamp != null && rightBoundTimestamp != null && leftBoundTimestamp.isAfter(rightBoundTimestamp)) { - throw new IllegalArgumentException( - "Left bound '" + leftBoundTimestamp + - "' must be <= right bound '" + rightBoundTimestamp + "'" - ); + LOGGER.warn("Left bound '{}' should be <= right bound '{}'", leftBoundTimestamp, rightBoundTimestamp); + return emptyIterator(); } Instant leftTimestamp = calculateBound(leftBoundTimestamp, this::getFirstPage); @@ -358,8 +356,7 @@ void refresh() { getFirstPage(); long currentEpochDay = currentEpochDay(); for (int shift = HOT_CACHE_SIZE - 1; shift >= 0; shift--) { - //noinspection ResultOfMethodCallIgnored - this.hotCache.get(currentEpochDay - shift); + this.hotCache.get(currentEpochDay - shift); } } @@ -559,12 +556,6 @@ private static PageInterval create(BookId id, Instant start, BookInfoMetrics.Cac Map pageById = new HashMap<>(); TreeMap pageByInstant = new TreeMap<>(); for (PageInfo page : pages) { - // if (page.getEnded() == null) { -// throw new IllegalStateException( -// "Page with '" + page.getId() + "' id hasn't got ended time" -// ); -// } - PageInfo previous = pageById.put(page.getId(), page); if (previous != null) { throw new IllegalStateException( diff --git a/cradle-core/src/test/java/com/exactpro/cradle/BookInfoTest.java b/cradle-core/src/test/java/com/exactpro/cradle/BookInfoTest.java index 9b9d709b..759746e3 100644 --- a/cradle-core/src/test/java/com/exactpro/cradle/BookInfoTest.java +++ b/cradle-core/src/test/java/com/exactpro/cradle/BookInfoTest.java @@ -146,7 +146,7 @@ public void getAllPagesInReverseOrderTest() { } @Test(dataProvider = "orders") - public void getPagesByOneTimestamp(Order order) { + public void getPagesWithEmptyResult(Order order) { PageInfo pageInfo = PAGES.get(0); List operateSource = List.of(pageInfo); BookInfo bookInfo = createBookInfo(operateSource, 1); @@ -156,12 +156,16 @@ public void getPagesByOneTimestamp(Order order) { emptyList(), "End timestamp before first page start" ); - assertEquals( newArrayList(bookInfo.getPages(pageInfo.getEnded().plus(1, NANOS), null, order)), emptyList(), "Start timestamp after last page end" ); + assertEquals( + newArrayList(bookInfo.getPages(pageInfo.getEnded(), pageInfo.getStarted(), order)), + emptyList(), + "Start > end timestamp after last page end" + ); } @Test(dataProvider = "orders")