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 @@ -31,7 +31,7 @@
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 {

Expand Down Expand Up @@ -74,11 +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()) {
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...");
serviceClient.addFulfillmentPlacesAsync(addFulfillmentPlacesRequest).getPollingFuture().get();
} catch (ExecutionException e) {
System.out.printf("Exception occurred during longrunning operation: %s%n", e.getMessage());
}
}
}
Expand Down
Expand Up @@ -24,13 +24,17 @@
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 {
Expand Down Expand Up @@ -74,11 +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()) {
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...");
serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest).getPollingFuture().get();
} catch (ExecutionException e) {
System.out.printf("Exception occurred during longrunning operation: %s%n", e.getMessage());
}
}
}
Expand Down
Expand Up @@ -24,20 +24,18 @@
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;
import java.io.IOException;
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 {
Expand Down Expand Up @@ -112,13 +110,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);
// 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...");
serviceClient.setInventoryAsync(setInventoryRequest).getPollingFuture().get();
} catch (ExecutionException e) {
System.out.printf("Exception occurred during longrunning operation: %s%n", e.getMessage());
}

// 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