Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aihuaxu committed Aug 27, 2024
1 parent d68751a commit 81440a4
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*/
public abstract class LocalPolarisMetaStoreManagerFactory<StoreType>
implements MetaStoreManagerFactory {

final Map<String, PolarisMetaStoreManager> metaStoreManagerMap = new HashMap<>();
final Map<String, StorageCredentialCache> storageCredentialCacheMap = new HashMap<>();
final Map<String, StoreType> backingStoreMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;
import org.apache.polaris.core.admin.model.AwsStorageConfigInfo;
import org.apache.polaris.core.admin.model.Catalog;
import org.apache.polaris.core.admin.model.CatalogProperties;
Expand All @@ -43,12 +42,8 @@
import org.apache.polaris.service.config.PolarisApplicationConfig;
import org.apache.polaris.service.test.PolarisConnectionExtension;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;

@ExtendWith({DropwizardExtensionsSupport.class, PolarisConnectionExtension.class})
public class PolarisOverlappingCatalogTest {
Expand Down Expand Up @@ -119,72 +114,101 @@ private Response createCatalog(
}
}

@ParameterizedTest
@ArgumentsSource(OverlappingCatalogArgs.class)
public void testBasicOverlappingCatalogs(boolean initiallyExternal, boolean laterExternal) {
String prefix = UUID.randomUUID().toString();

assertThat(createCatalog(prefix, "root", initiallyExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// OK, non-overlapping
assertThat(createCatalog(prefix, "boot", laterExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// OK, non-overlapping due to no `/`
assertThat(createCatalog(prefix, "roo", laterExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// Also OK due to no `/`
assertThat(createCatalog(prefix, "root.child", laterExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// inside `root`
assertThat(createCatalog(prefix, "root/child", laterExternal))
.returns(Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);

// `root` is inside this
assertThat(createCatalog(prefix, "", laterExternal))
.returns(Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);
@Test
public void testBasicOverlappingCatalogs() {
Arrays.asList(false, true)
.forEach(
initiallyExternal -> {
Arrays.asList(false, true)
.forEach(
laterExternal -> {
String prefix = UUID.randomUUID().toString();

assertThat(createCatalog(prefix, "root", initiallyExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// OK, non-overlapping
assertThat(createCatalog(prefix, "boot", laterExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// OK, non-overlapping due to no `/`
assertThat(createCatalog(prefix, "roo", laterExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// Also OK due to no `/`
assertThat(createCatalog(prefix, "root.child", laterExternal))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// inside `root`
assertThat(createCatalog(prefix, "root/child", laterExternal))
.returns(
Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);

// `root` is inside this
assertThat(createCatalog(prefix, "", laterExternal))
.returns(
Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);
});
});
}

@ParameterizedTest
@ArgumentsSource(OverlappingCatalogArgs.class)
public void testAllowedLocationOverlappingCatalogs(
boolean initiallyExternal, boolean laterExternal) {

String prefix = UUID.randomUUID().toString();

assertThat(createCatalog(prefix, "animals", initiallyExternal, Arrays.asList("dogs", "cats")))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// OK, non-overlapping
assertThat(createCatalog(prefix, "danimals", laterExternal, Arrays.asList("dan", "daniel")))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// This DBL overlaps with initial AL
assertThat(createCatalog(prefix, "dogs", initiallyExternal, Arrays.asList("huskies", "labs")))
.returns(Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);

// This AL overlaps with initial DBL
assertThat(
createCatalog(
prefix, "kingdoms", initiallyExternal, Arrays.asList("plants", "animals")))
.returns(Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);

// This AL overlaps with an initial AL
assertThat(createCatalog(prefix, "plays", initiallyExternal, Arrays.asList("rent", "cats")))
.returns(Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);
}

private static class OverlappingCatalogArgs implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
return Stream.of(
Arguments.of(true, true),
Arguments.of(true, false),
Arguments.of(false, true),
Arguments.of(false, false));
}
@Test
public void testAllowedLocationOverlappingCatalogs() {
Arrays.asList(false, true)
.forEach(
initiallyExternal -> {
Arrays.asList(false, true)
.forEach(
laterExternal -> {
String prefix = UUID.randomUUID().toString();

assertThat(
createCatalog(
prefix,
"animals",
initiallyExternal,
Arrays.asList("dogs", "cats")))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// OK, non-overlapping
assertThat(
createCatalog(
prefix,
"danimals",
laterExternal,
Arrays.asList("dan", "daniel")))
.returns(Response.Status.CREATED.getStatusCode(), Response::getStatus);

// This DBL overlaps with initial AL
assertThat(
createCatalog(
prefix,
"dogs",
initiallyExternal,
Arrays.asList("huskies", "labs")))
.returns(
Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);

// This AL overlaps with initial DBL
assertThat(
createCatalog(
prefix,
"kingdoms",
initiallyExternal,
Arrays.asList("plants", "animals")))
.returns(
Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);

// This AL overlaps with an initial AL
assertThat(
createCatalog(
prefix,
"plays",
initiallyExternal,
Arrays.asList("rent", "cats")))
.returns(
Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static String getTestRealm(Class testClassName) {

public static void createTestDir(String realm) throws IOException {
// Set up the database location
Path testDir = Path.of("build/test_data/iceberg/" + realm);
Path testDir = Path.of("build/test_data/polaris/" + realm);
if (Files.exists(testDir)) {
if (Files.isDirectory(testDir)) {
Files.walk(testDir)
Expand Down

0 comments on commit 81440a4

Please sign in to comment.