From 6cb58925759471ee19ea50b64f7b23f5edd48ef1 Mon Sep 17 00:00:00 2001 From: Jorge Beauregard Date: Thu, 29 Oct 2020 13:13:08 -0600 Subject: [PATCH] Addressed comments --- .../PhoneNumberAsyncClient.java | 9 ++++--- ...PhoneNumberAsyncClientIntegrationTest.java | 26 ++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/PhoneNumberAsyncClient.java b/sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/PhoneNumberAsyncClient.java index 1525faecbfa21..347523d578a24 100644 --- a/sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/PhoneNumberAsyncClient.java +++ b/sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/PhoneNumberAsyncClient.java @@ -911,7 +911,11 @@ Mono> purchaseSearchFetchResultOperation() { public PollerFlux beginReleasePhoneNumbers(List phoneNumbers, Duration pollInterval) { Objects.requireNonNull(phoneNumbers, "'phoneNumbers' cannot be null."); - Objects.requireNonNull(pollInterval, "'pollInterval' cannot be null."); + + if (pollInterval == null) { + pollInterval = defaultPollInterval; + } + return new PollerFlux(pollInterval, releaseNumbersActivationOperation(phoneNumbers), releaseNumbersPollOperation(), @@ -933,8 +937,7 @@ Mono> purchaseSearchFetchResultOperation() { }; } - private Function, - Mono>> + private Function, Mono>> releaseNumbersPollOperation() { return pollingContext -> getReleaseById(pollingContext.getLatestResponse().getValue().getReleaseId()) diff --git a/sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/PhoneNumberAsyncClientIntegrationTest.java b/sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/PhoneNumberAsyncClientIntegrationTest.java index 9259459219fe2..daa3df16d6408 100644 --- a/sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/PhoneNumberAsyncClientIntegrationTest.java +++ b/sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/PhoneNumberAsyncClientIntegrationTest.java @@ -469,12 +469,13 @@ public void beginCreateSearch(HttpClient httpClient) { PhoneNumberAsyncClient client = this.getClient(httpClient); PollerFlux poller = client.beginCreateSearch(createSearchOptions, duration); - AsyncPollResponse asyncRes = - poller.takeUntil(apr -> apr.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) - .blockLast(); - PhoneNumberSearch testResult = asyncRes.getValue(); - assertEquals(testResult.getPhoneNumbers().size(), 2); - assertNotNull(testResult.getSearchId()); + Mono> asyncRes = poller.last(); + StepVerifier.create(asyncRes) + .assertNext(item -> { + assertEquals(item.getValue().getPhoneNumbers().size(), 2); + assertNotNull(item.getValue().getSearchId()); + }) + .verifyComplete(); } @ParameterizedTest @@ -500,14 +501,15 @@ public void beginReleasePhoneNumbers(HttpClient httpClient) { PhoneNumber phoneNumber = new PhoneNumber(PHONENUMBER_TO_RELEASE); List phoneNumbers = new ArrayList<>(); phoneNumbers.add(phoneNumber); - Duration pollInterval = Duration.ofSeconds(5); + Duration pollInterval = Duration.ofSeconds(1); PollerFlux poller = this.getClient(httpClient).beginReleasePhoneNumbers(phoneNumbers, pollInterval); - AsyncPollResponse asyncRes = - poller.takeUntil(apr -> apr.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED). - blockLast(); - PhoneNumberRelease testResult = asyncRes.getValue(); - assertEquals(ReleaseStatus.COMPLETE, testResult.getStatus()); + Mono> asyncRes = poller.last(); + StepVerifier.create(asyncRes) + .assertNext(item -> { + assertEquals(ReleaseStatus.COMPLETE, item.getValue().getStatus()); + }) + .verifyComplete(); } private PhoneNumberAsyncClient getClient(HttpClient httpClient) {