diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 621c0d66c..8807efcad 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,16 @@ +# Copyright 2022 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. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:94580e16bbb4ea1592fa9dd5c5df76716e17858c0dc975582d096c6ae0dc91f5 + digest: sha256:7c853edc4136ae8f19f9d46d4569d38de2e446db2eea057f32e412bdba255846 diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 616371b51..50c4b1498 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -21,7 +21,7 @@ If you are still having issues, please include as much information as possible: General, Core, and Other are also allowed as types 2. OS type and version: 3. Java version: -4. pubsub version(s): +4. version(s): #### Steps to reproduce diff --git a/.github/workflows/approve-readme.yaml b/.github/workflows/approve-readme.yaml index 7513acaeb..c51324279 100644 --- a/.github/workflows/approve-readme.yaml +++ b/.github/workflows/approve-readme.yaml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest if: github.repository_owner == 'googleapis' && github.head_ref == 'autosynth-readme' steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v5 with: github-token: ${{secrets.YOSHI_APPROVER_TOKEN}} script: | diff --git a/.github/workflows/auto-release.yaml b/.github/workflows/auto-release.yaml index 9b4fd4d83..59c7cadde 100644 --- a/.github/workflows/auto-release.yaml +++ b/.github/workflows/auto-release.yaml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest if: contains(github.head_ref, 'release-please') steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v5 with: github-token: ${{secrets.YOSHI_APPROVER_TOKEN}} debug: true diff --git a/.kokoro/nightly/java11-integration.cfg b/.kokoro/nightly/java11-integration.cfg new file mode 100644 index 000000000..58049cc38 --- /dev/null +++ b/.kokoro/nightly/java11-integration.cfg @@ -0,0 +1,37 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-public-resources/java11014" +} + +env_vars: { + key: "JOB_TYPE" + value: "integration" +} +# TODO: remove this after we've migrated all tests and scripts +env_vars: { + key: "GCLOUD_PROJECT" + value: "gcloud-devel" +} + +env_vars: { + key: "GOOGLE_CLOUD_PROJECT" + value: "gcloud-devel" +} + +env_vars: { + key: "ENABLE_FLAKYBOT" + value: "true" +} + +env_vars: { + key: "GOOGLE_APPLICATION_CREDENTIALS" + value: "secret_manager/java-it-service-account" +} + +env_vars: { + key: "SECRET_MANAGER_KEYS" + value: "java-it-service-account" +} diff --git a/.repo-metadata.json b/.repo-metadata.json index 119950039..6cb07ab00 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -1,12 +1,12 @@ { - "name": "pubsub", + "api_shortname": "pubsub", "name_pretty": "Cloud Pub/Sub", "api_reference": "https://cloud.google.com/pubsub/", "product_documentation": "https://cloud.google.com/pubsub/docs/", "client_documentation": "https://cloud.google.com/java/docs/reference/google-cloud-pubsub/latest/history", "api_description": "is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a topic and other applications can subscribe to that topic to receive the messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows developers to communicate between independently written applications.", "issue_tracker": "https://issuetracker.google.com/savedsearches/559741", - "release_level": "ga", + "release_level": "stable", "language": "java", "repo": "googleapis/java-pubsub", "repo_short": "java-pubsub", diff --git a/CHANGELOG.md b/CHANGELOG.md index d6f717597..ead4d9b1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +### [1.115.2](https://github.com/googleapis/java-pubsub/compare/v1.115.1...v1.115.2) (2022-02-03) + + +### Dependencies + +* **java:** update actions/github-script action to v5 ([#1339](https://github.com/googleapis/java-pubsub/issues/1339)) ([#984](https://github.com/googleapis/java-pubsub/issues/984)) ([9a1cc0e](https://github.com/googleapis/java-pubsub/commit/9a1cc0eaf344e2f9cded1c331b0e71543f20ef65)) +* update dependency com.google.cloud:google-cloud-core to v2.4.0 ([#986](https://github.com/googleapis/java-pubsub/issues/986)) ([8cdf7a0](https://github.com/googleapis/java-pubsub/commit/8cdf7a0b1dffa1c01e9c739d79af552e6b42796e)) +* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.7.0 ([#988](https://github.com/googleapis/java-pubsub/issues/988)) ([8993760](https://github.com/googleapis/java-pubsub/commit/89937606134be8e0eb8b7669c6243f1f3b8a9aad)) +* update dependency com.google.errorprone:error_prone_annotations to v2.11.0 ([#983](https://github.com/googleapis/java-pubsub/issues/983)) ([abcbb32](https://github.com/googleapis/java-pubsub/commit/abcbb32e442948ff4637df8b657a7f8a0abd3062)) +* update dependency com.google.protobuf:protobuf-java-util to v3.19.3 ([#973](https://github.com/googleapis/java-pubsub/issues/973)) ([13a9f96](https://github.com/googleapis/java-pubsub/commit/13a9f9645661324cc26b23b9eca5d833bf9d089f)) +* update dependency com.google.protobuf:protobuf-java-util to v3.19.4 ([#987](https://github.com/googleapis/java-pubsub/issues/987)) ([ff71dc7](https://github.com/googleapis/java-pubsub/commit/ff71dc73c9950973512920073a0f0491527a0678)) + ### [1.115.1](https://www.github.com/googleapis/java-pubsub/compare/v1.115.0...v1.115.1) (2022-01-07) diff --git a/README.md b/README.md index 370bcac24..f3a75ec58 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file com.google.cloud libraries-bom - 24.1.2 + 24.2.0 pom import @@ -43,7 +43,7 @@ If you are using Maven without BOM, add this to your dependencies: com.google.cloud google-cloud-pubsub - 1.115.0 + 1.115.1 ``` @@ -51,20 +51,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies ```Groovy -implementation platform('com.google.cloud:libraries-bom:24.1.2') +implementation platform('com.google.cloud:libraries-bom:24.2.0') implementation 'com.google.cloud:google-cloud-pubsub' ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-pubsub:1.115.0' +implementation 'com.google.cloud:google-cloud-pubsub:1.115.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.115.0" +libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.115.1" ``` ## Authentication @@ -245,6 +245,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m | Create Pull Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | | Create Push Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.java) | | Create Subscription With Dead Letter Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.java) | +| Create Subscription With Filtering | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithFiltering.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithFiltering.java) | | Create Subscription With Ordering | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithOrdering.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithOrdering.java) | | Create Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateTopicExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateTopicExample.java) | | Create Topic With Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java) | @@ -386,7 +387,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsub/java8-win.html [kokoro-badge-image-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsub/java11.svg [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsub/java11.html -[stability-image]: https://img.shields.io/badge/stability-ga-green +[stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-pubsub.svg [maven-version-link]: https://search.maven.org/search?q=g:com.google.cloud%20AND%20a:google-cloud-pubsub&core=gav [authentication]: https://github.com/googleapis/google-cloud-java#authentication diff --git a/google-cloud-pubsub-bom/pom.xml b/google-cloud-pubsub-bom/pom.xml index 05d44cc88..4ee103ee5 100644 --- a/google-cloud-pubsub-bom/pom.xml +++ b/google-cloud-pubsub-bom/pom.xml @@ -3,12 +3,12 @@ 4.0.0 com.google.cloud google-cloud-pubsub-bom - 1.115.1 + 1.115.2 pom com.google.cloud google-cloud-shared-config - 1.2.4 + 1.2.6 Google Cloud pubsub BOM @@ -52,17 +52,17 @@ com.google.cloud google-cloud-pubsub - 1.115.1 + 1.115.2 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.97.1 + 1.97.2 com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.97.1 + 1.97.2 diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index c97f6d6a8..7078171a6 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-pubsub - 1.115.1 + 1.115.2 jar Google Cloud Pub/Sub https://github.com/googleapis/java-pubsub @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pubsub-parent - 1.115.1 + 1.115.2 google-cloud-pubsub @@ -159,7 +159,7 @@ maven-compiler-plugin - 3.8.1 + 3.9.0 1.8 1.8 diff --git a/grpc-google-cloud-pubsub-v1/pom.xml b/grpc-google-cloud-pubsub-v1/pom.xml index d4218e30f..906629053 100644 --- a/grpc-google-cloud-pubsub-v1/pom.xml +++ b/grpc-google-cloud-pubsub-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.97.1 + 1.97.2 grpc-google-cloud-pubsub-v1 GRPC library for grpc-google-cloud-pubsub-v1 com.google.cloud google-cloud-pubsub-parent - 1.115.1 + 1.115.2 diff --git a/pom.xml b/pom.xml index 7937e43af..c69b71d19 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-pubsub-parent pom - 1.115.1 + 1.115.2 Google Cloud Pub/Sub Parent https://github.com/googleapis/java-pubsub @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 1.2.4 + 1.2.6 @@ -61,7 +61,7 @@ com.google.cloud google-cloud-shared-dependencies - 2.6.0 + 2.7.0 pom import @@ -69,23 +69,23 @@ com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.97.1 + 1.97.2 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.97.1 + 1.97.2 com.google.cloud google-cloud-pubsub - 1.115.1 + 1.115.2 com.google.errorprone error_prone_annotations - 2.10.0 + 2.11.0 diff --git a/proto-google-cloud-pubsub-v1/pom.xml b/proto-google-cloud-pubsub-v1/pom.xml index 3a82a66b5..be6c4b034 100644 --- a/proto-google-cloud-pubsub-v1/pom.xml +++ b/proto-google-cloud-pubsub-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.97.1 + 1.97.2 proto-google-cloud-pubsub-v1 PROTO library for proto-google-cloud-pubsub-v1 com.google.cloud google-cloud-pubsub-parent - 1.115.1 + 1.115.2 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index ab9df840c..f0f95d297 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -44,7 +44,7 @@ com.google.cloud google-cloud-pubsub - 1.115.0 + 1.115.1 @@ -75,12 +75,12 @@ com.google.protobuf protobuf-java-util - 3.19.2 + 3.19.4 com.google.cloud google-cloud-core - 2.3.5 + 2.4.0 tests @@ -91,7 +91,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.2.0 + 3.3.0 add-snippets-source diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index d296648e7..06f54c1e4 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -43,7 +43,7 @@ com.google.cloud google-cloud-pubsub - 1.115.1 + 1.115.2 @@ -61,7 +61,7 @@ com.google.protobuf protobuf-java-util - 3.19.2 + 3.19.4 @@ -79,7 +79,7 @@ com.google.cloud google-cloud-core - 2.3.5 + 2.4.0 tests @@ -90,7 +90,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.2.0 + 3.3.0 add-snippets-source diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index f98c3f8f6..b09c4ff09 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -45,7 +45,7 @@ com.google.cloud libraries-bom - 24.1.2 + 24.2.0 pom import @@ -72,7 +72,7 @@ com.google.protobuf protobuf-java-util - 3.19.2 + 3.19.4 @@ -90,7 +90,7 @@ com.google.cloud google-cloud-core - 2.3.5 + 2.4.0 tests diff --git a/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithFiltering.java b/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithFiltering.java new file mode 100644 index 000000000..40bbac034 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithFiltering.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 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 pubsub; + +// [START pubsub_create_subscription_with_filter] +import com.google.cloud.pubsub.v1.SubscriptionAdminClient; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.ProjectTopicName; +import com.google.pubsub.v1.Subscription; +import java.io.IOException; + +public class CreateSubscriptionWithFiltering { + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String topicId = "your-topic-id"; + String subscriptionId = "your-subscription-id"; + String filter = "attributes.author=\"unknown\""; + + createSubscriptionWithFilteringExample(projectId, topicId, subscriptionId, filter); + } + + public static void createSubscriptionWithFilteringExample( + String projectId, String topicId, String subscriptionId, String filter) throws IOException { + try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { + + ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); + ProjectSubscriptionName subscriptionName = + ProjectSubscriptionName.of(projectId, subscriptionId); + + Subscription subscription = + subscriptionAdminClient.createSubscription( + Subscription.newBuilder() + .setName(subscriptionName.toString()) + .setTopic(topicName.toString()) + // Receive messages with attribute key "author" and value "unknown". + .setFilter(filter) + .build()); + + System.out.println( + "Created a subscription with filtering enabled: " + subscription.getAllFields()); + } + } +} +// [END pubsub_create_subscription_with_filter] diff --git a/samples/snippets/src/main/java/pubsub/SubscribeSyncExample.java b/samples/snippets/src/main/java/pubsub/SubscribeSyncExample.java index 1ece29c37..e3a034044 100644 --- a/samples/snippets/src/main/java/pubsub/SubscribeSyncExample.java +++ b/samples/snippets/src/main/java/pubsub/SubscribeSyncExample.java @@ -60,12 +60,21 @@ public static void subscribeSyncExample( // Use pullCallable().futureCall to asynchronously perform this operation. PullResponse pullResponse = subscriber.pullCallable().call(pullRequest); + + // Stop the program if the pull response is empty to avoid acknowledging + // an empty list of ack IDs. + if (pullResponse.getReceivedMessagesList().isEmpty()) { + System.out.println("No message was pulled. Exiting."); + return; + } + List ackIds = new ArrayList<>(); for (ReceivedMessage message : pullResponse.getReceivedMessagesList()) { // Handle received message // ... ackIds.add(message.getAckId()); } + // Acknowledge received messages. AcknowledgeRequest acknowledgeRequest = AcknowledgeRequest.newBuilder() diff --git a/samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.java b/samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.java index e074aa3fa..67b604203 100644 --- a/samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.java +++ b/samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.java @@ -38,9 +38,6 @@ public static void main(String... args) throws Exception { String subscriptionId = "your-subscription-id"; Integer numOfMessages = 10; - projectId = "tz-playground-bigdata"; - subscriptionId = "uno"; - subscribeSyncWithLeaseExample(projectId, subscriptionId, numOfMessages); } @@ -68,8 +65,14 @@ public static void subscribeSyncWithLeaseExample( // Use pullCallable().futureCall to asynchronously perform this operation. PullResponse pullResponse = subscriber.pullCallable().call(pullRequest); - List ackIds = new ArrayList<>(); + // Stop the program if the pull response is empty to avoid acknowledging + // an empty list of ack IDs. + if (pullResponse.getReceivedMessagesList().isEmpty()) { + System.out.println("No message was pulled. Exiting."); + return; + } + List ackIds = new ArrayList<>(); for (ReceivedMessage message : pullResponse.getReceivedMessagesList()) { ackIds.add(message.getAckId()); diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java index 59bb4377d..b0f57d50a 100644 --- a/samples/snippets/src/test/java/pubsub/AdminIT.java +++ b/samples/snippets/src/test/java/pubsub/AdminIT.java @@ -44,6 +44,7 @@ public class AdminIT { private static final String pullSubscriptionId = "iam-pull-subscription-" + _suffix; private static final String pushSubscriptionId = "iam-push-subscription-" + _suffix; private static final String orderedSubscriptionId = "iam-ordered-subscription-" + _suffix; + private static final String filteredSubscriptionId = "iam-filtered-subscription-" + _suffix; private static final String pushEndpoint = "https://my-test-project.appspot.com/push"; private static final TopicName topicName = TopicName.of(projectId, topicId); @@ -53,6 +54,8 @@ public class AdminIT { SubscriptionName.of(projectId, pushSubscriptionId); private static final SubscriptionName orderedSubscriptionName = SubscriptionName.of(projectId, orderedSubscriptionId); + private static final SubscriptionName filteredSubscriptionName = + SubscriptionName.of(projectId, filteredSubscriptionId); private static void requireEnvVar(String varName) { assertNotNull( @@ -82,6 +85,7 @@ public void tearDown() throws Exception { subscriptionAdminClient.deleteSubscription(pullSubscriptionName); subscriptionAdminClient.deleteSubscription(pushSubscriptionName); subscriptionAdminClient.deleteSubscription(orderedSubscriptionName); + subscriptionAdminClient.deleteSubscription(filteredSubscriptionName); } catch (NotFoundException ignored) { // ignore this as resources may not have been created } @@ -183,6 +187,14 @@ public void testAdmin() throws Exception { assertThat(bout.toString()).contains("Created a subscription with ordering"); assertThat(bout.toString()).contains("enable_message_ordering=true"); + bout.reset(); + // Test create a subscription with filtering enabled + CreateSubscriptionWithFiltering.createSubscriptionWithFilteringExample( + projectId, topicId, filteredSubscriptionId, "attributes.author=\"unknown\""); + assertThat(bout.toString()).contains("Created a subscription with filtering enabled"); + assertThat(bout.toString()) + .contains("google.pubsub.v1.Subscription.filter=attributes.author=\"unknown\""); + bout.reset(); // Test delete subscription. Run twice to delete both pull and push subscriptions. DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId); diff --git a/samples/snippets/src/test/java/pubsub/SubscriberIT.java b/samples/snippets/src/test/java/pubsub/SubscriberIT.java index aae4fb5af..d0946202c 100644 --- a/samples/snippets/src/test/java/pubsub/SubscriberIT.java +++ b/samples/snippets/src/test/java/pubsub/SubscriberIT.java @@ -21,8 +21,6 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; -import com.google.api.gax.core.ExecutorProvider; -import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.pubsub.v1.SubscriptionAdminClient; import com.google.cloud.pubsub.v1.TopicAdminClient; @@ -58,8 +56,6 @@ public class SubscriberIT { private static final TopicName topicName = TopicName.of(projectId, topicId); private static final ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId); - private static final ExecutorProvider executorProvider = - InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(4).build(); private static void requireEnvVar(String varName) { assertNotNull( diff --git a/versions.txt b/versions.txt index e25ad01f2..63895bc25 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -google-cloud-pubsub:1.115.1:1.115.1 -grpc-google-cloud-pubsub-v1:1.97.1:1.97.1 -proto-google-cloud-pubsub-v1:1.97.1:1.97.1 +google-cloud-pubsub:1.115.2:1.115.2 +grpc-google-cloud-pubsub-v1:1.97.2:1.97.2 +proto-google-cloud-pubsub-v1:1.97.2:1.97.2