googleapis / googleapis/google-cloud-java

[java-storage-nio] Storage: FakeStorageRpc states it supports generations, but generationMatch option unsupported on Blob creation.

Offen
#12,557 3 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @danielduhh Auf GitHub ansehen
api: storage type: feature request
Vorherrschende Sprache
Java
Sterne
2.1k
Forks
1.2k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
154

Beschreibung

#### Environment details

1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
General, Core, and Other are also allowed as types
2. OS type and version: Debian 11
3. Java version: 11
4. storage_nio version(s): HEAD

#### Steps to reproduce

1. Init `Storage` using `LocalStorageHelper`.
2. Call `create` with `BlobInfo` and `BlobTargetOption.generationMatch`.

#### Code example

```kotlin
val bucketName = "bucket"
val blobKey = "blob-key"
val storage = LocalStorageHelper.getOptions().service
storage.create(
BlobInfo.newBuilder(bucketName, blobKey, 0L).build(),
Storage.BlobTargetOption.generationMatch()
)
```

#### Stack trace
```
java.lang.UnsupportedOperationException
com.google.cloud.storage.StorageException:
at com.google.cloud.storage.StorageException.translateAndThrow(StorageException.java:81)
at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:229)
at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:157)
```

```
Caused by:
at com.google.cloud.storage.contrib.nio.testing.FakeStorageRpc.potentiallyThrow(FakeStorageRpc.java:446)
at com.google.cloud.storage.contrib.nio.testing.FakeStorageRpc.create(FakeStorageRpc.java:96)
at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:221)
at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:218)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:217)
... 40 more
```

#### External references such as API reference guides

https://github.com/googleapis/java-storage-nio/blob/main/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java

#### Any additional information below

`FakeStorageRpc` appears to handle generations for some operations using the `checkGeneration` private method. For Blob `create` however, it just calls `potentiallyThrow`. It seems like it should be a relatively simple change to check the generation if the appropriate option is set, with two wrinkles:
1. What should the behavior be w.r.t. `throwIfOption`? Should it still throw for any option, or just unsupported ones?
2. What's the right error code? Currently `checkGeneration` uses 404, but that's likely not correct for `create`. Does the real Cloud Storage implementation return [412 - Precondition failed](https://cloud.google.com/storage/docs/json_api/v1/status-codes#412_Precondition_Failed) in this case?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.