Skip to content

Commit

Permalink
[TH2-5165] getPages(start, end, order) can handle start > end case
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Feb 26, 2024
1 parent 6ec65e9 commit fc0c477
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
15 changes: 3 additions & 12 deletions cradle-core/src/main/java/com/exactpro/cradle/BookInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ public Iterator<PageInfo> 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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -559,12 +556,6 @@ private static PageInterval create(BookId id, Instant start, BookInfoMetrics.Cac
Map<PageId, PageInfo> pageById = new HashMap<>();
TreeMap<Instant, PageInfo> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PageInfo> operateSource = List.of(pageInfo);
BookInfo bookInfo = createBookInfo(operateSource, 1);
Expand All @@ -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")
Expand Down

0 comments on commit fc0c477

Please sign in to comment.