From 390532812ca4a678e53a90da95617c3739d4fd96 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Tue, 16 Jun 2020 03:14:25 +0000 Subject: [PATCH 1/8] add Java snippets for creating, listing, and deleting queues --- .../java/com/example/task/CreateQueue.java | 37 ++++++++ .../java/com/example/task/DeleteQueue.java | 33 +++++++ .../java/com/example/task/ListQueues.java | 41 ++++++++ .../java/com/example/task/CreateQueueIT.java | 79 ++++++++++++++++ .../java/com/example/task/DeleteQueueIT.java | 94 +++++++++++++++++++ .../java/com/example/task/ListQueuesIT.java | 92 ++++++++++++++++++ 6 files changed, 376 insertions(+) create mode 100644 tasks/src/main/java/com/example/task/CreateQueue.java create mode 100644 tasks/src/main/java/com/example/task/DeleteQueue.java create mode 100644 tasks/src/main/java/com/example/task/ListQueues.java create mode 100644 tasks/src/test/java/com/example/task/CreateQueueIT.java create mode 100644 tasks/src/test/java/com/example/task/DeleteQueueIT.java create mode 100644 tasks/src/test/java/com/example/task/ListQueuesIT.java diff --git a/tasks/src/main/java/com/example/task/CreateQueue.java b/tasks/src/main/java/com/example/task/CreateQueue.java new file mode 100644 index 00000000000..0effedd36fc --- /dev/null +++ b/tasks/src/main/java/com/example/task/CreateQueue.java @@ -0,0 +1,37 @@ +package com.example.task; + +// [START cloud_tasks_create_queue] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.QueueName; +import com.google.cloud.tasks.v2.Queue; + +public class CreateQueue { + /** + * Create a queue using the Cloud Tasks client. + * + * @param projectId the Id of the project. + * @param queueId the name of your Queue. + * @param locationId the GCP region of your queue. + * @throws Exception on Cloud Tasks Client errors. + */ + public static void createQueue(String projectId, String locationId, String queueId) + throws Exception { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Construct the fully qualified location. + String parent = LocationName.of(projectId, locationId).toString(); + + // Construct the fully qualified queue path. + String queuePath = QueueName.of(projectId, locationId, queueId).toString(); + + // Send create queue request. + Queue queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build()); + + System.out.println("Queue created: " + queue.getName()); + } + } +} +// [END cloud_tasks_create_queue] diff --git a/tasks/src/main/java/com/example/task/DeleteQueue.java b/tasks/src/main/java/com/example/task/DeleteQueue.java new file mode 100644 index 00000000000..89782f1cc21 --- /dev/null +++ b/tasks/src/main/java/com/example/task/DeleteQueue.java @@ -0,0 +1,33 @@ +package com.example.task; + +// [START cloud_tasks_delete_queue] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.QueueName; + +public class DeleteQueue { + /** + * Delete a queue using the Cloud Tasks client. + * + * @param projectId the Id of the project. + * @param queueId the name of your Queue. + * @param locationId the GCP region of your queue. + * @throws Exception on Cloud Tasks Client errors. + */ + public static void deleteQueue(String projectId, String locationId, String queueId) + throws Exception { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Construct the fully qualified queue path. + String queuePath = QueueName.of(projectId, locationId, queueId).toString(); + + // Send delete queue request. + client.deleteQueue(queuePath); + + System.out.println("Queue deleted: " + queueId); + } + } +} +// [END cloud_tasks_delete_queue] diff --git a/tasks/src/main/java/com/example/task/ListQueues.java b/tasks/src/main/java/com/example/task/ListQueues.java new file mode 100644 index 00000000000..15dda28538c --- /dev/null +++ b/tasks/src/main/java/com/example/task/ListQueues.java @@ -0,0 +1,41 @@ +package com.example.task; + +// [START cloud_tasks_list_queues] +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.Queue; + +public class ListQueues { + /** + * List queues using the Cloud Tasks client. + * + * @param projectId the Id of the project. + * @param locationId the GCP region of your queue. + * @throws Exception on Cloud Tasks Client errors. + */ + public static void listQueues(String projectId, String locationId) + throws Exception { + + // Instantiates a client. + try (CloudTasksClient client = CloudTasksClient.create()) { + + // Construct the fully qualified location path. + String parent = LocationName.of(projectId, locationId).toString(); + + // Send list queues request. + CloudTasksClient.ListQueuesPagedResponse response = client.listQueues(parent); + + // Iterate over results and print queue names + int total = 0; + for(Queue queue : response.iterateAll()){ + System.out.println(queue.getName()); + total++; + } + + if(total == 0){ + System.out.println("No queues found!"); + } + } + } +} +// [END cloud_tasks_list_queues] diff --git a/tasks/src/test/java/com/example/task/CreateQueueIT.java b/tasks/src/test/java/com/example/task/CreateQueueIT.java new file mode 100644 index 00000000000..56ed26970dd --- /dev/null +++ b/tasks/src/test/java/com/example/task/CreateQueueIT.java @@ -0,0 +1,79 @@ +/* + * Copyright 2019 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.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.QueueName; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for creating Tasks with HTTP targets. */ +@RunWith(JUnit4.class) +public class CreateQueueIT { + private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = "us-central1"; + private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); + + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getProperty(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + try (CloudTasksClient client = CloudTasksClient.create()) { + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + client.deleteQueue(queuePath); + } catch (Exception e) { + System.out.println("Error with queue deletion."); + } + } + + @Test + public void testCreateQueue() throws Exception { + CreateQueue.createQueue(PROJECT_ID, LOCATION_ID, QUEUE_ID); + String got = bout.toString(); + assertThat(got).contains("Queue created:"); + } +} diff --git a/tasks/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/src/test/java/com/example/task/DeleteQueueIT.java new file mode 100644 index 00000000000..404166685a6 --- /dev/null +++ b/tasks/src/test/java/com/example/task/DeleteQueueIT.java @@ -0,0 +1,94 @@ +/* + * Copyright 2019 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.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.api.gax.rpc.NotFoundException; +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.QueueName; +import com.google.cloud.tasks.v2.Queue; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for creating Tasks with HTTP targets. */ +@RunWith(JUnit4.class) +public class DeleteQueueIT { + private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = "us-central1"; + private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); + + private ByteArrayOutputStream bout; + private PrintStream old_out, out; + private Queue queue; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getProperty(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + old_out = System.out; + System.setOut(out); + + try (CloudTasksClient client = CloudTasksClient.create()) { + String parent = LocationName.of(PROJECT_ID, LOCATION_ID).toString(); + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build()); + } catch (Exception e) { + System.out.println("Error with queue creation."); + } + } + + @After + public void tearDown() { + System.setOut(old_out); + try (CloudTasksClient client = CloudTasksClient.create()) { + client.deleteQueue(queue.getName()); + } catch (IOException e) { + System.out.println("Error with queue deletion."); + } catch (NotFoundException e){ + System.out.println("Queue already successfully deleted"); + } + } + + @Test + public void testDeleteQueue() throws Exception { + DeleteQueue.deleteQueue(PROJECT_ID, LOCATION_ID, QUEUE_ID); + String got = bout.toString(); + assertThat(got).contains("Queue deleted:"); + } +} diff --git a/tasks/src/test/java/com/example/task/ListQueuesIT.java b/tasks/src/test/java/com/example/task/ListQueuesIT.java new file mode 100644 index 00000000000..7fa8dde0cbd --- /dev/null +++ b/tasks/src/test/java/com/example/task/ListQueuesIT.java @@ -0,0 +1,92 @@ +/* + * Copyright 2019 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.task; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.api.gax.rpc.NotFoundException; +import com.google.cloud.tasks.v2.CloudTasksClient; +import com.google.cloud.tasks.v2.LocationName; +import com.google.cloud.tasks.v2.QueueName; +import com.google.cloud.tasks.v2.Queue; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for creating Tasks with HTTP targets. */ +@RunWith(JUnit4.class) +public class ListQueuesIT { + private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = "us-central1"; + private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); + + private ByteArrayOutputStream bout; + private PrintStream old_out, out; + private Queue queue; + + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getProperty(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + old_out = System.out; + System.setOut(out); + + try (CloudTasksClient client = CloudTasksClient.create()) { + String parent = LocationName.of(PROJECT_ID, LOCATION_ID).toString(); + String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); + queue = client.createQueue(parent, Queue.newBuilder().setName(queuePath).build()); + } catch (Exception e) { + System.out.println("Error with queue creation."); + } + } + + @After + public void tearDown() { + System.setOut(old_out); + try (CloudTasksClient client = CloudTasksClient.create()) { + client.deleteQueue(queue.getName()); + } catch (IOException e) { + System.out.println("Error with queue deletion."); + } + } + + @Test + public void testListQueues() throws Exception { + ListQueues.listQueues(PROJECT_ID, LOCATION_ID); + String got = bout.toString(); + assertThat(got).contains(queue.getName()); + } +} From 03efa1730713862669253cf621abf920c4bdc77a Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Tue, 16 Jun 2020 03:43:07 +0000 Subject: [PATCH 2/8] update licenses --- .../java/com/example/task/CreateQueue.java | 14 ++++++++++ .../java/com/example/task/DeleteQueue.java | 14 ++++++++++ .../java/com/example/task/ListQueues.java | 14 ++++++++++ .../java/com/example/task/CreateQueueIT.java | 28 +++++++++---------- .../java/com/example/task/DeleteQueueIT.java | 28 +++++++++---------- .../java/com/example/task/ListQueuesIT.java | 28 +++++++++---------- 6 files changed, 81 insertions(+), 45 deletions(-) diff --git a/tasks/src/main/java/com/example/task/CreateQueue.java b/tasks/src/main/java/com/example/task/CreateQueue.java index 0effedd36fc..949e117b640 100644 --- a/tasks/src/main/java/com/example/task/CreateQueue.java +++ b/tasks/src/main/java/com/example/task/CreateQueue.java @@ -1,3 +1,17 @@ +// 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 com.example.task; // [START cloud_tasks_create_queue] diff --git a/tasks/src/main/java/com/example/task/DeleteQueue.java b/tasks/src/main/java/com/example/task/DeleteQueue.java index 89782f1cc21..178f7361785 100644 --- a/tasks/src/main/java/com/example/task/DeleteQueue.java +++ b/tasks/src/main/java/com/example/task/DeleteQueue.java @@ -1,3 +1,17 @@ +// 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 com.example.task; // [START cloud_tasks_delete_queue] diff --git a/tasks/src/main/java/com/example/task/ListQueues.java b/tasks/src/main/java/com/example/task/ListQueues.java index 15dda28538c..401aab05a5c 100644 --- a/tasks/src/main/java/com/example/task/ListQueues.java +++ b/tasks/src/main/java/com/example/task/ListQueues.java @@ -1,3 +1,17 @@ +// 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 com.example.task; // [START cloud_tasks_list_queues] diff --git a/tasks/src/test/java/com/example/task/CreateQueueIT.java b/tasks/src/test/java/com/example/task/CreateQueueIT.java index 56ed26970dd..4ef8b7cd81d 100644 --- a/tasks/src/test/java/com/example/task/CreateQueueIT.java +++ b/tasks/src/test/java/com/example/task/CreateQueueIT.java @@ -1,18 +1,16 @@ -/* - * Copyright 2019 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. - */ +// 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 com.example.task; diff --git a/tasks/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/src/test/java/com/example/task/DeleteQueueIT.java index 404166685a6..66ca04eaae2 100644 --- a/tasks/src/test/java/com/example/task/DeleteQueueIT.java +++ b/tasks/src/test/java/com/example/task/DeleteQueueIT.java @@ -1,18 +1,16 @@ -/* - * Copyright 2019 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. - */ +// 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 com.example.task; diff --git a/tasks/src/test/java/com/example/task/ListQueuesIT.java b/tasks/src/test/java/com/example/task/ListQueuesIT.java index 7fa8dde0cbd..250f91c3514 100644 --- a/tasks/src/test/java/com/example/task/ListQueuesIT.java +++ b/tasks/src/test/java/com/example/task/ListQueuesIT.java @@ -1,18 +1,16 @@ -/* - * Copyright 2019 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. - */ +// 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 com.example.task; From 60df62f3e9b386863ab7745d0fcfefca79fb6d46 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Tue, 16 Jun 2020 05:08:22 +0000 Subject: [PATCH 3/8] styling fixes for lint --- tasks/src/main/java/com/example/task/CreateQueue.java | 2 +- tasks/src/main/java/com/example/task/ListQueues.java | 10 +++++----- .../src/test/java/com/example/task/DeleteQueueIT.java | 9 +++++---- tasks/src/test/java/com/example/task/ListQueuesIT.java | 7 ++++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tasks/src/main/java/com/example/task/CreateQueue.java b/tasks/src/main/java/com/example/task/CreateQueue.java index 949e117b640..32c1b089328 100644 --- a/tasks/src/main/java/com/example/task/CreateQueue.java +++ b/tasks/src/main/java/com/example/task/CreateQueue.java @@ -17,8 +17,8 @@ // [START cloud_tasks_create_queue] import com.google.cloud.tasks.v2.CloudTasksClient; import com.google.cloud.tasks.v2.LocationName; -import com.google.cloud.tasks.v2.QueueName; import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; public class CreateQueue { /** diff --git a/tasks/src/main/java/com/example/task/ListQueues.java b/tasks/src/main/java/com/example/task/ListQueues.java index 401aab05a5c..3cdd27ae398 100644 --- a/tasks/src/main/java/com/example/task/ListQueues.java +++ b/tasks/src/main/java/com/example/task/ListQueues.java @@ -41,13 +41,13 @@ public static void listQueues(String projectId, String locationId) // Iterate over results and print queue names int total = 0; - for(Queue queue : response.iterateAll()){ - System.out.println(queue.getName()); - total++; + for (Queue queue : response.iterateAll()) { + System.out.println(queue.getName()); + total++; } - if(total == 0){ - System.out.println("No queues found!"); + if (total == 0) { + System.out.println("No queues found!"); } } } diff --git a/tasks/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/src/test/java/com/example/task/DeleteQueueIT.java index 66ca04eaae2..993cb3c23c1 100644 --- a/tasks/src/test/java/com/example/task/DeleteQueueIT.java +++ b/tasks/src/test/java/com/example/task/DeleteQueueIT.java @@ -20,8 +20,8 @@ import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.tasks.v2.CloudTasksClient; import com.google.cloud.tasks.v2.LocationName; -import com.google.cloud.tasks.v2.QueueName; import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; @@ -41,7 +41,8 @@ public class DeleteQueueIT { private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); private ByteArrayOutputStream bout; - private PrintStream old_out, out; + private PrintStream out; + private PrintStream oldOut; private Queue queue; private static void requireEnvVar(String varName) { @@ -73,12 +74,12 @@ public void setUp() { @After public void tearDown() { - System.setOut(old_out); + System.setOut(oldOut); try (CloudTasksClient client = CloudTasksClient.create()) { client.deleteQueue(queue.getName()); } catch (IOException e) { System.out.println("Error with queue deletion."); - } catch (NotFoundException e){ + } catch (NotFoundException e) { System.out.println("Queue already successfully deleted"); } } diff --git a/tasks/src/test/java/com/example/task/ListQueuesIT.java b/tasks/src/test/java/com/example/task/ListQueuesIT.java index 250f91c3514..ce34ae72110 100644 --- a/tasks/src/test/java/com/example/task/ListQueuesIT.java +++ b/tasks/src/test/java/com/example/task/ListQueuesIT.java @@ -20,8 +20,8 @@ import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.tasks.v2.CloudTasksClient; import com.google.cloud.tasks.v2.LocationName; -import com.google.cloud.tasks.v2.QueueName; import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.QueueName; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; @@ -41,7 +41,8 @@ public class ListQueuesIT { private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); private ByteArrayOutputStream bout; - private PrintStream old_out, out; + private PrintStream out; + private PrintStream oldOut; private Queue queue; private static void requireEnvVar(String varName) { @@ -73,7 +74,7 @@ public void setUp() { @After public void tearDown() { - System.setOut(old_out); + System.setOut(oldOut); try (CloudTasksClient client = CloudTasksClient.create()) { client.deleteQueue(queue.getName()); } catch (IOException e) { From 04325a690c902383c0295dc9be2a8d82ed2116dc Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Wed, 17 Jun 2020 16:47:42 +0000 Subject: [PATCH 4/8] fix test comments and remove oldout --- tasks/src/test/java/com/example/task/CreateQueueIT.java | 4 ++-- tasks/src/test/java/com/example/task/DeleteQueueIT.java | 6 ++---- tasks/src/test/java/com/example/task/ListQueuesIT.java | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tasks/src/test/java/com/example/task/CreateQueueIT.java b/tasks/src/test/java/com/example/task/CreateQueueIT.java index 4ef8b7cd81d..022b850e8e8 100644 --- a/tasks/src/test/java/com/example/task/CreateQueueIT.java +++ b/tasks/src/test/java/com/example/task/CreateQueueIT.java @@ -29,7 +29,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Tests for creating Tasks with HTTP targets. */ +/** Tests for creating queues. */ @RunWith(JUnit4.class) public class CreateQueueIT { private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); @@ -59,13 +59,13 @@ public void setUp() { @After public void tearDown() { - System.setOut(null); try (CloudTasksClient client = CloudTasksClient.create()) { String queuePath = QueueName.of(PROJECT_ID, LOCATION_ID, QUEUE_ID).toString(); client.deleteQueue(queuePath); } catch (Exception e) { System.out.println("Error with queue deletion."); } + System.setOut(null); } @Test diff --git a/tasks/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/src/test/java/com/example/task/DeleteQueueIT.java index 993cb3c23c1..8b016f2f3ad 100644 --- a/tasks/src/test/java/com/example/task/DeleteQueueIT.java +++ b/tasks/src/test/java/com/example/task/DeleteQueueIT.java @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Tests for creating Tasks with HTTP targets. */ +/** Tests for deleting queues. */ @RunWith(JUnit4.class) public class DeleteQueueIT { private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); @@ -42,7 +42,6 @@ public class DeleteQueueIT { private ByteArrayOutputStream bout; private PrintStream out; - private PrintStream oldOut; private Queue queue; private static void requireEnvVar(String varName) { @@ -60,7 +59,6 @@ public static void checkRequirements() { public void setUp() { bout = new ByteArrayOutputStream(); out = new PrintStream(bout); - old_out = System.out; System.setOut(out); try (CloudTasksClient client = CloudTasksClient.create()) { @@ -74,7 +72,6 @@ public void setUp() { @After public void tearDown() { - System.setOut(oldOut); try (CloudTasksClient client = CloudTasksClient.create()) { client.deleteQueue(queue.getName()); } catch (IOException e) { @@ -82,6 +79,7 @@ public void tearDown() { } catch (NotFoundException e) { System.out.println("Queue already successfully deleted"); } + System.setOut(null); } @Test diff --git a/tasks/src/test/java/com/example/task/ListQueuesIT.java b/tasks/src/test/java/com/example/task/ListQueuesIT.java index ce34ae72110..1be08b39372 100644 --- a/tasks/src/test/java/com/example/task/ListQueuesIT.java +++ b/tasks/src/test/java/com/example/task/ListQueuesIT.java @@ -33,7 +33,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Tests for creating Tasks with HTTP targets. */ +/** Tests for listing queues. */ @RunWith(JUnit4.class) public class ListQueuesIT { private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); @@ -42,7 +42,6 @@ public class ListQueuesIT { private ByteArrayOutputStream bout; private PrintStream out; - private PrintStream oldOut; private Queue queue; private static void requireEnvVar(String varName) { @@ -60,7 +59,6 @@ public static void checkRequirements() { public void setUp() { bout = new ByteArrayOutputStream(); out = new PrintStream(bout); - old_out = System.out; System.setOut(out); try (CloudTasksClient client = CloudTasksClient.create()) { @@ -74,12 +72,12 @@ public void setUp() { @After public void tearDown() { - System.setOut(oldOut); try (CloudTasksClient client = CloudTasksClient.create()) { client.deleteQueue(queue.getName()); } catch (IOException e) { System.out.println("Error with queue deletion."); } + System.setOut(null); } @Test From 2f3674ce0443f1a18a970db8ed714f9619b6150f Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Thu, 18 Jun 2020 01:07:24 +0000 Subject: [PATCH 5/8] have createhttptask use env var --- .../main/java/com/example/task/DeleteQueue.java | 1 - .../java/com/example/task/CreateHttpTaskIT.java | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tasks/src/main/java/com/example/task/DeleteQueue.java b/tasks/src/main/java/com/example/task/DeleteQueue.java index 178f7361785..956ba8b5fd9 100644 --- a/tasks/src/main/java/com/example/task/DeleteQueue.java +++ b/tasks/src/main/java/com/example/task/DeleteQueue.java @@ -16,7 +16,6 @@ // [START cloud_tasks_delete_queue] import com.google.cloud.tasks.v2.CloudTasksClient; -import com.google.cloud.tasks.v2.LocationName; import com.google.cloud.tasks.v2.QueueName; public class DeleteQueue { diff --git a/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java b/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java index e03d907a677..65f79062d6b 100644 --- a/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java +++ b/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java @@ -17,6 +17,7 @@ package com.example.task; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertNotNull; import com.google.cloud.tasks.v2.CloudTasksClient; import com.google.cloud.tasks.v2.QueueName; @@ -24,6 +25,7 @@ import java.io.PrintStream; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -31,7 +33,7 @@ /** Tests for creating Tasks with HTTP targets. */ @RunWith(JUnit4.class) public class CreateHttpTaskIT { - private static final String PROJECT_ID = "java-docs-samples-testing"; + private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); private static final String LOCATION_ID = "us-east1"; private static final String QUEUE_ID = "default"; private static final String EMAIL = @@ -39,6 +41,17 @@ public class CreateHttpTaskIT { private ByteArrayOutputStream bout; private PrintStream out; + private static void requireEnvVar(String varName) { + assertNotNull( + String.format("Environment variable '%s' must be set to perform these tests.", varName), + System.getProperty(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + @Before public void setUp() { bout = new ByteArrayOutputStream(); From 5897509b15ed5a179983062ec8edb11317dd852d Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Thu, 18 Jun 2020 21:55:34 +0000 Subject: [PATCH 6/8] Change System.getProperty to System.getenv and require LOCATION_ID environment variable as well --- tasks/src/test/java/com/example/task/CreateHttpTaskIT.java | 7 ++++--- tasks/src/test/java/com/example/task/CreateQueueIT.java | 7 ++++--- tasks/src/test/java/com/example/task/DeleteQueueIT.java | 7 ++++--- tasks/src/test/java/com/example/task/ListQueuesIT.java | 7 ++++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java b/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java index 65f79062d6b..11fd89f0b12 100644 --- a/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java +++ b/tasks/src/test/java/com/example/task/CreateHttpTaskIT.java @@ -33,8 +33,8 @@ /** Tests for creating Tasks with HTTP targets. */ @RunWith(JUnit4.class) public class CreateHttpTaskIT { - private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); - private static final String LOCATION_ID = "us-east1"; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); private static final String QUEUE_ID = "default"; private static final String EMAIL = "java-docs-samples-testing@java-docs-samples-testing.iam.gserviceaccount.com"; @@ -44,12 +44,13 @@ public class CreateHttpTaskIT { private static void requireEnvVar(String varName) { assertNotNull( String.format("Environment variable '%s' must be set to perform these tests.", varName), - System.getProperty(varName)); + System.getenv(varName)); } @BeforeClass public static void checkRequirements() { requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); } @Before diff --git a/tasks/src/test/java/com/example/task/CreateQueueIT.java b/tasks/src/test/java/com/example/task/CreateQueueIT.java index 022b850e8e8..8677ee30d09 100644 --- a/tasks/src/test/java/com/example/task/CreateQueueIT.java +++ b/tasks/src/test/java/com/example/task/CreateQueueIT.java @@ -32,8 +32,8 @@ /** Tests for creating queues. */ @RunWith(JUnit4.class) public class CreateQueueIT { - private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); - private static final String LOCATION_ID = "us-central1"; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); private ByteArrayOutputStream bout; @@ -42,12 +42,13 @@ public class CreateQueueIT { private static void requireEnvVar(String varName) { assertNotNull( String.format("Environment variable '%s' must be set to perform these tests.", varName), - System.getProperty(varName)); + System.getenv(varName)); } @BeforeClass public static void checkRequirements() { requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); } @Before diff --git a/tasks/src/test/java/com/example/task/DeleteQueueIT.java b/tasks/src/test/java/com/example/task/DeleteQueueIT.java index 8b016f2f3ad..90c3f74bf59 100644 --- a/tasks/src/test/java/com/example/task/DeleteQueueIT.java +++ b/tasks/src/test/java/com/example/task/DeleteQueueIT.java @@ -36,8 +36,8 @@ /** Tests for deleting queues. */ @RunWith(JUnit4.class) public class DeleteQueueIT { - private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); - private static final String LOCATION_ID = "us-central1"; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); private ByteArrayOutputStream bout; @@ -47,12 +47,13 @@ public class DeleteQueueIT { private static void requireEnvVar(String varName) { assertNotNull( String.format("Environment variable '%s' must be set to perform these tests.", varName), - System.getProperty(varName)); + System.getenv(varName)); } @BeforeClass public static void checkRequirements() { requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); } @Before diff --git a/tasks/src/test/java/com/example/task/ListQueuesIT.java b/tasks/src/test/java/com/example/task/ListQueuesIT.java index 1be08b39372..11e68b8e58e 100644 --- a/tasks/src/test/java/com/example/task/ListQueuesIT.java +++ b/tasks/src/test/java/com/example/task/ListQueuesIT.java @@ -36,8 +36,8 @@ /** Tests for listing queues. */ @RunWith(JUnit4.class) public class ListQueuesIT { - private static final String PROJECT_ID = System.getProperty("GOOGLE_CLOUD_PROJECT"); - private static final String LOCATION_ID = "us-central1"; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION_ID = System.getenv("LOCATION_ID"); private static final String QUEUE_ID = "test-queue-" + UUID.randomUUID(); private ByteArrayOutputStream bout; @@ -47,12 +47,13 @@ public class ListQueuesIT { private static void requireEnvVar(String varName) { assertNotNull( String.format("Environment variable '%s' must be set to perform these tests.", varName), - System.getProperty(varName)); + System.getenv(varName)); } @BeforeClass public static void checkRequirements() { requireEnvVar("GOOGLE_CLOUD_PROJECT"); + requireEnvVar("LOCATION_ID"); } @Before From 8dbd5a4903e7181633125c60568aeeaa6f6197d8 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Thu, 18 Jun 2020 22:58:49 +0000 Subject: [PATCH 7/8] specify exception type in throws --- tasks/src/main/java/com/example/task/CreateHttpTask.java | 3 ++- .../main/java/com/example/task/CreateHttpTaskWithToken.java | 3 ++- tasks/src/main/java/com/example/task/CreateQueue.java | 3 ++- tasks/src/main/java/com/example/task/DeleteQueue.java | 3 ++- tasks/src/main/java/com/example/task/ListQueues.java | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tasks/src/main/java/com/example/task/CreateHttpTask.java b/tasks/src/main/java/com/example/task/CreateHttpTask.java index 858b439ae58..c57b4b910a6 100644 --- a/tasks/src/main/java/com/example/task/CreateHttpTask.java +++ b/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -23,6 +23,7 @@ import com.google.cloud.tasks.v2.QueueName; import com.google.cloud.tasks.v2.Task; import com.google.protobuf.ByteString; +import java.io.IOException; import java.nio.charset.Charset; public class CreateHttpTask { @@ -35,7 +36,7 @@ public class CreateHttpTask { * @throws Exception on Cloud Tasks Client errors. */ public static void createTask(String projectId, String locationId, String queueId) - throws Exception { + throws IOException { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { diff --git a/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java b/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java index 72c4768ef35..1f01099475e 100644 --- a/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java +++ b/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java @@ -24,6 +24,7 @@ import com.google.cloud.tasks.v2.QueueName; import com.google.cloud.tasks.v2.Task; import com.google.protobuf.ByteString; +import java.io.IOException; import java.nio.charset.Charset; public class CreateHttpTaskWithToken { @@ -38,7 +39,7 @@ public class CreateHttpTaskWithToken { */ public static void createTask( String projectId, String locationId, String queueId, String serviceAccountEmail) - throws Exception { + throws IOException { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { diff --git a/tasks/src/main/java/com/example/task/CreateQueue.java b/tasks/src/main/java/com/example/task/CreateQueue.java index 32c1b089328..3a57ea700f0 100644 --- a/tasks/src/main/java/com/example/task/CreateQueue.java +++ b/tasks/src/main/java/com/example/task/CreateQueue.java @@ -19,6 +19,7 @@ import com.google.cloud.tasks.v2.LocationName; import com.google.cloud.tasks.v2.Queue; import com.google.cloud.tasks.v2.QueueName; +import java.io.IOException; public class CreateQueue { /** @@ -30,7 +31,7 @@ public class CreateQueue { * @throws Exception on Cloud Tasks Client errors. */ public static void createQueue(String projectId, String locationId, String queueId) - throws Exception { + throws IOException { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { diff --git a/tasks/src/main/java/com/example/task/DeleteQueue.java b/tasks/src/main/java/com/example/task/DeleteQueue.java index 956ba8b5fd9..55f8c3e2511 100644 --- a/tasks/src/main/java/com/example/task/DeleteQueue.java +++ b/tasks/src/main/java/com/example/task/DeleteQueue.java @@ -17,6 +17,7 @@ // [START cloud_tasks_delete_queue] import com.google.cloud.tasks.v2.CloudTasksClient; import com.google.cloud.tasks.v2.QueueName; +import java.io.IOException; public class DeleteQueue { /** @@ -28,7 +29,7 @@ public class DeleteQueue { * @throws Exception on Cloud Tasks Client errors. */ public static void deleteQueue(String projectId, String locationId, String queueId) - throws Exception { + throws IOException { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { diff --git a/tasks/src/main/java/com/example/task/ListQueues.java b/tasks/src/main/java/com/example/task/ListQueues.java index 3cdd27ae398..9d5090d7cd6 100644 --- a/tasks/src/main/java/com/example/task/ListQueues.java +++ b/tasks/src/main/java/com/example/task/ListQueues.java @@ -18,6 +18,7 @@ import com.google.cloud.tasks.v2.CloudTasksClient; import com.google.cloud.tasks.v2.LocationName; import com.google.cloud.tasks.v2.Queue; +import java.io.IOException; public class ListQueues { /** @@ -28,7 +29,7 @@ public class ListQueues { * @throws Exception on Cloud Tasks Client errors. */ public static void listQueues(String projectId, String locationId) - throws Exception { + throws IOException { // Instantiates a client. try (CloudTasksClient client = CloudTasksClient.create()) { From 9dde85cdea525edcd8c5f41dc76f5083e596203d Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Thu, 18 Jun 2020 23:18:34 +0000 Subject: [PATCH 8/8] add main methods and remove javadoc style comments to adhere with style guide --- .../java/com/example/task/CreateHttpTask.java | 18 +++++++++------- .../example/task/CreateHttpTaskWithToken.java | 21 +++++++++++-------- .../java/com/example/task/CreateQueue.java | 18 +++++++++------- .../java/com/example/task/DeleteQueue.java | 18 +++++++++------- .../java/com/example/task/ListQueues.java | 16 +++++++------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/tasks/src/main/java/com/example/task/CreateHttpTask.java b/tasks/src/main/java/com/example/task/CreateHttpTask.java index c57b4b910a6..e86636bbc6b 100644 --- a/tasks/src/main/java/com/example/task/CreateHttpTask.java +++ b/tasks/src/main/java/com/example/task/CreateHttpTask.java @@ -27,14 +27,16 @@ import java.nio.charset.Charset; public class CreateHttpTask { - /** - * Create a task with a HTTP target using the Cloud Tasks client. - * - * @param projectId the Id of the project. - * @param queueId the name of your Queue. - * @param locationId the GCP region of your queue. - * @throws Exception on Cloud Tasks Client errors. - */ + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + createTask(projectId, locationId, queueId); + } + + // Create a task with a HTTP target using the Cloud Tasks client. public static void createTask(String projectId, String locationId, String queueId) throws IOException { diff --git a/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java b/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java index 1f01099475e..a341f680fea 100644 --- a/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java +++ b/tasks/src/main/java/com/example/task/CreateHttpTaskWithToken.java @@ -28,15 +28,18 @@ import java.nio.charset.Charset; public class CreateHttpTaskWithToken { - /** - * Create a task with a HTTP target and authorization token using the Cloud Tasks client. - * - * @param projectId the Id of the project. - * @param queueId the name of your Queue. - * @param locationId the GCP region of your queue. - * @param serviceAccountEmail your Cloud IAM service account - * @throws Exception on Cloud Tasks Client errors. - */ + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + String serviceAccountEmail = + "java-docs-samples-testing@java-docs-samples-testing.iam.gserviceaccount.com"; + createTask(projectId, locationId, queueId, serviceAccountEmail); + } + + // Create a task with a HTTP target and authorization token using the Cloud Tasks client. public static void createTask( String projectId, String locationId, String queueId, String serviceAccountEmail) throws IOException { diff --git a/tasks/src/main/java/com/example/task/CreateQueue.java b/tasks/src/main/java/com/example/task/CreateQueue.java index 3a57ea700f0..04aa81101ad 100644 --- a/tasks/src/main/java/com/example/task/CreateQueue.java +++ b/tasks/src/main/java/com/example/task/CreateQueue.java @@ -22,14 +22,16 @@ import java.io.IOException; public class CreateQueue { - /** - * Create a queue using the Cloud Tasks client. - * - * @param projectId the Id of the project. - * @param queueId the name of your Queue. - * @param locationId the GCP region of your queue. - * @throws Exception on Cloud Tasks Client errors. - */ + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + createQueue(projectId, locationId, queueId); + } + + // Create a queue using the Cloud Tasks client. public static void createQueue(String projectId, String locationId, String queueId) throws IOException { diff --git a/tasks/src/main/java/com/example/task/DeleteQueue.java b/tasks/src/main/java/com/example/task/DeleteQueue.java index 55f8c3e2511..6f5d9898b48 100644 --- a/tasks/src/main/java/com/example/task/DeleteQueue.java +++ b/tasks/src/main/java/com/example/task/DeleteQueue.java @@ -20,14 +20,16 @@ import java.io.IOException; public class DeleteQueue { - /** - * Delete a queue using the Cloud Tasks client. - * - * @param projectId the Id of the project. - * @param queueId the name of your Queue. - * @param locationId the GCP region of your queue. - * @throws Exception on Cloud Tasks Client errors. - */ + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + String queueId = "my-queue"; + deleteQueue(projectId, locationId, queueId); + } + + // Delete a queue using the Cloud Tasks client. public static void deleteQueue(String projectId, String locationId, String queueId) throws IOException { diff --git a/tasks/src/main/java/com/example/task/ListQueues.java b/tasks/src/main/java/com/example/task/ListQueues.java index 9d5090d7cd6..85fd8c14cc6 100644 --- a/tasks/src/main/java/com/example/task/ListQueues.java +++ b/tasks/src/main/java/com/example/task/ListQueues.java @@ -21,13 +21,15 @@ import java.io.IOException; public class ListQueues { - /** - * List queues using the Cloud Tasks client. - * - * @param projectId the Id of the project. - * @param locationId the GCP region of your queue. - * @throws Exception on Cloud Tasks Client errors. - */ + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String locationId = "us-central1"; + listQueues(projectId, locationId); + } + + // List queues using the Cloud Tasks client. public static void listQueues(String projectId, String locationId) throws IOException {