googleapis / googleapis/google-cloud-java

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

Đang mở
#12,557 3 bình luận 0 reaction 1 người được giao Được @danielduhh nhận Xem trên GitHub
api: storage type: feature request
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

#### 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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.