Skip to content
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

fix: DynamoAdmin.namespaceExists to check full namespace (not prefix) #782

Merged
merged 6 commits into from Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1142,7 +1142,7 @@ public boolean namespaceExists(String nonPrefixedNamespace) throws ExecutionExce
List<String> tableNames = listTablesResponse.tableNames();
Namespace namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace);
for (String tableName : tableNames) {
if (tableName.startsWith(namespace.prefixed())) {
if (tableName.startsWith(namespace.prefixed() + ".")) {
namespaceExists = true;
break;
}
Expand Down
Expand Up @@ -198,6 +198,23 @@ public void getTableMetadata_ShouldReturnCorrectTableMetadata() throws Execution
assertThat(actualRequest.consistentRead()).isTrue();
}

// https://github.com/scalar-labs/scalardb/issues/784
@Test
public void namespaceExists_ShouldPerformExactMatch() throws ExecutionException {
// Arrange
ListTablesResponse listTablesResponse = mock(ListTablesResponse.class);
when(client.listTables(any(ListTablesRequest.class))).thenReturn(listTablesResponse);
when(listTablesResponse.lastEvaluatedTableName()).thenReturn(null);
when(listTablesResponse.tableNames())
.thenReturn(ImmutableList.<String>builder().add(getFullTableName()).build());

// Act
// Assert
assertThat(admin.namespaceExists(NAMESPACE)).isTrue();
// compare with namespace prefix
assertThat(admin.namespaceExists(NAMESPACE.substring(0, NAMESPACE.length() - 1))).isFalse();
}

@Test
public void dropNamespace_ShouldDropAllTablesInNamespace() throws ExecutionException {
// Arrange
Expand Down