Skip to content

Conversation

@gaborkaszab
Copy link
Collaborator

Moves the freshness-aware loading tests from TestRESTCatalog to their own test suite. For this there are some additional changes:

  • Request matcher functions got their own util class for cross-suite usability
  • New test base for tests that launch a REST server
  • TestRESTScanPlannig shares the new test base
  • New TestRESTTableCache suite

Moves the freshness-aware loading tests from TestRESTCatalog to their
own test suite. For this there are some additional changes:
 - Request matcher functions got their own util class for cross-suite
   usability
 - New test base for tests that launch a REST server
 - TestRESTScanPlannig shares the new test base
 - New TestRESTTableCache suite
@github-actions github-actions bot added the core label Jan 19, 2026
@gaborkaszab
Copy link
Collaborator Author

This PR addresses the test-related review comments from #14398. cc @nastra Not sure what would be the best way to carry-over the comments

Copy link
Collaborator Author

@gaborkaszab gaborkaszab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed all of the comments from the other PR with one exception. I added a comment containing the original comment too.

.containsOnlyKeys(
RESTTableCache.SessionIdTableId.of(DEFAULT_SESSION_CONTEXT.sessionId(), TABLE));

assertThat(table).isNotEqualTo(metadataTable.table());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original comment: "I don't think this will ever be true anyway, because tables don't implement equals"

This checks that the table objects aren't the same.
Note, there is a similar test in testFreshnessAwareLoading too, and it's on purpose to verify that subsequent loadTable calls don't return the same table object. The intent here too but to check the same with the table object inside the metadata table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in that case you'd probably want to use isNotSameAs(..) to be more explicit here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, indeed, thx

@gaborkaszab gaborkaszab requested a review from nastra January 19, 2026 13:58
import java.util.Map;
import java.util.Objects;

class RESTRequestMatcher {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd just rename this to RequestMatcher, since the REST part could be a bit misleading given that we deal with HTTP requests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (payload instanceof RESTMessage) {
RESTMessage message = (RESTMessage) payload;
ObjectReader reader = MAPPER.readerFor(message.getClass());
if (parserContext != null && !parserContext.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really only relevant for REST scan planning. We don't have any other uses for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the general version into the base class and an override into TestRESTScanPlanning

class RESTRequestMatcher {
private RESTRequestMatcher() {}

public static HTTPRequest match(HTTPRequest.HTTPMethod method) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should all of those be called matches?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
It's a bit weird with the contains headers version: matchesContainsHeaders, matchesContainHeaders, not sure

}

@AfterEach
public void teardownCatalogs() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be singular to align with setupCatalog. The fact that there's a backing catalog is an implementation detail and doesn't have to be exposed in this method name here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just keep it more generic by having setup/teardown

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to setup/teardown

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact check style fails with these names. I renamed them to before()/after()

ImmutableMap.of());

protected InMemoryCatalog backendCatalog;
protected RESTCatalogAdapter adapterForRESTServer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I know we're calling it like this in a few places currently but I'm not sure it's actually adding value to have ForRESTServer in the name. Maybe we should just rename it to adapter here and in the method that initializes it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapter could be introduced 2 ways and I wanted to call out that this is the adapter that lives in the REST server. The other option would be when the adapter mocks the REST server and the REST client directly gets the answers from the adapter without using the server. I can rename this to adapter but in TestRESTCatalog I found it useful to have this differentiation with the naming to understand better what adapter I use in the tests.

.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid max entries: negative");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to add some additional tests that verify basic add/remove/invalidate works for that cache. We don't care about freshness-aware tables here but we really only care about testing the basic features of what the table cache is offering

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitating to keep this PR refactor only or to add new tests here. I added them now. I think that the expiration related tests in TestFreshnessAwareLoading are still relevant and should be kept. WDYT?

Copy link
Collaborator Author

@gaborkaszab gaborkaszab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look @nastra

import java.util.Map;
import java.util.Objects;

class RESTRequestMatcher {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

class RESTRequestMatcher {
private RESTRequestMatcher() {}

public static HTTPRequest match(HTTPRequest.HTTPMethod method) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
It's a bit weird with the contains headers version: matchesContainsHeaders, matchesContainHeaders, not sure

ImmutableMap.of());

protected InMemoryCatalog backendCatalog;
protected RESTCatalogAdapter adapterForRESTServer;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapter could be introduced 2 ways and I wanted to call out that this is the adapter that lives in the REST server. The other option would be when the adapter mocks the REST server and the REST client directly gets the answers from the adapter without using the server. I can rename this to adapter but in TestRESTCatalog I found it useful to have this differentiation with the naming to understand better what adapter I use in the tests.

}

@AfterEach
public void teardownCatalogs() throws Exception {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to setup/teardown

if (payload instanceof RESTMessage) {
RESTMessage message = (RESTMessage) payload;
ObjectReader reader = MAPPER.readerFor(message.getClass());
if (parserContext != null && !parserContext.isEmpty()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the general version into the base class and an override into TestRESTScanPlanning

.containsOnlyKeys(
RESTTableCache.SessionIdTableId.of(DEFAULT_SESSION_CONTEXT.sessionId(), TABLE));

assertThat(table).isNotEqualTo(metadataTable.table());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, indeed, thx

.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid max entries: negative");
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitating to keep this PR refactor only or to add new tests here. I added them now. I think that the expiration related tests in TestFreshnessAwareLoading are still relevant and should be kept. WDYT?

}

@AfterEach
public void teardownCatalogs() throws Exception {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact check style fails with these names. I renamed them to before()/after()

@gaborkaszab gaborkaszab force-pushed the main_freshness_aware_test_suite branch from e0c8810 to 4b37afb Compare January 20, 2026 10:53
&& Objects.equals(req.body(), body));
}

public static HTTPRequest matchesContainsHeaders(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that one I would just name containsHeaders

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

}

private RESTCatalog catalog(
public static RESTCatalog catalog(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestFreshnessAwareLoading has a test for the interworking between customized table ops and freshness-aware loading that uses this utility function. I didn't wan't to copy-paste the code so made some changes so that I can reach it from the other test suite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case I would just duplicate this for now and only refactor once we have 3 or more places where this is needed. I believe this is how we typically handled it in the project

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, copy-pasted and reverted the changes on the original version

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants