diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 9351fdfb..3473042c 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,4 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:387835a1375a0049ec44e02542c844302854c732d8291bdf8e472c0ff70a8f67 + digest: sha256:df8d7b2cc0dbc65871e7edd86601901a0612b272fa3f7f0eb590c5c53aa5f92e diff --git a/.github/workflows/approve-readme.yaml b/.github/workflows/approve-readme.yaml index 1bb18232..f5fc7d51 100644 --- a/.github/workflows/approve-readme.yaml +++ b/.github/workflows/approve-readme.yaml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest if: github.repository_owner == 'googleapis' && github.head_ref == 'autosynth-readme' steps: - - uses: actions/github-script@v5 + - uses: actions/github-script@v6 with: github-token: ${{secrets.YOSHI_APPROVER_TOKEN}} script: | diff --git a/.github/workflows/auto-release.yaml b/.github/workflows/auto-release.yaml index 18e23230..7a106d00 100644 --- a/.github/workflows/auto-release.yaml +++ b/.github/workflows/auto-release.yaml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest if: contains(github.head_ref, 'release-please') steps: - - uses: actions/github-script@v5 + - uses: actions/github-script@v6 with: github-token: ${{secrets.YOSHI_APPROVER_TOKEN}} debug: true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b5e56aa..83ef7f9c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,8 +27,8 @@ jobs: matrix: java: [8, 11, 17] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: distribution: zulu java-version: ${{matrix.java}} @@ -39,8 +39,8 @@ jobs: windows: runs-on: windows-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: distribution: zulu java-version: 8 @@ -54,8 +54,8 @@ jobs: matrix: java: [8, 11, 17] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: distribution: zulu java-version: ${{matrix.java}} @@ -64,8 +64,8 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: distribution: zulu java-version: 11 @@ -76,8 +76,8 @@ jobs: clirr: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: distribution: zulu java-version: 8 diff --git a/.github/workflows/samples.yaml b/.github/workflows/samples.yaml index d5d964df..912ed8b2 100644 --- a/.github/workflows/samples.yaml +++ b/.github/workflows/samples.yaml @@ -20,9 +20,10 @@ jobs: checkstyle: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v1 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: + distribution: zulu java-version: 8 - name: Run checkstyle run: mvn -P lint --quiet --batch-mode checkstyle:check diff --git a/.kokoro/build.bat b/.kokoro/build.bat index cc602c9e..067cf4a4 100644 --- a/.kokoro/build.bat +++ b/.kokoro/build.bat @@ -1,18 +1,18 @@ +:: 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. +:: Github action job to test core java library features on +:: downstream client libraries before they are released. :: See documentation in type-shell-output.bat -# 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. -# Github action job to test core java library features on -# downstream client libraries before they are released. "C:\Program Files\Git\bin\bash.exe" %~dp0build.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 62e9e3db..783aace3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +### [2.1.5](https://github.com/googleapis/java-tasks/compare/v2.1.4...v2.1.5) (2022-03-03) + + +### Documentation + +* **sample:** add native-image sample ([#621](https://github.com/googleapis/java-tasks/issues/621)) ([ec53481](https://github.com/googleapis/java-tasks/commit/ec53481cc690561f4aa7ffd6307f66197d1239bc)) + + +### Dependencies + +* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.8.0 ([#631](https://github.com/googleapis/java-tasks/issues/631)) ([fb1ef62](https://github.com/googleapis/java-tasks/commit/fb1ef621fe3c14a875de8dd25bd0ac702bb2e996)) +* update dependency com.google.cloud:native-image-support to v0.12.6 ([#628](https://github.com/googleapis/java-tasks/issues/628)) ([457b697](https://github.com/googleapis/java-tasks/commit/457b697a3d9029bd4f33b258ea98918bb38cc1b2)) +* update dependency org.graalvm.buildtools:junit-platform-native to v0.9.10 ([#626](https://github.com/googleapis/java-tasks/issues/626)) ([808c56e](https://github.com/googleapis/java-tasks/commit/808c56ef98ecdf7a57cbf31234ef4c6b1c93c609)) +* update dependency org.graalvm.buildtools:native-maven-plugin to v0.9.10 ([#627](https://github.com/googleapis/java-tasks/issues/627)) ([1f08e4a](https://github.com/googleapis/java-tasks/commit/1f08e4a446881032d3c40ee31986fa748dbc1914)) + ### [2.1.4](https://github.com/googleapis/java-tasks/compare/v2.1.3...v2.1.4) (2022-02-28) diff --git a/README.md b/README.md index 70530abc..c387b3a5 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-tasks - 2.1.3 + 2.1.4 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-tasks:2.1.3' +implementation 'com.google.cloud:google-cloud-tasks:2.1.4' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-tasks" % "2.1.3" +libraryDependencies += "com.google.cloud" % "google-cloud-tasks" % "2.1.4" ``` ## Authentication @@ -76,6 +76,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-tasks/tree/ma | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | +| Tasks Sample Application | [source code](https://github.com/googleapis/java-tasks/blob/main/samples/native-image-sample/src/main/java/com/example/tasks/TasksSampleApplication.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-tasks&page=editor&open_in_editor=samples/native-image-sample/src/main/java/com/example/tasks/TasksSampleApplication.java) | | Create Http Task | [source code](https://github.com/googleapis/java-tasks/blob/main/samples/snippets/src/main/java/com/example/task/CreateHttpTask.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-tasks&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/task/CreateHttpTask.java) | | Create Http Task With Token | [source code](https://github.com/googleapis/java-tasks/blob/main/samples/snippets/src/main/java/com/example/task/CreateHttpTaskWithToken.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-tasks&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/task/CreateHttpTaskWithToken.java) | | Create Queue | [source code](https://github.com/googleapis/java-tasks/blob/main/samples/snippets/src/main/java/com/example/task/CreateQueue.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-tasks&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/task/CreateQueue.java) | diff --git a/google-cloud-tasks-bom/pom.xml b/google-cloud-tasks-bom/pom.xml index f8fb5d26..b2ba3877 100644 --- a/google-cloud-tasks-bom/pom.xml +++ b/google-cloud-tasks-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-tasks-bom - 2.1.4 + 2.1.5 pom com.google.cloud @@ -52,37 +52,37 @@ com.google.cloud google-cloud-tasks - 2.1.4 + 2.1.5 com.google.api.grpc grpc-google-cloud-tasks-v2beta3 - 0.91.4 + 0.91.5 com.google.api.grpc grpc-google-cloud-tasks-v2beta2 - 0.91.4 + 0.91.5 com.google.api.grpc grpc-google-cloud-tasks-v2 - 2.1.4 + 2.1.5 com.google.api.grpc proto-google-cloud-tasks-v2beta3 - 0.91.4 + 0.91.5 com.google.api.grpc proto-google-cloud-tasks-v2beta2 - 0.91.4 + 0.91.5 com.google.api.grpc proto-google-cloud-tasks-v2 - 2.1.4 + 2.1.5 diff --git a/google-cloud-tasks/pom.xml b/google-cloud-tasks/pom.xml index 08233231..83a4c078 100644 --- a/google-cloud-tasks/pom.xml +++ b/google-cloud-tasks/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-tasks - 2.1.4 + 2.1.5 jar Google Cloud Tasks https://github.com/googleapis/java-tasks @@ -11,7 +11,7 @@ com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 google-cloud-tasks diff --git a/grpc-google-cloud-tasks-v2/pom.xml b/grpc-google-cloud-tasks-v2/pom.xml index d8029c34..44c89a8b 100644 --- a/grpc-google-cloud-tasks-v2/pom.xml +++ b/grpc-google-cloud-tasks-v2/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-tasks-v2 - 2.1.4 + 2.1.5 grpc-google-cloud-tasks-v2 GRPC library for grpc-google-cloud-tasks-v2 com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 diff --git a/grpc-google-cloud-tasks-v2beta2/pom.xml b/grpc-google-cloud-tasks-v2beta2/pom.xml index 9b2852b9..a8efd998 100644 --- a/grpc-google-cloud-tasks-v2beta2/pom.xml +++ b/grpc-google-cloud-tasks-v2beta2/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-tasks-v2beta2 - 0.91.4 + 0.91.5 grpc-google-cloud-tasks-v2beta2 GRPC library for grpc-google-cloud-tasks-v2beta2 com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 diff --git a/grpc-google-cloud-tasks-v2beta3/pom.xml b/grpc-google-cloud-tasks-v2beta3/pom.xml index 868b01a7..2f798a2d 100644 --- a/grpc-google-cloud-tasks-v2beta3/pom.xml +++ b/grpc-google-cloud-tasks-v2beta3/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-tasks-v2beta3 - 0.91.4 + 0.91.5 grpc-google-cloud-tasks-v2beta3 GRPC library for grpc-google-cloud-tasks-v2beta3 com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 diff --git a/pom.xml b/pom.xml index ba6a5b3b..66209592 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-tasks-parent pom - 2.1.4 + 2.1.5 Google Cloud Tasks Parent https://github.com/googleapis/java-tasks @@ -61,43 +61,43 @@ com.google.api.grpc proto-google-cloud-tasks-v2beta3 - 0.91.4 + 0.91.5 com.google.api.grpc proto-google-cloud-tasks-v2beta2 - 0.91.4 + 0.91.5 com.google.api.grpc proto-google-cloud-tasks-v2 - 2.1.4 + 2.1.5 com.google.api.grpc grpc-google-cloud-tasks-v2beta3 - 0.91.4 + 0.91.5 com.google.api.grpc grpc-google-cloud-tasks-v2beta2 - 0.91.4 + 0.91.5 com.google.api.grpc grpc-google-cloud-tasks-v2 - 2.1.4 + 2.1.5 com.google.cloud google-cloud-tasks - 2.1.4 + 2.1.5 com.google.cloud google-cloud-shared-dependencies - 2.7.0 + 2.8.0 pom import @@ -144,7 +144,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.2.1 + 3.2.2 diff --git a/proto-google-cloud-tasks-v2/pom.xml b/proto-google-cloud-tasks-v2/pom.xml index b71485f8..beb41c39 100644 --- a/proto-google-cloud-tasks-v2/pom.xml +++ b/proto-google-cloud-tasks-v2/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-tasks-v2 - 2.1.4 + 2.1.5 proto-google-cloud-tasks-v2 PROTO library for proto-google-cloud-tasks-v2 com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 diff --git a/proto-google-cloud-tasks-v2beta2/pom.xml b/proto-google-cloud-tasks-v2beta2/pom.xml index 6bae5332..b4f9997f 100644 --- a/proto-google-cloud-tasks-v2beta2/pom.xml +++ b/proto-google-cloud-tasks-v2beta2/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-tasks-v2beta2 - 0.91.4 + 0.91.5 proto-google-cloud-tasks-v2beta2 PROTO library for proto-google-cloud-tasks-v2beta2 com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 diff --git a/proto-google-cloud-tasks-v2beta3/pom.xml b/proto-google-cloud-tasks-v2beta3/pom.xml index 2419d53f..e2f23b6d 100644 --- a/proto-google-cloud-tasks-v2beta3/pom.xml +++ b/proto-google-cloud-tasks-v2beta3/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-tasks-v2beta3 - 0.91.4 + 0.91.5 proto-google-cloud-tasks-v2beta3 PROTO library for proto-google-cloud-tasks-v2beta3 com.google.cloud google-cloud-tasks-parent - 2.1.4 + 2.1.5 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index bd1aa24a..46a34aca 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -29,7 +29,7 @@ com.google.cloud google-cloud-tasks - 2.1.3 + 2.1.4 diff --git a/samples/native-image-sample/README.md b/samples/native-image-sample/README.md new file mode 100644 index 00000000..acbbe7ff --- /dev/null +++ b/samples/native-image-sample/README.md @@ -0,0 +1,119 @@ +# Cloud Tasks Sample Application with Native Image + +The Cloud Tasks sample application demonstrates some common operations with +[Google Cloud Tasks](https://cloud.google.com/tasks) and is compatible with +Native Image compilation. + +This application will create a new queue called `graal-test-queue` if it does +not already exist. +It will then submit a new task to this queue. + +## Setup Instructions + +1. Follow the [GCP Project and Native Image Setup Instructions](../../README.md). + +2. [Enable the Cloud Tasks APIs](https://console.cloud.google.com/apis/api/cloudtasks.googleapis.com). + +### Run with Native Image Compilation + +Navigate to this directory in a new terminal. + +1. Compile the application using the Native Image Compiler. This step may take a few minutes. + + ``` + $ mvn package -P native + ``` + + The project uses an environment variable `LOCATION_ID` to run the test. + +2. Run the application: + + ``` + $ LOCATION_ID=us-east1 ./target/tasks-sample + ``` + + The sample application uses an environment variable `LOCATION_ID`. + +3. The application runs through some basic Cloud Tasks operations (create queue, create task) and then prints some results of the operations. + + ``` + Test queue ready: name: "projects/xxxxxxxxxx/locations/us-central1/queues/graal-test-queue-4009" + rate_limits { + max_dispatches_per_second: 500.0 + max_burst_size: 100 + max_concurrent_dispatches: 1 + } + retry_config { + max_attempts: 100 + min_backoff { + nanos: 100000000 + } + max_backoff { + seconds: 3600 + } + max_doublings: 16 + } + state: RUNNING + + Created task: name: "projects/xxxxxxxxxx/locations/us-central1/queues/graal-test-queue-4009/tasks/5886258204485021611" + http_request { + url: "https://google.com/" + http_method: GET + headers { + key: "User-Agent" + value: "Google-Cloud-Tasks" + } + } + schedule_time { + seconds: 1613189391 + nanos: 486293000 + } + create_time { + seconds: 1613189391 + } + dispatch_deadline { + seconds: 600 + } + view: BASIC + + Queue purged + Queue deleted + ``` + +4. Run the test in the project in the native-image mode + + ``` + $ LOCATION_ID=us-east1 mvn test -P native + ... + [INFO] ------------------------------------------------------- + [INFO] T E S T S + [INFO] ------------------------------------------------------- + [INFO] Running com.example.tasks.ITNativeImageTasksSample + ... + [INFO] --- native-maven-plugin:0.9.9:test (test-native) @ native-image-sample --- + [INFO] ==================== + [INFO] Initializing project: native-image-sample + ... + com.example.tasks.ITNativeImageTasksSample > testRunSampleApplication SUCCESSFUL + + + Test run finished after 1025 ms + [ 3 containers found ] + [ 0 containers skipped ] + [ 3 containers started ] + [ 0 containers aborted ] + [ 3 containers successful ] + [ 0 containers failed ] + [ 1 tests found ] + [ 0 tests skipped ] + [ 1 tests started ] + [ 0 tests aborted ] + [ 1 tests successful ] + [ 0 tests failed ] + + [INFO] ------------------------------------------------------------------------ + [INFO] BUILD SUCCESS + [INFO] ------------------------------------------------------------------------ + [INFO] Total time: 02:27 min + ... + ``` diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml new file mode 100644 index 00000000..dbadb0b8 --- /dev/null +++ b/samples/native-image-sample/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + com.example.tasks + native-image-sample + Native Image Sample + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + + 1.8 + 1.8 + UTF-8 + + + + + + com.google.cloud + libraries-bom + 24.4.0 + pom + import + + + + + + + com.google.cloud + google-cloud-core + + + com.google.cloud + google-cloud-tasks + + + junit + junit + 4.13.2 + test + + + com.google.truth + truth + 1.1.3 + test + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.example.TasksSampleApplication + + + + + + + + + + native + + + + com.google.cloud + native-image-support + 0.12.6 + + + org.junit.vintage + junit-vintage-engine + 5.8.2 + + + org.graalvm.buildtools + junit-platform-native + 0.9.10 + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + 2.22.2 + + + **/IT* + + + + + org.graalvm.buildtools + native-maven-plugin + 0.9.10 + true + + com.example.tasks.TasksSampleApplication + + --no-fallback + --no-server + --initialize-at-build-time + --features=com.google.cloud.nativeimage.features.ProtobufMessageFeature + + + + + build-native + + build + test + + package + + + test-native + + test + + test + + + + + + + + \ No newline at end of file diff --git a/samples/native-image-sample/src/main/java/com/example/tasks/TasksSampleApplication.java b/samples/native-image-sample/src/main/java/com/example/tasks/TasksSampleApplication.java new file mode 100644 index 00000000..de736aa8 --- /dev/null +++ b/samples/native-image-sample/src/main/java/com/example/tasks/TasksSampleApplication.java @@ -0,0 +1,85 @@ +/* + * 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. + */ + +package com.example.tasks; + +import com.google.cloud.ServiceOptions; +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.CreateQueueRequest; +import com.google.cloud.tasks.v2.HttpMethod; +import com.google.cloud.tasks.v2.HttpRequest; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; +import com.google.cloud.tasks.v2.RateLimits; +import com.google.cloud.tasks.v2.Task; +import java.io.IOException; +import java.util.UUID; + +/** Sample application demonstrating Native Image compatibility with Google Cloud Tasks APIs. */ +public class TasksSampleApplication { + /** + * Queue name randomness added to avoid FAILED_PRECONDITION: The queue cannot be created because a + * queue with this name existed too recently. + */ + private static final String GRAALVM_TEST_QUEUE_NAME = "graal-test-queue-"; + + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); + + /** Runs the Cloud Tasks sample application. */ + public static void main(String[] args) throws IOException { + String projectId = ServiceOptions.getDefaultProjectId(); + LocationName parent = LocationName.of(projectId, LOCATION_ID); + QueueName queueName = + QueueName.of( + parent.getProject(), + parent.getLocation(), + GRAALVM_TEST_QUEUE_NAME + UUID.randomUUID().toString()); + + try (CloudTasksClient client = CloudTasksClient.create()) { + // Create queue + Queue queue = + Queue.newBuilder() + .setName(queueName.toString()) + .setRateLimits(RateLimits.newBuilder().setMaxConcurrentDispatches(1).build()) + .build(); + + CreateQueueRequest createQueueRequest = + CreateQueueRequest.newBuilder().setParent(parent.toString()).setQueue(queue).build(); + + Queue createdQueue = client.createQueue(createQueueRequest); + System.out.println("Test queue ready: " + createdQueue); + + // Create task + HttpRequest taskTarget = + HttpRequest.newBuilder() + .setUrl("https://google.com") + .setHttpMethod(HttpMethod.GET) + .build(); + + Task taskRequest = Task.newBuilder().setHttpRequest(taskTarget).build(); + Task task = client.createTask(queueName, taskRequest); + System.out.println("Created task: " + task); + + // Cleanup + client.purgeQueue(queueName); + System.out.println("Queue purged"); + + client.deleteQueue(queueName); + System.out.println("Queue deleted"); + } + } +} diff --git a/samples/native-image-sample/src/test/java/com/example/tasks/ITNativeImageTasksSample.java b/samples/native-image-sample/src/test/java/com/example/tasks/ITNativeImageTasksSample.java new file mode 100644 index 00000000..70e91ffa --- /dev/null +++ b/samples/native-image-sample/src/test/java/com/example/tasks/ITNativeImageTasksSample.java @@ -0,0 +1,43 @@ +/* + * 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 + * + * https://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.example.tasks; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.Before; +import org.junit.Test; + +public class ITNativeImageTasksSample { + private ByteArrayOutputStream bout; + + @Before + public void setUp() throws Exception { + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + } + + @Test + public void testRunSampleApplication() throws Exception { + TasksSampleApplication.main(new String[] {}); + String output = bout.toString(); + assertThat(output).contains("Test queue ready"); + assertThat(output).contains("Queue purged"); + assertThat(output).contains("Queue deleted"); + } +} diff --git a/samples/pom.xml b/samples/pom.xml index 92ea1f87..87ddc149 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -31,6 +31,7 @@ install-without-bom snapshot snippets + native-image-sample diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 6269374b..872836ad 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,7 +28,7 @@ com.google.cloud google-cloud-tasks - 2.1.3 + 2.1.4 diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 01715b0e..b8d8ce12 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -30,7 +30,7 @@ com.google.cloud libraries-bom - 24.3.0 + 24.4.0 pom import diff --git a/versions.txt b/versions.txt index 1613fadc..aacfbac5 100644 --- a/versions.txt +++ b/versions.txt @@ -1,10 +1,10 @@ # Format: # module:released-version:current-version -google-cloud-tasks:2.1.4:2.1.4 -grpc-google-cloud-tasks-v2beta3:0.91.4:0.91.4 -grpc-google-cloud-tasks-v2beta2:0.91.4:0.91.4 -grpc-google-cloud-tasks-v2:2.1.4:2.1.4 -proto-google-cloud-tasks-v2beta3:0.91.4:0.91.4 -proto-google-cloud-tasks-v2beta2:0.91.4:0.91.4 -proto-google-cloud-tasks-v2:2.1.4:2.1.4 +google-cloud-tasks:2.1.5:2.1.5 +grpc-google-cloud-tasks-v2beta3:0.91.5:0.91.5 +grpc-google-cloud-tasks-v2beta2:0.91.5:0.91.5 +grpc-google-cloud-tasks-v2:2.1.5:2.1.5 +proto-google-cloud-tasks-v2beta3:0.91.5:0.91.5 +proto-google-cloud-tasks-v2beta2:0.91.5:0.91.5 +proto-google-cloud-tasks-v2:2.1.5:2.1.5