Skip to content

Commit

Permalink
[TH2-5165] bookId, name, start are unique page identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Feb 19, 2024
1 parent 66beb2a commit 10c1056
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ public Instant getRemoved() {
public PageInfo toPageInfo() {
Instant start = TimeUtils.toInstant(getStartDate(), getStartTime());
return new PageInfo(new PageId(new BookId(book), start, name),
start,
TimeUtils.toInstant(getEndDate(), getEndTime()),
name,
getComment(),
getUpdated(),
getRemoved());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,28 @@ public abstract class BaseCradleCassandraTest {
private static final List<PageInfo> DEFAULT_PAGES = List.of(
new PageInfo(
new PageId(DEFAULT_BOOK_ID, DEFAULT_DATA_START, DEFAULT_PAGE_PREFIX + 0),
DEFAULT_DATA_START,
DEFAULT_DATA_START.plus(10, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 0, ""),
DEFAULT_DATA_START.plus(10, ChronoUnit.MINUTES), ""),
new PageInfo(
new PageId(DEFAULT_BOOK_ID, DEFAULT_DATA_START.plus(10, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 1),
DEFAULT_DATA_START.plus(10, ChronoUnit.MINUTES),
DEFAULT_DATA_START.plus(20, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 1, ""),
DEFAULT_DATA_START.plus(20, ChronoUnit.MINUTES), ""),
new PageInfo(
new PageId(DEFAULT_BOOK_ID, DEFAULT_DATA_START.plus(20, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 2),
DEFAULT_DATA_START.plus(20, ChronoUnit.MINUTES),
DEFAULT_DATA_START.plus(30, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 2, ""),
DEFAULT_DATA_START.plus(30, ChronoUnit.MINUTES), ""),
new PageInfo(
new PageId(DEFAULT_BOOK_ID, DEFAULT_DATA_START.plus(30, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 3),
DEFAULT_DATA_START.plus(30, ChronoUnit.MINUTES),
DEFAULT_DATA_START.plus(40, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 3, ""),
DEFAULT_DATA_START.plus(40, ChronoUnit.MINUTES), ""),
new PageInfo(
new PageId(DEFAULT_BOOK_ID, DEFAULT_DATA_START.plus(40, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 4),
DEFAULT_DATA_START.plus(40, ChronoUnit.MINUTES),
DEFAULT_DATA_START.plus(50, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 4, ""),
DEFAULT_DATA_START.plus(50, ChronoUnit.MINUTES), ""),
new PageInfo(
new PageId(DEFAULT_BOOK_ID, DEFAULT_DATA_START.plus(50, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 5),
DEFAULT_DATA_START.plus(50, ChronoUnit.MINUTES),
DEFAULT_DATA_START.plus(60, ChronoUnit.MINUTES), DEFAULT_PAGE_PREFIX + 5, ""));
DEFAULT_DATA_START.plus(60, ChronoUnit.MINUTES), ""));


protected List<PageInfo> pages = DEFAULT_PAGES;
protected CqlSession session;
protected CassandraCradleStorage storage;
protected Instant dataStart = DEFAULT_DATA_START;
protected Instant dataEnd = DEFAULT_DATA_END;
protected BookId bookId = DEFAULT_BOOK_ID;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PagesInIntervalIteratorProviderTest {

@Test
public void defaultPageVsIncludedInterval() {
PageInfo pageInfo = new PageInfo(new PageId(bookId, Instant.EPOCH, "test-page"), Instant.EPOCH,null, "test-page", null);
PageInfo pageInfo = new PageInfo(new PageId(bookId, Instant.EPOCH, "test-page"), null, null);

assertTrue(checkInterval(pageInfo, pageInfo.getId().getStart(), Instant.now()), "in.st = p.st, in.en = p.en");
assertTrue(checkInterval(pageInfo, pageInfo.getId().getStart().plusNanos(1), Instant.now()), "in.st = p.st + 1, in.en = p.en");
Expand All @@ -46,7 +46,7 @@ public void defaultPageVsIncludedInterval() {
@Test
public void onePageVsIntervals() {
Instant now = Instant.now();
PageInfo pageInfo = new PageInfo(new PageId(bookId, now, "test-page"), now, now.plusSeconds(1), "test-page", null);
PageInfo pageInfo = new PageInfo(new PageId(bookId, now, "test-page"), now.plusSeconds(1), null);

assertTrue(checkInterval(pageInfo, pageInfo.getId().getStart(), pageInfo.getEnded()), "in.st = p.st, in.en = p.en");
assertTrue(checkInterval(pageInfo, pageInfo.getId().getStart().plusNanos(1), pageInfo.getEnded()), "in.st = p.st + 1, in.en = p.en");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ public BookInfo addPages(BookId bookId, List<PageToAdd> pages) throws CradleStor
* @param bookId ID of the book whose pages to refresh
* @return refreshed book information
* @throws CradleStorageException if given bookId is unknown
* @throws IOException if page data reading failed
*/
public BookInfo refreshPages(BookId bookId) throws CradleStorageException {
logger.info("Refreshing pages of book '{}'", bookId);
Expand Down Expand Up @@ -1604,19 +1603,15 @@ private List<PageInfo> checkAndConvertPages(List<PageToAdd> pages, BookInfo book
}

result.add(new PageInfo(new PageId(bookId, prevPage.getStart(), prevPage.getName()),
prevPage.getStart(),
checkCollisionAndGetPageEnd(book, prevPage, page.getStart()),
prevPage.getName(),
prevPage.getComment()));
}
prevPage = page;
}

if (prevPage != null) {
result.add(new PageInfo(new PageId(bookId, prevPage.getStart(), prevPage.getName()),
prevPage.getStart(),
checkCollisionAndGetPageEnd(book, prevPage, null),
prevPage.getName(),
prevPage.getComment()));
}

Expand Down
14 changes: 7 additions & 7 deletions cradle-core/src/main/java/com/exactpro/cradle/PageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ public Instant getStart() {
return start;
}

/**
* @deprecated name has been moved to {@link PageInfo#getName()}
*/
@Deprecated
public String getName()
{
return name;
Expand All @@ -62,7 +58,7 @@ public String getName()
@Override
public int hashCode()
{
return Objects.hash(bookId, start);
return Objects.hash(bookId, start, name);
}

@Override
Expand All @@ -75,13 +71,17 @@ public boolean equals(Object obj)
if (getClass() != obj.getClass())
return false;
PageId other = (PageId) obj;
return Objects.equals(bookId, other.bookId) && Objects.equals(start, other.start);
return Objects.equals(bookId, other.bookId) &&
Objects.equals(start, other.start) &&
Objects.equals(name, other.name);
}


@Override
public String toString()
{
return EscapeUtils.escape(bookId.toString())+DELIMITER+EscapeUtils.escape(start.toString());
return EscapeUtils.escape(bookId.toString())+DELIMITER+
EscapeUtils.escape(start.toString())+DELIMITER+
EscapeUtils.escape(name);
}
}
39 changes: 15 additions & 24 deletions cradle-core/src/main/java/com/exactpro/cradle/PageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,24 @@
public class PageInfo
{
private final PageId id;
private final Instant started;
private final Instant ended;
private final String name;
private final String comment;
private final Instant updated;
private final Instant removed;

public PageInfo(PageId id, Instant started, Instant ended, String name, String comment, Instant updated, Instant removed)
public PageInfo(PageId id, Instant ended, String comment, Instant updated, Instant removed)
{
this.id = id;
this.started = started;
this.ended = ended;
this.name = name;
this.comment = comment;
this.updated = updated;
this.removed = removed;
}

public PageInfo(PageId id, Instant started, Instant ended, String name, String comment)
public PageInfo(PageId id, Instant ended, String comment)
{
this.id = id;
this.started = started;
this.ended = ended;
this.name = name;
this.comment = comment;
this.updated = null;
this.removed = null;
Expand All @@ -59,24 +53,12 @@ public PageId getId()
{
return id;
}
/**
* @deprecated name has been moved to {@link PageId#getStart()}
*/
@Deprecated
public Instant getStarted()
{
return started;
}


public Instant getEnded()
{
return ended;
}

public String getName() {
return name;
}

public String getComment()
{
return comment;
Expand All @@ -90,13 +72,23 @@ public Instant getRemoved() {
return removed;
}


public Instant getStarted()
{
return id.getStart();
}

public String getName() {
return id.getName();
}

public static PageInfo ended(PageInfo page, Instant endTimestamp)
{
return page == null ? null : new PageInfo(page.getId(), page.getId().getStart(), endTimestamp, page.getName(), page.getComment(), page.getUpdated(), page.getRemoved());
return page == null ? null : new PageInfo(page.getId(), endTimestamp, page.getComment(), page.getUpdated(), page.getRemoved());
}

public boolean isValidFor(Instant timestamp) {
return (started == null || !started.isAfter(timestamp)) &&
return (getStarted() == null || !getStarted().isAfter(timestamp)) &&
(ended == null || ended.isAfter(timestamp));
}

Expand All @@ -117,7 +109,6 @@ public String toString() {
return "PageInfo{" +
"id=" + id +
", ended=" + ended +
", name='" + name + '\'' +
", comment='" + comment + '\'' +
", updated=" + updated +
", removed=" + removed +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void lazyPageAddTest() {
}
}

@SuppressWarnings("deprecation")
@Test
public void removePageTest() {
List<PageInfo> operateSource = new ArrayList<>(PAGES);
Expand Down Expand Up @@ -148,6 +147,6 @@ private static BookInfo createBookInfo(List<PageInfo> pages) {
}

private static PageInfo createPageInfo(Instant start, @Nullable Instant end) {
return new PageInfo(new PageId(BOOK_ID, start, start.toString()), start, end, "test-name", "test-comment");
return new PageInfo(new PageId(BOOK_ID, start, start.toString()), end, "test-comment");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void prepareBatch() throws CradleStorageException {
}

@DataProvider(name = "batch invalid events")
public Object[][] batchInvalidEvents() throws CradleStorageException {
public Object[][] batchInvalidEvents() {
Object[][] batchEvents = new Object[][]
{
{validEvent().parentId(null), //No parent ID
Expand Down Expand Up @@ -205,7 +205,7 @@ public void duplicateIds() throws CradleStorageException {
batch.addTestEvent(eventBuilder.id(eventId).name(DUMMY_NAME).parentId(batch.getParentId()).build());
}

@Test(expectedExceptions = {CradleStorageException.class}, expectedExceptionsMessageRegExp = ".* '.*\\:XXX' .* stored in this batch .*")
@Test(expectedExceptions = {CradleStorageException.class}, expectedExceptionsMessageRegExp = ".* '.*:XXX' .* stored in this batch .*")
public void externalReferences() throws CradleStorageException {
StoredTestEventId parentId = new StoredTestEventId(BOOK, SCOPE, START_TIMESTAMP, "1");
batch.addTestEvent(eventBuilder.id(parentId)
Expand Down Expand Up @@ -299,8 +299,6 @@ private static BookInfo createBookInfo() {
List<PageInfo> pages = List.of(new PageInfo(
new PageId(null, START_TIMESTAMP, null),
START_TIMESTAMP,
START_TIMESTAMP,
null,
null)
);
return new BookInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ private static BookInfo createBookInfo() {
List<PageInfo> pages = List.of(new PageInfo(
new PageId(null, START_TIMESTAMP, null),
START_TIMESTAMP,
START_TIMESTAMP,
null,
null)
);
return new BookInfo(
Expand Down

0 comments on commit 10c1056

Please sign in to comment.