From f00ea1cc3ddcb43d4276ccc3609906c0a8589f8a Mon Sep 17 00:00:00 2001 From: BenWhitehead Date: Mon, 16 Sep 2024 14:54:05 -0400 Subject: [PATCH] fix: remove server unimplemented GrpcStorageImpl#{get,list,create,delete}Notification Partial revert of 830052b3 --- .../google/cloud/storage/GrpcConversions.java | 61 ------------ .../google/cloud/storage/GrpcStorageImpl.java | 93 +----------------- .../google/cloud/storage/JsonConversions.java | 7 -- .../google/cloud/storage/Notification.java | 6 -- .../cloud/storage/NotificationInfo.java | 24 ----- .../com/google/cloud/storage/Storage.java | 8 +- .../java/com/google/cloud/storage/Utils.java | 20 ---- .../storage/NotificationInfoPropertyTest.java | 23 ----- .../cloud/storage/it/ITNotificationTest.java | 11 +-- .../jqwik/NotificationArbitraryProvider.java | 94 ------------------- .../net.jqwik.api.providers.ArbitraryProvider | 1 - 11 files changed, 11 insertions(+), 337 deletions(-) delete mode 100644 google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoPropertyTest.java delete mode 100644 google-cloud-storage/src/test/java/com/google/cloud/storage/jqwik/NotificationArbitraryProvider.java diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java index 63a33b80a1..7396e0ae69 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java @@ -21,7 +21,6 @@ import static com.google.cloud.storage.Utils.ifNonNull; import static com.google.cloud.storage.Utils.lift; import static com.google.cloud.storage.Utils.projectNameCodec; -import static com.google.cloud.storage.Utils.topicNameCodec; import com.google.api.pathtemplate.PathTemplate; import com.google.cloud.Binding; @@ -37,8 +36,6 @@ import com.google.cloud.storage.BucketInfo.PublicAccessPrevention; import com.google.cloud.storage.Conversions.Codec; import com.google.cloud.storage.HmacKey.HmacKeyState; -import com.google.cloud.storage.NotificationInfo.EventType; -import com.google.cloud.storage.NotificationInfo.PayloadFormat; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -52,8 +49,6 @@ import com.google.storage.v2.BucketAccessControl; import com.google.storage.v2.CryptoKeyName; import com.google.storage.v2.HmacKeyMetadata; -import com.google.storage.v2.NotificationConfig; -import com.google.storage.v2.NotificationConfigName; import com.google.storage.v2.Object; import com.google.storage.v2.ObjectAccessControl; import com.google.storage.v2.ObjectChecksums; @@ -107,8 +102,6 @@ final class GrpcConversions { Codec.of(this::blobIdEncode, this::blobIdDecode); private final Codec blobInfoCodec = Codec.of(this::blobInfoEncode, this::blobInfoDecode); - private final Codec - notificationInfoCodec = Codec.of(this::notificationEncode, this::notificationDecode); private final Codec policyCodec = Codec.of(this::policyEncode, this::policyDecode); private final Codec bindingCodec = @@ -219,10 +212,6 @@ Codec blobInfo() { return blobInfoCodec; } - Codec notificationInfo() { - return notificationInfoCodec; - } - Codec policyCodec() { return policyCodec; } @@ -1003,56 +992,6 @@ private BlobInfo blobInfoDecode(Object from) { return toBuilder.build(); } - private NotificationConfig notificationEncode(NotificationInfo from) { - NotificationConfig.Builder to = NotificationConfig.newBuilder(); - String id = from.getNotificationId(); - if (id != null) { - if (NotificationConfigName.isParsableFrom(id)) { - ifNonNull(id, to::setName); - } else { - NotificationConfigName name = NotificationConfigName.of("_", from.getBucket(), id); - to.setName(name.toString()); - } - } - ifNonNull(from.getTopic(), topicNameCodec::encode, to::setTopic); - ifNonNull(from.getEtag(), to::setEtag); - ifNonNull(from.getEventTypes(), toImmutableListOf(EventType::name), to::addAllEventTypes); - ifNonNull(from.getCustomAttributes(), to::putAllCustomAttributes); - ifNonNull(from.getObjectNamePrefix(), to::setObjectNamePrefix); - ifNonNull(from.getPayloadFormat(), PayloadFormat::name, to::setPayloadFormat); - return to.build(); - } - - private NotificationInfo notificationDecode(NotificationConfig from) { - NotificationInfo.Builder to = - NotificationInfo.newBuilder(topicNameCodec.decode(from.getTopic())); - if (!from.getName().isEmpty()) { - NotificationConfigName parse = NotificationConfigName.parse(from.getName()); - // the case where parse could return null is already guarded by the preceding isEmpty check - //noinspection DataFlowIssue - to.setNotificationId(parse.getNotificationConfig()); - to.setBucket(parse.getBucket()); - } - if (!from.getEtag().isEmpty()) { - to.setEtag(from.getEtag()); - } - if (!from.getEventTypesList().isEmpty()) { - EventType[] eventTypes = - from.getEventTypesList().stream().map(EventType::valueOf).toArray(EventType[]::new); - to.setEventTypes(eventTypes); - } - if (!from.getCustomAttributesMap().isEmpty()) { - to.setCustomAttributes(from.getCustomAttributesMap()); - } - if (!from.getObjectNamePrefix().isEmpty()) { - to.setObjectNamePrefix(from.getObjectNamePrefix()); - } - if (!from.getPayloadFormat().isEmpty()) { - to.setPayloadFormat(PayloadFormat.valueOf(from.getPayloadFormat())); - } - return to.build(); - } - private com.google.iam.v1.Policy policyEncode(Policy from) { com.google.iam.v1.Policy.Builder to = com.google.iam.v1.Policy.newBuilder(); ifNonNull(from.getEtag(), byteStringB64StringCodec::decode, to::setEtag); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java index f01d4f7614..35ba536aef 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java @@ -82,21 +82,14 @@ import com.google.storage.v2.ComposeObjectRequest; import com.google.storage.v2.ComposeObjectRequest.SourceObject; import com.google.storage.v2.CreateBucketRequest; -import com.google.storage.v2.CreateNotificationConfigRequest; import com.google.storage.v2.DeleteBucketRequest; -import com.google.storage.v2.DeleteNotificationConfigRequest; import com.google.storage.v2.DeleteObjectRequest; import com.google.storage.v2.GetBucketRequest; -import com.google.storage.v2.GetNotificationConfigRequest; import com.google.storage.v2.GetObjectRequest; import com.google.storage.v2.ListBucketsRequest; -import com.google.storage.v2.ListNotificationConfigsRequest; -import com.google.storage.v2.ListNotificationConfigsResponse; import com.google.storage.v2.ListObjectsRequest; import com.google.storage.v2.ListObjectsResponse; import com.google.storage.v2.LockBucketRetentionPolicyRequest; -import com.google.storage.v2.NotificationConfig; -import com.google.storage.v2.NotificationConfigName; import com.google.storage.v2.Object; import com.google.storage.v2.ObjectAccessControl; import com.google.storage.v2.ReadObjectRequest; @@ -104,7 +97,6 @@ import com.google.storage.v2.RewriteObjectRequest; import com.google.storage.v2.RewriteResponse; import com.google.storage.v2.StorageClient; -import com.google.storage.v2.StorageClient.ListNotificationConfigsPage; import com.google.storage.v2.UpdateBucketRequest; import com.google.storage.v2.UpdateObjectRequest; import com.google.storage.v2.WriteObjectRequest; @@ -1393,96 +1385,23 @@ public ServiceAccount getServiceAccount(String projectId) { @Override public Notification createNotification(String bucket, NotificationInfo notificationInfo) { - NotificationConfig encode = codecs.notificationInfo().encode(notificationInfo); - CreateNotificationConfigRequest req = - CreateNotificationConfigRequest.newBuilder() - .setParent(bucketNameCodec.encode(bucket)) - .setNotificationConfig(encode) - .build(); - GrpcCallContext retryContext = Retrying.newCallContext(); - return Retrying.run( - getOptions(), - retryAlgorithmManager.getFor(req), - () -> storageClient.createNotificationConfigCallable().call(req, retryContext), - syntaxDecoders.notificationConfig); + return throwHttpJsonOnly( + fmtMethodName("createNotification", String.class, NotificationInfo.class)); } @Override public Notification getNotification(String bucket, String notificationId) { - String name; - if (NotificationConfigName.isParsableFrom(notificationId)) { - name = notificationId; - } else { - NotificationConfigName configName = NotificationConfigName.of("_", bucket, notificationId); - name = configName.toString(); - } - GetNotificationConfigRequest req = - GetNotificationConfigRequest.newBuilder().setName(name).build(); - GrpcCallContext retryContext = Retrying.newCallContext(); - return Retrying.run( - getOptions(), - retryAlgorithmManager.getFor(req), - () -> { - try { - return storageClient.getNotificationConfigCallable().call(req, retryContext); - } catch (NotFoundException e) { - return null; - } - }, - syntaxDecoders.notificationConfig); + return throwHttpJsonOnly(fmtMethodName("getNotification", String.class, String.class)); } @Override public List listNotifications(String bucket) { - ListNotificationConfigsRequest req = - ListNotificationConfigsRequest.newBuilder() - .setParent(bucketNameCodec.encode(bucket)) - .build(); - ResultRetryAlgorithm algorithm = retryAlgorithmManager.getFor(req); - GrpcCallContext retryContext = Retrying.newCallContext(); - return Retrying.run( - getOptions(), - algorithm, - () -> storageClient.listNotificationConfigsPagedCallable().call(req, retryContext), - resp -> { - TransformingPageDecorator< - ListNotificationConfigsRequest, - ListNotificationConfigsResponse, - NotificationConfig, - ListNotificationConfigsPage, - Notification> - page = - new TransformingPageDecorator<>( - resp.getPage(), syntaxDecoders.notificationConfig, getOptions(), algorithm); - return ImmutableList.copyOf(page.iterateAll()); - }); + return throwHttpJsonOnly(fmtMethodName("listNotifications", String.class)); } @Override public boolean deleteNotification(String bucket, String notificationId) { - String name; - if (NotificationConfigName.isParsableFrom(notificationId)) { - name = notificationId; - } else { - NotificationConfigName configName = NotificationConfigName.of("_", bucket, notificationId); - name = configName.toString(); - } - DeleteNotificationConfigRequest req = - DeleteNotificationConfigRequest.newBuilder().setName(name).build(); - GrpcCallContext retryContext = Retrying.newCallContext(); - return Boolean.TRUE.equals( - Retrying.run( - getOptions(), - retryAlgorithmManager.getFor(req), - () -> { - try { - storageClient.deleteNotificationConfigCallable().call(req, retryContext); - return true; - } catch (NotFoundException e) { - return false; - } - }, - Decoder.identity())); + return throwHttpJsonOnly(fmtMethodName("deleteNotification", String.class, String.class)); } @BetaApi @@ -1519,8 +1438,6 @@ private final class SyntaxDecoders { o -> codecs.blobInfo().decode(o).asBlob(GrpcStorageImpl.this); final Decoder bucket = b -> codecs.bucketInfo().decode(b).asBucket(GrpcStorageImpl.this); - final Decoder notificationConfig = - n -> codecs.notificationInfo().decode(n).asNotification(GrpcStorageImpl.this); } /** diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java index 274441436a..12562cb020 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java @@ -94,11 +94,6 @@ final class JsonConversions { // when converting from gRPC to apiary or vice-versa we want to preserve this property. Until // such a time as the apiary model has a project field, we manually apply it with this name. private static final String PROJECT_ID_FIELD_NAME = "x_project"; - // gRPC has a NotificationConfig.name property which contains the bucket the config is associated - // with which that apiary doesn't have yet. - // when converting from gRPC to apiary or vice-versa we want to preserve this property. Until - // such a time as the apiary model has a bucket field, we manually apply it with this name. - private static final String NOTIFICATION_BUCKET_FIELD_NAME = "x_bucket"; private final Codec entityCodec = Codec.of(this::entityEncode, this::entityDecode); @@ -882,7 +877,6 @@ private com.google.api.services.storage.model.Notification notificationEncode( to.setEtag(from.getEtag()); to.setSelfLink(from.getSelfLink()); to.setTopic(from.getTopic()); - ifNonNull(from.getBucket(), b -> to.set(NOTIFICATION_BUCKET_FIELD_NAME, b)); ifNonNull(from.getNotificationId(), to::setId); ifNonNull(from.getCustomAttributes(), to::setCustomAttributes); ifNonNull(from.getObjectNamePrefix(), to::setObjectNamePrefix); @@ -922,7 +916,6 @@ private BucketInfo.HierarchicalNamespace hierarchicalNamespaceDecode( private NotificationInfo notificationDecode( com.google.api.services.storage.model.Notification from) { NotificationInfo.Builder builder = new NotificationInfo.BuilderImpl(from.getTopic()); - ifNonNull(from.get(NOTIFICATION_BUCKET_FIELD_NAME), String.class::cast, builder::setBucket); ifNonNull(from.getId(), builder::setNotificationId); ifNonNull(from.getEtag(), builder::setEtag); ifNonNull(from.getCustomAttributes(), builder::setCustomAttributes); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Notification.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Notification.java index f3e0738d5c..bb6d2747d4 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Notification.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Notification.java @@ -89,12 +89,6 @@ public Builder setCustomAttributes(Map customAttributes) { return this; } - @Override - Builder setBucket(String bucket) { - infoBuilder.setBucket(bucket); - return this; - } - @Override public Notification build() { return new Notification(storage, infoBuilder); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java index 7bf1477908..58621577db 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/NotificationInfo.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.api.core.InternalApi; import com.google.api.pathtemplate.PathTemplate; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -35,13 +34,11 @@ public class NotificationInfo implements Serializable { private static final PathTemplate PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}"); - // TODO: Change to StringEnum in next major version public enum PayloadFormat { JSON_API_V1, NONE } - // TODO: Change to StringEnum in next major version public enum EventType { OBJECT_FINALIZE, OBJECT_METADATA_UPDATE, @@ -57,7 +54,6 @@ public enum EventType { private final String objectNamePrefix; private final String etag; private final String selfLink; - private final String bucket; /** Builder for {@code NotificationInfo}. */ public abstract static class Builder { @@ -79,8 +75,6 @@ public abstract static class Builder { public abstract Builder setCustomAttributes(Map customAttributes); - abstract Builder setBucket(String bucket); - /** Creates a {@code NotificationInfo} object. */ public abstract NotificationInfo build(); } @@ -96,7 +90,6 @@ public static class BuilderImpl extends Builder { private String objectNamePrefix; private String etag; private String selfLink; - private String bucket; BuilderImpl(String topic) { this.topic = topic; @@ -111,7 +104,6 @@ public static class BuilderImpl extends Builder { customAttributes = notificationInfo.customAttributes; payloadFormat = notificationInfo.payloadFormat; objectNamePrefix = notificationInfo.objectNamePrefix; - bucket = notificationInfo.bucket; } @Override @@ -164,12 +156,6 @@ public Builder setCustomAttributes(Map customAttributes) { return this; } - @Override - Builder setBucket(String bucket) { - this.bucket = bucket; - return this; - } - public NotificationInfo build() { checkNotNull(topic); checkTopicFormat(topic); @@ -186,7 +172,6 @@ public NotificationInfo build() { customAttributes = builder.customAttributes; payloadFormat = builder.payloadFormat; objectNamePrefix = builder.objectNamePrefix; - bucket = builder.bucket; } /** Returns the service-generated id for the notification. */ @@ -240,15 +225,6 @@ public Map getCustomAttributes() { return customAttributes; } - /** - * gRPC has the bucket name encoded in the notification name, use this internal property to track - * it. - */ - @InternalApi - String getBucket() { - return bucket; - } - @Override public int hashCode() { return Objects.hash( diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 5bb3c15d46..0729b47225 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -4805,7 +4805,7 @@ List testIamPermissions( * @return the created notification * @throws StorageException upon failure */ - @TransportCompatibility({Transport.HTTP, Transport.GRPC}) + @TransportCompatibility({Transport.HTTP}) Notification createNotification(String bucket, NotificationInfo notificationInfo); /** @@ -4824,7 +4824,7 @@ List testIamPermissions( * @return the {@code Notification} object with the given id or {@code null} if not found * @throws StorageException upon failure */ - @TransportCompatibility({Transport.HTTP, Transport.GRPC}) + @TransportCompatibility({Transport.HTTP}) Notification getNotification(String bucket, String notificationId); /** @@ -4841,7 +4841,7 @@ List testIamPermissions( * @return a list of {@link Notification} objects added to the bucket. * @throws StorageException upon failure */ - @TransportCompatibility({Transport.HTTP, Transport.GRPC}) + @TransportCompatibility({Transport.HTTP}) List listNotifications(String bucket); /** @@ -4865,7 +4865,7 @@ List testIamPermissions( * @return {@code true} if the notification has been deleted, {@code false} if not found * @throws StorageException upon failure */ - @TransportCompatibility({Transport.HTTP, Transport.GRPC}) + @TransportCompatibility({Transport.HTTP}) boolean deleteNotification(String bucket, String notificationId); /** diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Utils.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Utils.java index 6359ec5d13..853294c1f3 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Utils.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Utils.java @@ -172,26 +172,6 @@ final class Utils { } }); - private static final String PUBSUB_PREFIX = "//pubsub.googleapis.com/"; - static final Codec topicNameCodec = - Codec.of( - topic -> { - requireNonNull(topic, "topic must be non null"); - if (topic.startsWith(PUBSUB_PREFIX)) { - return topic; - } else { - return PUBSUB_PREFIX + topic; - } - }, - resourceName -> { - requireNonNull(resourceName, "resourceName must be non null"); - if (resourceName.startsWith(PUBSUB_PREFIX)) { - return resourceName.substring(PUBSUB_PREFIX.length()); - } else { - return resourceName; - } - }); - static final Codec crc32cCodec = Codec.of(Utils::crc32cEncode, Utils::crc32cDecode); diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoPropertyTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoPropertyTest.java deleted file mode 100644 index 5a20dfc60a..0000000000 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/NotificationInfoPropertyTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.storage; - -import com.google.storage.v2.NotificationConfig; - -final class NotificationInfoPropertyTest - extends BaseConvertablePropertyTest< - NotificationInfo, NotificationConfig, com.google.api.services.storage.model.Notification> {} diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITNotificationTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITNotificationTest.java index 69a0665803..d0c41f5d56 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITNotificationTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITNotificationTest.java @@ -47,8 +47,8 @@ @RunWith(StorageITRunner.class) @CrossRun( - transports = {Transport.HTTP, Transport.GRPC}, - backends = {Backend.PROD, Backend.TEST_BENCH}) + transports = {Transport.HTTP}, + backends = {Backend.PROD}) public class ITNotificationTest { private static final Notification.PayloadFormat PAYLOAD_FORMAT = PayloadFormat.JSON_API_V1; private static final Map CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1"); @@ -116,7 +116,6 @@ public void cleanup() { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void listNotification_doesNotExist() throws Exception { // create a temporary bucket to ensure we're immune from ordering on other tests try (TemporaryBucket tempB = @@ -130,7 +129,6 @@ public void listNotification_doesNotExist() throws Exception { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void listNotification_exists() { Notification notification = storage.createNotification(bucket.getName(), notificationInfo); List notifications = storage.listNotifications(bucket.getName()); @@ -139,7 +137,6 @@ public void listNotification_exists() { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void createNotification_doesNotExist() throws Exception { Notification notification = storage.createNotification(bucket.getName(), notificationInfo); assertAll( @@ -150,7 +147,6 @@ public void createNotification_doesNotExist() throws Exception { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void getNotification_exists() throws Exception { Notification notification = storage.createNotification(bucket.getName(), notificationInfo); @@ -170,7 +166,6 @@ public void getNotification_exists() throws Exception { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void getNotification_doesNotExists() { Notification getResult = storage.getNotification(bucket.getName(), DOES_NOT_EXIST_ID); @@ -178,7 +173,6 @@ public void getNotification_doesNotExists() { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void deleteNotification_exists() { Notification notification = storage.createNotification(bucket.getName(), notificationInfo); boolean deleteResult = @@ -187,7 +181,6 @@ public void deleteNotification_exists() { } @Test - @CrossRun.Ignore(transports = Transport.GRPC, backends = Backend.PROD) public void deleteNotification_doesNotExists() { boolean deleteResult = storage.deleteNotification(bucket.getName(), DOES_NOT_EXIST_ID); assertThat(deleteResult).isFalse(); diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/jqwik/NotificationArbitraryProvider.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/jqwik/NotificationArbitraryProvider.java deleted file mode 100644 index 8e960791c7..0000000000 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/jqwik/NotificationArbitraryProvider.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.storage.jqwik; - -import static com.google.cloud.storage.PackagePrivateMethodWorkarounds.ifNonNull; - -import com.google.pubsub.v1.TopicName; -import com.google.storage.v2.NotificationConfig; -import com.google.storage.v2.NotificationConfigName; -import java.util.Collections; -import java.util.Set; -import net.jqwik.api.Arbitraries; -import net.jqwik.api.Arbitrary; -import net.jqwik.api.Combinators; -import net.jqwik.api.providers.ArbitraryProvider; -import net.jqwik.api.providers.TypeUsage; -import org.checkerframework.checker.nullness.qual.NonNull; - -public final class NotificationArbitraryProvider implements ArbitraryProvider { - - @Override - public boolean canProvideFor(TypeUsage targetType) { - return targetType.isOfType(NotificationConfig.class); - } - - @NonNull - @Override - public Set> provideFor( - @NonNull TypeUsage targetType, @NonNull SubtypeProvider subtypeProvider) { - Arbitrary as = - Combinators.combine( - notificationName(), - topic(), - StorageArbitraries.etag().injectNull(0.5), - eventTypes(), - StorageArbitraries.buckets().labels(), - StorageArbitraries.objects().name().injectNull(0.5), - Arbitraries.of("JSON_API_V1", "NONE")) - .as( - (name, topic, etag, types, customAttributes, prefix, payloadFormat) -> { - NotificationConfig.Builder b = - NotificationConfig.newBuilder() - .setName(name.toString()) - .setTopic(topic) - .setPayloadFormat(payloadFormat); - ifNonNull(types, b::addAllEventTypes); - ifNonNull(customAttributes, b::putAllCustomAttributes); - ifNonNull(etag, b::setEtag); - ifNonNull(prefix, b::setObjectNamePrefix); - return b.build(); - }); - return Collections.singleton(as); - } - - private static Arbitrary> eventTypes() { - return Arbitraries.of( - "OBJECT_FINALIZE", "OBJECT_METADATA_UPDATE", "OBJECT_DELETE", "OBJECT_ARCHIVE") - .set() - .ofMinSize(0) - .ofMaxSize(4); - } - - @NonNull - private static Arbitrary topic() { - return Combinators.combine( - StorageArbitraries.projectID(), - StorageArbitraries.alphaString().ofMinLength(1).ofMaxLength(10)) - .as((p, t) -> TopicName.of(p.get(), t)) - .map(tn -> "//pubsub.googleapis.com/" + tn.toString()); - } - - @NonNull - private static Arbitrary notificationName() { - return Combinators.combine( - StorageArbitraries.buckets().name(), StorageArbitraries.alphaString().ofMinLength(1)) - .as( - (bucket, notification) -> - NotificationConfigName.of(bucket.getProject(), bucket.getBucket(), notification)); - } -} diff --git a/google-cloud-storage/src/test/resources/META-INF/services/net.jqwik.api.providers.ArbitraryProvider b/google-cloud-storage/src/test/resources/META-INF/services/net.jqwik.api.providers.ArbitraryProvider index 2fcbe230f7..2014e4acfd 100644 --- a/google-cloud-storage/src/test/resources/META-INF/services/net.jqwik.api.providers.ArbitraryProvider +++ b/google-cloud-storage/src/test/resources/META-INF/services/net.jqwik.api.providers.ArbitraryProvider @@ -19,4 +19,3 @@ com.google.cloud.storage.jqwik.BucketArbitraryProvider com.google.cloud.storage.jqwik.HmacKeyMetadataArbitraryProvider com.google.cloud.storage.jqwik.ServiceAccountArbitraryProvider com.google.cloud.storage.jqwik.IamPolicyArbitraryProvider -com.google.cloud.storage.jqwik.NotificationArbitraryProvider