diff --git a/README.md b/README.md index bf008990..65f1593d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Overview (5.4.3) +# Overview (5.4.4) Cradle API is used to work with Cradle - the datalake where th2 stores its data. @@ -209,6 +209,9 @@ Test events have mandatory parameters that are verified when storing an event. T ## Release notes +### 5.4.4 +* Fixed the problem - page cache doesn't work correct when storage has removed page(s) + ### 5.4.3 * Refactored the CassandraCradleStorage methods (doAddPages, doUpdatePageName, doUpdatePageComment) to execute insert and update operations atomically. * Updated th2 gradle plugin: `0.1.3` (bom: `4.8.0`) diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/ReadThroughBookCache.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/ReadThroughBookCache.java index cd795f0a..968b96f7 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/ReadThroughBookCache.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/ReadThroughBookCache.java @@ -130,7 +130,7 @@ Collection loadPageInfo(BookId bookId, Instant start, Instant end, boo } public PageInfo loadLastPageInfo(BookId bookId, boolean loadRemoved) { - for (PageEntity pageEntity : operators.getPageOperator().getLast( + for (PageEntity pageEntity : operators.getPageOperator().getAllDesc( bookId.getName(), readAttrs )) { @@ -142,10 +142,7 @@ public PageInfo loadLastPageInfo(BookId bookId, boolean loadRemoved) { } public PageInfo loadFirstPageInfo(BookId bookId, boolean loadRemoved) { - for (PageEntity pageEntity : operators.getPageOperator().getFirst( - bookId.getName(), - readAttrs - )) { + for (PageEntity pageEntity : operators.getPageOperator().getAll(bookId.getName(), readAttrs)) { if (loadRemoved || pageEntity.getRemoved() == null || pageEntity.getRemoved().equals(DEFAULT_PAGE_REMOVE_TIME)) { return pageEntity.toPageInfo(); } diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/books/PageOperator.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/books/PageOperator.java index 3c0625c9..8ad30f92 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/books/PageOperator.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/books/PageOperator.java @@ -38,6 +38,21 @@ public interface PageOperator { @Select PagingIterable getAll(String book, Function attributes); + /** + * Executes request to Cassandra to receive several pages in descending order + * + * @param book - book id + * @param attributes - request attributes + * @return iterator for all pages in descending order + */ + @Query("SELECT * FROM ${qualifiedTableId} " + + "WHERE " + + FIELD_BOOK +"=:book " + + "ORDER BY " + + FIELD_START_DATE + " DESC, " + + FIELD_START_TIME + " DESC") + PagingIterable getAllDesc(String book, Function attributes); + /** * Executes request to Cassandra to receive several pages * @param book - book id @@ -73,24 +88,6 @@ PagingIterable getAllDescBefore(String book, LocalDate date, LocalTime time, Function attributes); - @Query("SELECT * FROM ${qualifiedTableId} " + - "WHERE " + - FIELD_BOOK +"=:book " + - "ORDER BY " + - FIELD_START_DATE + " DESC, " + - FIELD_START_TIME + " DESC " + - "LIMIT 1") - PagingIterable getLast(String book, Function attributes); - - @Query("SELECT * FROM ${qualifiedTableId} " + - "WHERE " + - FIELD_BOOK +"=:book " + - "ORDER BY " + - FIELD_START_DATE + " ASC, " + - FIELD_START_TIME + " ASC " + - "LIMIT 1") - PagingIterable getFirst(String book, Function attributes); - @Update(nullSavingStrategy = NullSavingStrategy.SET_TO_NULL) ResultSet update(PageEntity entity, Function attributes); diff --git a/cradle-cassandra/src/test/java/com/exactpro/cradle/cassandra/integration/pages/BookInfoApiTest.java b/cradle-cassandra/src/test/java/com/exactpro/cradle/cassandra/integration/pages/BookInfoApiTest.java index f5f12822..8873eef6 100644 --- a/cradle-cassandra/src/test/java/com/exactpro/cradle/cassandra/integration/pages/BookInfoApiTest.java +++ b/cradle-cassandra/src/test/java/com/exactpro/cradle/cassandra/integration/pages/BookInfoApiTest.java @@ -21,6 +21,7 @@ import com.exactpro.cradle.Order; import com.exactpro.cradle.PageId; import com.exactpro.cradle.PageInfo; +import com.exactpro.cradle.PageToAdd; import com.exactpro.cradle.cassandra.CassandraCradleStorage; import com.exactpro.cradle.cassandra.integration.CassandraCradleHelper; import com.exactpro.cradle.utils.CradleStorageException; @@ -37,6 +38,7 @@ import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.exactpro.cradle.BookInfoMetrics.CacheName.HOT; import static com.exactpro.cradle.BookInfoMetrics.CacheName.RANDOM; @@ -54,6 +56,9 @@ public class BookInfoApiTest { private static final Instant NOW = Instant.now(); private static final BookId BOOK_ID = new BookId("test_book"); + private static final PageInfo PAGE_0 = new PageInfo( // -2 00:00 - -1 00:00 + new PageId(BOOK_ID, NOW.minus(2, DAYS).truncatedTo(DAYS), "page-0"), + NOW.minus(1, DAYS).truncatedTo(DAYS), ""); private static final PageInfo PAGE_1 = new PageInfo( // -1 00:00 - 1 00:00 new PageId(BOOK_ID, NOW.minus(1, DAYS).truncatedTo(DAYS), "page-1"), NOW.plus(1, DAYS).truncatedTo(DAYS), ""); @@ -77,9 +82,10 @@ public class BookInfoApiTest { public void beforeClass() throws IOException, CradleStorageException { storage = CassandraCradleHelper.getInstance().getStorage(); storage.addBook(new BookToAdd(BOOK_ID.getName(), NOW.minus(100, DAYS))); - for (PageInfo page : PAGES) { - storage.addPage(BOOK_ID, page.getName(), page.getStarted(), page.getComment()); - } + storage.addPages(BOOK_ID, Stream.concat(Stream.of(PAGE_0), PAGES.stream()) + .map(pageInfo -> new PageToAdd(pageInfo.getName(), pageInfo.getStarted(), pageInfo.getComment())) + .collect(Collectors.toList())); + storage.removePage(PAGE_0.getId()); } @BeforeMethod @@ -145,7 +151,7 @@ public void getPagesByTimeTest(Order order) { assertFalse(bookInfo.getPages(NOW.minus(4, DAYS), NOW.minus(3, DAYS), order).hasNext()); assertLoadCount(hotCacheLoad, randomCacheLoad, "after get pages before first page"); - assertLoadCount(hotCacheLoad, randomCacheLoad, "after get [1, 2] pages"); + assertLoadCount(hotCacheLoad, randomCacheLoad, "before get [1, 2] pages"); assertEquals( extractNames(bookInfo.getPages( NOW.minus(1, DAYS).truncatedTo(DAYS), @@ -156,7 +162,7 @@ public void getPagesByTimeTest(Order order) { ); assertLoadCount(hotCacheLoad, randomCacheLoad += 1, "after get [1, 2] pages"); - assertLoadCount(hotCacheLoad, randomCacheLoad, "after get [3, 4] pages"); + assertLoadCount(hotCacheLoad, randomCacheLoad, "before get [3, 4] pages"); assertEquals( extractNames(bookInfo.getPages( NOW.plus(1, DAYS).truncatedTo(DAYS) diff --git a/gradle.properties b/gradle.properties index 820f9e1b..372c2c80 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -release_version=5.4.3 +release_version=5.4.4 description='Cradle API' vcs_url=https://github.com/th2-net/cradleapi \ No newline at end of file