-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Adjust namespace separator in TestRESTCatalog #14808
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
Core: Adjust namespace separator in TestRESTCatalog #14808
Conversation
|
When we get the path in the REST catalog tests we use e.g. |
|
cc @nastra as the owner of the configurable namespace separator change |
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
31d1ba0 to
019e40f
Compare
019e40f to
bb52da6
Compare
| catalog.createTable(table, SCHEMA); | ||
|
|
||
| ResourcePaths paths = ResourcePaths.forCatalogProperties(ImmutableMap.of()); | ||
| assertThat(paths.tables(ns)) |
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.
it seems like what you're really trying to test is
@Test
public void nestedNamespaceWithLegacyAndNewSeparator() {
Namespace namespace = Namespace.of("first", "second", "third");
String legacySeparator = RESTUtil.NAMESPACE_SEPARATOR_URLENCODED_UTF_8;
String newSeparator = "%2E";
// legacy separator is always used by default, so no need to configure it
ResourcePaths withLegacySeparator = ResourcePaths.forCatalogProperties(ImmutableMap.of());
ResourcePaths withNewSeparator =
ResourcePaths.forCatalogProperties(
ImmutableMap.of(RESTCatalogProperties.NAMESPACE_SEPARATOR, newSeparator));
// old client would call encodeNamespace without specifying a separator when constructing a
// resource path
String legacyEncodedNamespace = RESTUtil.encodeNamespace(namespace);
assertThat(withLegacySeparator.namespace(namespace))
.contains(legacyEncodedNamespace)
.contains(legacySeparator);
// old client would decode without specifying the separator
assertThat(RESTUtil.decodeNamespace(legacyEncodedNamespace)).isEqualTo(namespace);
// new server would decode the namespace using the new separator
assertThat(RESTUtil.decodeNamespace(legacyEncodedNamespace, newSeparator)).isEqualTo(namespace);
// new client would call encodeNamespace with specifying a separator when constructing a
// resource path
String newEncodedSeparator = RESTUtil.encodeNamespace(namespace, newSeparator);
assertThat(withNewSeparator.namespace(namespace))
.contains(newEncodedSeparator)
.contains(newSeparator);
// new server would decode the namespace using the new separator
assertThat(RESTUtil.decodeNamespace(newEncodedSeparator, newSeparator)).isEqualTo(namespace);
}
In that case the test should probably live in TestResourcePaths
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.
@gaborkaszab can you also add ^ to TestResourcePaths
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. I've split this into 2
bb52da6 to
b6da4d9
Compare
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
|
|
||
| RESTCatalog catalog = catalog(adapter); | ||
|
|
||
| // Do verification with paths using the default namespace separator. |
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.
| // Do verification with paths using the default namespace separator. | |
| // Do verification with paths using the legacy namespace separator. |
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 with the suggested naming, I think this comment is redundant, so I'm removing it.
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
|
|
||
| @Test | ||
| public void testClientNamespaceSeparatorOverridden() { | ||
| RESTCatalogAdapter adapter = Mockito.spy(new RESTCatalogAdapter(backendCatalog)); |
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 a comment that says that the server now always sends back the separator in the config response so that this is clear 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.
Done. I added an extra check also to verify the override is sent by the adapter. Makes the test more future proof, however, this may be an overkill. Let me know and I'll remove the check
|
|
||
| catalog.createNamespace(nestedNamespace); | ||
|
|
||
| catalog.createTable(table, SCHEMA); |
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.
we don't really need the table creation 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.
I use this so that I can also verify that the paths use the desired namespace separators. I know you've commented that it rather belongs to TestResourcePaths, but in general I think whenever an end-to-end scenario is easy to do, it makes sense to add test coverage there (besides narrower unit testing). In this case it's pretty simple to cover, and add more test coverage not just to ResourcePaths but also to the RESTCatalog code around creating and using the paths. This gives use more complete tests here: the paths and the params together.
b6da4d9 to
8c040b8
Compare
| ConfigResponse configResponse = (ConfigResponse) invocation.callRealMethod(); | ||
|
|
||
| assertThat(configResponse.overrides()) | ||
| .contains( |
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 can just use containsEntry(...) directly 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.
Done
The resource paths used for comparisons in the REST catalog test use different namespace separator than the test REST catalogs. This PR brings them in line.
8c040b8 to
d379d99
Compare
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 looking, @nastra !
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
| ConfigResponse configResponse = (ConfigResponse) invocation.callRealMethod(); | ||
|
|
||
| assertThat(configResponse.overrides()) | ||
| .contains( |
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
|
|
||
| RESTCatalog catalog = catalog(adapter); | ||
|
|
||
| // Do verification with paths using the default namespace separator. |
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 with the suggested naming, I think this comment is redundant, so I'm removing it.
| catalog.createTable(table, SCHEMA); | ||
|
|
||
| ResourcePaths paths = ResourcePaths.forCatalogProperties(ImmutableMap.of()); | ||
| assertThat(paths.tables(ns)) |
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. I've split this into 2
core/src/test/java/org/apache/iceberg/rest/TestResourcePaths.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestResourcePaths.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
Outdated
Show resolved
Hide resolved
|
Thanks for reviewing, @nastra ! |
The resource paths used for comparisons in the REST catalog test use different namespace separator than the test REST catalogs. This PR brings them in line.