Skip to content

Commit

Permalink
fix(samples): Removed delays on LRO (#527)
Browse files Browse the repository at this point in the history
* fix (samples) Removed delays on LRO.

* fix (samples) removed delays on lro.

* pr fix: replaced while with polling.

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* pr fix: fixed tests.

* pr fix: fixed test.

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
dfirova and gcf-owl-bot[bot] authored Sep 26, 2022
1 parent 059da48 commit 6c39da2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.cloud.retail.v2.ProductServiceClient;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;

public class AddFulfillmentPlaces {

Expand Down Expand Up @@ -72,11 +72,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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.cloud.retail.v2.RemoveFulfillmentPlacesRequest;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;

public class RemoveFulfillmentPlaces {

Expand Down Expand Up @@ -73,11 +73,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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@
import static setup.SetupCleanup.getProduct;

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 java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;

public class SetInventory {

Expand Down Expand Up @@ -106,12 +102,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()) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testAddFulfillment() {
String outputResult = bout.toString();

assertThat(outputResult).contains("Add fulfilment places");
assertThat(outputResult).contains("Add fulfillment places, wait 45 seconds");
assertThat(outputResult).contains("Waiting for operation to finish...");
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c39da2

Please sign in to comment.