Skip to content

Commit

Permalink
[TH2-5204] refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Jun 26, 2024
1 parent 553d9fd commit fa46d7f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ Test events have mandatory parameters that are verified when storing an event. T

## Release notes

### 5.4.1
* Page interval in page cache hols all pages covered the interval.<br>
Fixed the problem - components reload page interval and last page each time when page starts in day before and ends day after requested period.

### 5.4.0
* Using internal executor instead of ForkJoinPool.commonPool() to process intermediate tasks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,30 @@
public interface PageOperator {
@Select
PagingIterable<PageEntity> getAll(String book, Function<BoundStatementBuilder, BoundStatementBuilder> attributes);


/**
* Executes request to Cassandra to receive several pages
* @param book - book id
* @param startDate - start day
* @param startTime - start time
* @param attributes - request attributes
* @return iterator for all pages which start datetime is greater than requested datetime - (requested datetime ... ]
*/
@Query( "SELECT * FROM ${qualifiedTableId} " +
"WHERE " +
FIELD_BOOK +"=:book AND " +
"(" + FIELD_START_DATE + ", " + FIELD_START_TIME + ") > (:startDate, :startTime)")
PagingIterable<PageEntity> getByStart(String book, LocalDate startDate, LocalTime startTime,
Function<BoundStatementBuilder, BoundStatementBuilder> attributes);

/**
* Executes request to Cassandra to receive several pages
* @param book - book id
* @param endDate- end day
* @param endTime - end time
* @param attributes - request attributes
* @return iterator for all pages which start datetime is greater or equal than requested datetime - (... requested datetime]
*/
@Query("SELECT * FROM ${qualifiedTableId} " +
"WHERE " +
FIELD_BOOK +"=:book AND " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ public void beforeMethod() {
doReturn(bookOperator).when(operators).getBookOperator();
doReturn(pagingIterable).when(pageOperator).getAll(same(bookId.getName()), same(readAttrs));
doAnswer(invocation -> {
LocalDate startDate = invocation.getArgument(1);
LocalTime startTime = invocation.getArgument(2);
LocalDate endDate = invocation.getArgument(3);
LocalTime endTime = invocation.getArgument(4);
String bookId = invocation.getArgument(0);
LocalDate endDate = invocation.getArgument(1);
LocalTime endTime = invocation.getArgument(2);

endDate = endDate == null ? LocalDate.MAX : endDate;
endTime = endTime == null ? LocalTime.MAX : endTime;

List<PageEntity> result = new ArrayList<>();
for (PageEntity pageEntity : pagingIterable) {
if ((startDate == null || !startDate.isAfter(pageEntity.getStartDate())) &&
(startTime == null || !startTime.isAfter(pageEntity.getStartTime())) &&
(endDate == null || pageEntity.getEndDate() == null || !endDate.isBefore(pageEntity.getEndDate())) &&
(endTime == null || pageEntity.getEndTime() == null || !endTime.isBefore(pageEntity.getEndTime()))) {
if (pageEntity.getBook().equals(bookId)
&& (pageEntity.getStartDate().isBefore(endDate)
|| pageEntity.getStartDate().equals(endDate) && !pageEntity.getStartTime().isAfter(endTime))) {
result.add(pageEntity);
}
}
Expand Down
2 changes: 0 additions & 2 deletions cradle-core/src/main/java/com/exactpro/cradle/BookInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public Iterator<PageInfo> getPages(@Nullable Instant leftBoundTimestamp,
* - end - page end timestamp excluded
*/
public PageInfo findPage(Instant timestamp) {
// Check is timestamp before epoch
long epochDay = getEpochDay(timestamp);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("find page for {} epoch {}, current cache hot: {}, random: {}",
Expand All @@ -249,7 +248,6 @@ public PageInfo findPage(Instant timestamp) {
if (epochDay < 0) {
return null;
}
// Check is timestamp >= MAX_EPOCH_DAY
if (epochDay >= MAX_EPOCH_DAY) {
PageInfo lastPage = getLastPage();
if (lastPage != null && lastPage.getEnded() == null) {
Expand Down

0 comments on commit fa46d7f

Please sign in to comment.