From 6b791f85c152f632e8eb1aac00e72cf0dff0d2c7 Mon Sep 17 00:00:00 2001 From: Daria Firova Date: Thu, 1 Sep 2022 09:46:28 +0300 Subject: [PATCH 1/6] fix (samples) Removed delays on LRO. --- .../java/product/AddFulfillmentPlaces.java | 11 ++++++++--- .../java/product/RemoveFulfillmentPlaces.java | 10 +++++++--- .../src/main/java/product/SetInventory.java | 19 ++++++++----------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java index 31d94273..15d020e7 100644 --- a/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java @@ -24,9 +24,13 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; +import com.google.cloud.retail.v2.AddFulfillmentPlacesMetadata; import com.google.cloud.retail.v2.AddFulfillmentPlacesRequest; +import com.google.cloud.retail.v2.AddFulfillmentPlacesResponse; import com.google.cloud.retail.v2.ProductServiceClient; +import com.google.longrunning.Operation; import com.google.protobuf.Timestamp; import java.io.IOException; import java.time.Instant; @@ -74,11 +78,12 @@ public static void addFulfillmentPlaces(String productName, String placeId) // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest); + OperationFuture response = + serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. - System.out.println("Add fulfillment places, wait 45 seconds: "); - TimeUnit.SECONDS.sleep(45); + System.out.println("Waiting for operation to finish..."); + while (!response.isDone()) {} } } } diff --git a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java index 14f64dee..fae0f721 100644 --- a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java @@ -24,9 +24,12 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; import com.google.cloud.retail.v2.ProductServiceClient; +import com.google.cloud.retail.v2.RemoveFulfillmentPlacesMetadata; import com.google.cloud.retail.v2.RemoveFulfillmentPlacesRequest; +import com.google.cloud.retail.v2.RemoveFulfillmentPlacesResponse; import com.google.protobuf.Timestamp; import java.io.IOException; import java.time.Instant; @@ -74,11 +77,12 @@ public static void removeFulfillmentPlaces(String productName, String storeId) // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest); + OperationFuture response = + serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. - System.out.println("Remove fulfillment places, wait 30 seconds."); - TimeUnit.SECONDS.sleep(30); + System.out.println("Waiting for operation to finish..."); + while (!response.isDone()) {} } } } diff --git a/samples/interactive-tutorials/src/main/java/product/SetInventory.java b/samples/interactive-tutorials/src/main/java/product/SetInventory.java index fbf260db..2a21aca2 100644 --- a/samples/interactive-tutorials/src/main/java/product/SetInventory.java +++ b/samples/interactive-tutorials/src/main/java/product/SetInventory.java @@ -24,13 +24,10 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; -import com.google.cloud.retail.v2.FulfillmentInfo; -import com.google.cloud.retail.v2.PriceInfo; -import com.google.cloud.retail.v2.Product; +import com.google.cloud.retail.v2.*; import com.google.cloud.retail.v2.Product.Availability; -import com.google.cloud.retail.v2.ProductServiceClient; -import com.google.cloud.retail.v2.SetInventoryRequest; import com.google.protobuf.FieldMask; import com.google.protobuf.Int32Value; import com.google.protobuf.Timestamp; @@ -112,13 +109,13 @@ public static void setInventory(String productName) throws IOException, Interrup // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - serviceClient.setInventoryAsync(setInventoryRequest); + OperationFuture response = + serviceClient.setInventoryAsync(setInventoryRequest); + // This is a long-running operation and its result is not immediately + // present with get operations,thus we simulate wait with sleep method. + System.out.println("Waiting for operation to finish..."); + while (!response.isDone()) {} } - - // This is a long-running operation and its result is not immediately - // present with get operations,thus we simulate wait with sleep method. - System.out.println("Set inventory, wait 30 seconds."); - TimeUnit.SECONDS.sleep(30); } } From 67d7d5044a7377afa42689a33787d14afcfea5c8 Mon Sep 17 00:00:00 2001 From: Daria Firova Date: Thu, 1 Sep 2022 09:46:28 +0300 Subject: [PATCH 2/6] fix (samples) removed delays on lro. --- .../java/product/AddFulfillmentPlaces.java | 11 ++++++++--- .../java/product/RemoveFulfillmentPlaces.java | 10 +++++++--- .../src/main/java/product/SetInventory.java | 19 ++++++++----------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java index 31d94273..15d020e7 100644 --- a/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java @@ -24,9 +24,13 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; +import com.google.cloud.retail.v2.AddFulfillmentPlacesMetadata; import com.google.cloud.retail.v2.AddFulfillmentPlacesRequest; +import com.google.cloud.retail.v2.AddFulfillmentPlacesResponse; import com.google.cloud.retail.v2.ProductServiceClient; +import com.google.longrunning.Operation; import com.google.protobuf.Timestamp; import java.io.IOException; import java.time.Instant; @@ -74,11 +78,12 @@ public static void addFulfillmentPlaces(String productName, String placeId) // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest); + OperationFuture response = + serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. - System.out.println("Add fulfillment places, wait 45 seconds: "); - TimeUnit.SECONDS.sleep(45); + System.out.println("Waiting for operation to finish..."); + while (!response.isDone()) {} } } } diff --git a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java index 14f64dee..fae0f721 100644 --- a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java @@ -24,9 +24,12 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; import com.google.cloud.retail.v2.ProductServiceClient; +import com.google.cloud.retail.v2.RemoveFulfillmentPlacesMetadata; import com.google.cloud.retail.v2.RemoveFulfillmentPlacesRequest; +import com.google.cloud.retail.v2.RemoveFulfillmentPlacesResponse; import com.google.protobuf.Timestamp; import java.io.IOException; import java.time.Instant; @@ -74,11 +77,12 @@ public static void removeFulfillmentPlaces(String productName, String storeId) // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest); + OperationFuture response = + serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. - System.out.println("Remove fulfillment places, wait 30 seconds."); - TimeUnit.SECONDS.sleep(30); + System.out.println("Waiting for operation to finish..."); + while (!response.isDone()) {} } } } diff --git a/samples/interactive-tutorials/src/main/java/product/SetInventory.java b/samples/interactive-tutorials/src/main/java/product/SetInventory.java index fbf260db..2a21aca2 100644 --- a/samples/interactive-tutorials/src/main/java/product/SetInventory.java +++ b/samples/interactive-tutorials/src/main/java/product/SetInventory.java @@ -24,13 +24,10 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; -import com.google.cloud.retail.v2.FulfillmentInfo; -import com.google.cloud.retail.v2.PriceInfo; -import com.google.cloud.retail.v2.Product; +import com.google.cloud.retail.v2.*; import com.google.cloud.retail.v2.Product.Availability; -import com.google.cloud.retail.v2.ProductServiceClient; -import com.google.cloud.retail.v2.SetInventoryRequest; import com.google.protobuf.FieldMask; import com.google.protobuf.Int32Value; import com.google.protobuf.Timestamp; @@ -112,13 +109,13 @@ public static void setInventory(String productName) throws IOException, Interrup // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - serviceClient.setInventoryAsync(setInventoryRequest); + OperationFuture response = + serviceClient.setInventoryAsync(setInventoryRequest); + // This is a long-running operation and its result is not immediately + // present with get operations,thus we simulate wait with sleep method. + System.out.println("Waiting for operation to finish..."); + while (!response.isDone()) {} } - - // This is a long-running operation and its result is not immediately - // present with get operations,thus we simulate wait with sleep method. - System.out.println("Set inventory, wait 30 seconds."); - TimeUnit.SECONDS.sleep(30); } } From 3341b600fcfe93d587e458e242faef7936d1b875 Mon Sep 17 00:00:00 2001 From: Daria Firova Date: Mon, 5 Sep 2022 09:37:58 +0300 Subject: [PATCH 3/6] pr fix: replaced while with polling. --- .../src/main/java/product/AddFulfillmentPlaces.java | 12 ++++-------- .../main/java/product/RemoveFulfillmentPlaces.java | 7 ++++--- .../src/main/java/product/SetInventory.java | 7 ++++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java index 15d020e7..1d0b0527 100644 --- a/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/AddFulfillmentPlaces.java @@ -24,18 +24,14 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; -import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; -import com.google.cloud.retail.v2.AddFulfillmentPlacesMetadata; import com.google.cloud.retail.v2.AddFulfillmentPlacesRequest; -import com.google.cloud.retail.v2.AddFulfillmentPlacesResponse; import com.google.cloud.retail.v2.ProductServiceClient; -import com.google.longrunning.Operation; import com.google.protobuf.Timestamp; import java.io.IOException; import java.time.Instant; import java.util.UUID; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.ExecutionException; public class AddFulfillmentPlaces { @@ -78,12 +74,12 @@ public static void addFulfillmentPlaces(String productName, String placeId) // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - OperationFuture response = - serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. System.out.println("Waiting for operation to finish..."); - while (!response.isDone()) {} + serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest).getPollingFuture().get(); + } catch (ExecutionException e) { + System.out.printf("Exception occurred during longrunning operation: %s%n", e.getMessage()); } } } diff --git a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java index fae0f721..78732b8d 100644 --- a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.time.Instant; import java.util.UUID; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; public class RemoveFulfillmentPlaces { @@ -77,12 +78,12 @@ public static void removeFulfillmentPlaces(String productName, String storeId) // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - OperationFuture response = - serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. System.out.println("Waiting for operation to finish..."); - while (!response.isDone()) {} + serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest).getPollingFuture().get(); + } catch (ExecutionException e) { + System.out.printf("Exception occurred during longrunning operation: %s%n", e.getMessage()); } } } diff --git a/samples/interactive-tutorials/src/main/java/product/SetInventory.java b/samples/interactive-tutorials/src/main/java/product/SetInventory.java index 2a21aca2..cf94565b 100644 --- a/samples/interactive-tutorials/src/main/java/product/SetInventory.java +++ b/samples/interactive-tutorials/src/main/java/product/SetInventory.java @@ -35,6 +35,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.UUID; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; public class SetInventory { @@ -109,12 +110,12 @@ public static void setInventory(String productName) throws IOException, Interrup // completing all of your requests, call the "close" method on the client to // safely clean up any remaining background resources. try (ProductServiceClient serviceClient = ProductServiceClient.create()) { - OperationFuture response = - serviceClient.setInventoryAsync(setInventoryRequest); // This is a long-running operation and its result is not immediately // present with get operations,thus we simulate wait with sleep method. System.out.println("Waiting for operation to finish..."); - while (!response.isDone()) {} + serviceClient.setInventoryAsync(setInventoryRequest).getPollingFuture().get(); + } catch (ExecutionException e) { + System.out.printf("Exception occurred during longrunning operation: %s%n", e.getMessage()); } } } From 52931eb1810adf24aae94013e0676f54774c9c88 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 12 Sep 2022 16:30:31 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../src/main/java/product/RemoveFulfillmentPlaces.java | 4 ---- .../src/main/java/product/SetInventory.java | 2 -- 2 files changed, 6 deletions(-) diff --git a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java index 78732b8d..8341d69e 100644 --- a/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java +++ b/samples/interactive-tutorials/src/main/java/product/RemoveFulfillmentPlaces.java @@ -24,18 +24,14 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; -import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; import com.google.cloud.retail.v2.ProductServiceClient; -import com.google.cloud.retail.v2.RemoveFulfillmentPlacesMetadata; import com.google.cloud.retail.v2.RemoveFulfillmentPlacesRequest; -import com.google.cloud.retail.v2.RemoveFulfillmentPlacesResponse; import com.google.protobuf.Timestamp; import java.io.IOException; import java.time.Instant; import java.util.UUID; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; public class RemoveFulfillmentPlaces { diff --git a/samples/interactive-tutorials/src/main/java/product/SetInventory.java b/samples/interactive-tutorials/src/main/java/product/SetInventory.java index cf94565b..20efe2c4 100644 --- a/samples/interactive-tutorials/src/main/java/product/SetInventory.java +++ b/samples/interactive-tutorials/src/main/java/product/SetInventory.java @@ -24,7 +24,6 @@ import static setup.SetupCleanup.deleteProduct; import static setup.SetupCleanup.getProduct; -import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.ServiceOptions; import com.google.cloud.retail.v2.*; import com.google.cloud.retail.v2.Product.Availability; @@ -36,7 +35,6 @@ import java.util.Arrays; import java.util.UUID; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; public class SetInventory { From d8d57a6897eb10d48b74e0d5edcfd69a88e3bb3d Mon Sep 17 00:00:00 2001 From: Daria Firova Date: Tue, 13 Sep 2022 10:09:32 +0300 Subject: [PATCH 5/6] pr fix: fixed tests. --- .../src/test/java/product/AddFulfillmentPlacesTest.java | 2 +- .../src/test/java/product/RemoveFulfillmentPlacesTest.java | 2 +- .../src/test/java/product/SetInventoryTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java b/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java index e561cb42..9617153d 100644 --- a/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java +++ b/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java @@ -65,7 +65,7 @@ public void testAddFulfillment() { String outputResult = bout.toString(); assertThat(outputResult).contains("Add fulfilment places with current date"); - assertThat(outputResult).contains("Add fulfillment places, wait 45 seconds"); + assertThat(outputResult).contains("Waiting for operation to finish..."); } @After diff --git a/samples/interactive-tutorials/src/test/java/product/RemoveFulfillmentPlacesTest.java b/samples/interactive-tutorials/src/test/java/product/RemoveFulfillmentPlacesTest.java index bddaca37..fd4d041e 100644 --- a/samples/interactive-tutorials/src/test/java/product/RemoveFulfillmentPlacesTest.java +++ b/samples/interactive-tutorials/src/test/java/product/RemoveFulfillmentPlacesTest.java @@ -64,7 +64,7 @@ public void testRemoveFulfillmentPlaces() { String outputResult = bout.toString(); assertThat(outputResult).contains("Remove fulfilment places with current date"); - assertThat(outputResult).contains("Remove fulfillment places, wait 30 seconds"); + assertThat(outputResult).contains("Waiting for operation to finish..."); assertThat(outputResult).contains("Delete product request name"); assertThat(outputResult).contains("was deleted"); } diff --git a/samples/interactive-tutorials/src/test/java/product/SetInventoryTest.java b/samples/interactive-tutorials/src/test/java/product/SetInventoryTest.java index 747da07e..12d0f716 100644 --- a/samples/interactive-tutorials/src/test/java/product/SetInventoryTest.java +++ b/samples/interactive-tutorials/src/test/java/product/SetInventoryTest.java @@ -64,7 +64,7 @@ public void testSetInventoryTest() { String outputResult = bout.toString(); assertThat(outputResult).contains("Set inventory request"); - assertThat(outputResult).contains("Set inventory, wait 30 seconds"); + assertThat(outputResult).contains("Waiting for operation to finish..."); } @After From e65088e98d03bd117190f374788a755c83764534 Mon Sep 17 00:00:00 2001 From: Daria Firova Date: Wed, 14 Sep 2022 10:44:08 +0300 Subject: [PATCH 6/6] pr fix: fixed test. --- .../src/test/java/product/AddFulfillmentPlacesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java b/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java index 9617153d..c80d7d65 100644 --- a/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java +++ b/samples/interactive-tutorials/src/test/java/product/AddFulfillmentPlacesTest.java @@ -64,7 +64,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException public void testAddFulfillment() { String outputResult = bout.toString(); - assertThat(outputResult).contains("Add fulfilment places with current date"); + assertThat(outputResult).contains("Add fulfilment places"); assertThat(outputResult).contains("Waiting for operation to finish..."); }