googleapis / googleapis/google-cloud-java

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

Abierto
#12,557 3 comentarios 0 reacciones 1 asignado Reclamado por @danielduhh Ver en GitHub
api: storage type: feature request
Lenguaje dominante
Java
Estrellas
2.1k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
154

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.