Repository navigation
feat(storage): add delete object contexts sample - #14794
Draft
sahusneha2004 wants to merge 1 commit into
Draft
sahusneha2004 wants to merge 1 commit into
sahusneha2004 wants to merge 1 commit into
Conversation
Adds DeleteObjectContexts sample (region tag storage_delete_object_contexts) that clears all custom contexts on an object with a precondition, plus an integration test. Internal bug: b/482946642 [Generated-by: AI]
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces the DeleteObjectContexts class to delete all custom contexts of a Google Cloud Storage object by setting them to an empty map, and adds a corresponding integration test. The feedback recommends replacing JUnit's assertTrue with Google Truth's assertThat in the test assertion to ensure consistency with the rest of the test suite.
|
|
||
| Blob updatedBlob = storage.get(bucket.getName(), blobName); | ||
| ObjectContexts contexts = updatedBlob.getContexts(); | ||
| assertTrue(contexts == null || contexts.getCustom().isEmpty()); |
Contributor
There was a problem hiding this comment.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
DeleteObjectContextssample (region tagstorage_delete_object_contexts) for java-storage that removes all custom object contexts from an existing object, plus an integration test (ITObjectSnippets#testDeleteObjectContexts).This completes the object-contexts sample set for Java (set / get / list already exist; delete-all was previously only shown as a comment inside
SetObjectContexts.java).What it does
storage.get(BlobId)).ObjectContextswith an empty custom map and applies it viablob.toBuilder().setContexts(...).storage.update(..., BlobTargetOption.generationMatch())(same precondition style asSetObjectContexts).Deleted all custom contexts for object <object> in bucket <bucket>.SDK mechanism note (verified in library source)
ObjectContexts.Builder.setCustom(null)is normalized toImmutableMap.of()(BlobInfo.java), so an empty map andnullare equivalent.BlobInfo.BuilderImpl.setContextsdiffs the new map against the fetched blob's contexts (Utils.diffMaps) and, when the new map is empty, records a per-key modified fieldcontexts.custom.<key>for every existing key. These are sent as deletions over JSON ({"contexts":{"custom":{"<key>":null,...}}}) and asupdate_maskpaths over gRPC. The library's ownITNestedUpdateMaskTest("1 key, set empty") covers this on both transports. The sample uses the explicit empty map for clarity, and the builder is derived from the fetched blob (required for the diff to produce deletions).Test
ITObjectSnippets#testDeleteObjectContexts: uploads an object, sets a context viaSetObjectContexts, asserts it is present, runsDeleteObjectContexts, asserts stdout containsDeleted all custom contexts for object <name>and that the re-read object's contexts are null/empty.Local validation not run (mvn/java unavailable in the agent sandbox); relying on CI for fmt/checkstyle and samples ITs.
Internal bug: b/482946642
[Generated-by: AI]