Skip to content

Commit

Permalink
check tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio Trettenero committed Dec 4, 2024
1 parent 6eb29c3 commit 612b0b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ create table TBLS (
created_date TIMESTAMP not null,
last_updated_by STRING(255),
last_updated_date TIMESTAMP not null,
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE
foreign key (db_name) references DBS(name) ON UPDATE CASCADE
);
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na
try {
this.polarisStoreService.deleteDatabase(name.getDatabaseName());
} catch (DataIntegrityViolationException exception) {
if (exception.getCause() instanceof org.hibernate.exception.ConstraintViolationException) {
throw new InvalidMetaException(name, "Cannot delete database because it still contains tables.", exception);
}
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
throw new ConnectorException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.netflix.metacat.common.server.connectors.ConnectorRequestContext;
import com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException;
import com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException;
import com.netflix.metacat.common.server.connectors.exception.InvalidMetaException;
import com.netflix.metacat.common.server.connectors.model.AuditInfo;
import com.netflix.metacat.common.server.connectors.model.DatabaseInfo;
import com.netflix.metacat.common.server.connectors.model.TableInfo;
Expand Down Expand Up @@ -213,7 +214,12 @@ public void testDeleteDbNoCascades() {
polarisTableService.create(requestContext, tableInfo);
Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName));

polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME);
// Expect an InvalidMetaException when trying to delete a non-empty database
Assertions.assertThrows(InvalidMetaException.class, () -> {
polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME);
});

// Ensure the database still exists after the failed delete attempt
Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME));
}
}
Expand Down

0 comments on commit 612b0b3

Please sign in to comment.