Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

fix(samples): Removed delays on LRO #527

Merged
merged 10 commits into from Sep 26, 2022
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AddFulfillmentPlacesResponse, AddFulfillmentPlacesMetadata> 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()) {}
dfirova marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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<RemoveFulfillmentPlacesResponse, RemoveFulfillmentPlacesMetadata> 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()) {}
}
}
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SetInventoryResponse, SetInventoryMetadata> 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);
}
}

Expand Down