-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Refactor: Test suite for freshness-aware loading #15082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Core: Refactor: Test suite for freshness-aware loading #15082
Conversation
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
gaborkaszab
left a comment
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, indeed, thx
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| class RESTRequestMatcher { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to setup/teardown
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); | ||
| } | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
gaborkaszab
left a comment
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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"); | ||
| } | ||
| } |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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()
e0c8810 to
4b37afb
Compare
| && Objects.equals(req.body(), body)); | ||
| } | ||
|
|
||
| public static HTTPRequest matchesContainsHeaders( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
nastra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Moves the freshness-aware loading tests from TestRESTCatalog to their own test suite. For this there are some additional changes: