Skip to content

Commit

Permalink
Test redone to use async responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-beauregard committed Oct 8, 2020
1 parent 4808bee commit 6176e0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public Response<Void> purchaseSearchWithResponse(String searchId, Context contex
* until it gets a result from the server
* @return A {@link SyncPoller} object with the search result
*/
@ServiceMethod(returns = ReturnType.SINGLE)
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<PhoneNumberSearch, PhoneNumberSearch> beginCreateSearch(
CreateSearchOptions options, Duration pollInterval) {
return phoneNumberAsyncClient.beginCreateSearch(options, pollInterval).getSyncPoller();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.azure.communication.common.PhoneNumber;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.util.polling.SyncPoller;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.AsyncPollResponse;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.Context;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
Expand Down Expand Up @@ -480,10 +482,12 @@ public void beginCreateSearch() {

Duration duration = Duration.ofSeconds(1);
PhoneNumberAsyncClient client = this.getClient();
SyncPoller<PhoneNumberSearch, PhoneNumberSearch> res =
client.beginCreateSearch(createSearchOptions, duration).getSyncPoller();
res.waitForCompletion();
PhoneNumberSearch testResult = res.getFinalResult();
PollerFlux<PhoneNumberSearch, PhoneNumberSearch> poller =
client.beginCreateSearch(createSearchOptions, duration);
AsyncPollResponse<PhoneNumberSearch, PhoneNumberSearch> asyncRes =
poller.takeUntil(apr -> apr.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED)
.blockLast();
PhoneNumberSearch testResult = asyncRes.getValue();
assertEquals(testResult.getPhoneNumbers().size(), 2);
assertNotNull(testResult.getSearchId());
}
Expand Down

0 comments on commit 6176e0a

Please sign in to comment.