From 221def1ebf3ae2795293b8f4dcda47415e895e16 Mon Sep 17 00:00:00 2001 From: ankitarorabit <48968483+ankitarorabit@users.noreply.github.com> Date: Thu, 25 Mar 2021 18:28:15 -0700 Subject: [PATCH] [Communication] Revert "[Communication] Change SMS APIs to be pageable (#20042)" (#20104) * Revert "[Communication] Change SMS APIs to be pageable (#20042)" This reverts commit 9c5d7bfa0ceb76218478dcb463f1af0e67307262. * Changes to keep * Update versions in the package POM * Include other valid APIView feedback * PR feedback * remove unused logger --- .../azure-communication-sms/CHANGELOG.md | 4 +- .../azure-communication-sms/README.md | 9 ++-- .../communication/sms/SmsAsyncClient.java | 36 ++++++---------- .../azure/communication/sms/SmsClient.java | 10 ++--- .../sms/samples/quickstart/ReadmeSamples.java | 9 ++-- .../sms/SmsAsyncClientTests.java | 42 ++++++++++--------- .../communication/sms/SmsClientTests.java | 6 +-- sdk/communication/pom.xml | 8 ++-- 8 files changed, 58 insertions(+), 66 deletions(-) diff --git a/sdk/communication/azure-communication-sms/CHANGELOG.md b/sdk/communication/azure-communication-sms/CHANGELOG.md index 79966eb6ada34..9c69f2fcc0d59 100644 --- a/sdk/communication/azure-communication-sms/CHANGELOG.md +++ b/sdk/communication/azure-communication-sms/CHANGELOG.md @@ -1,8 +1,6 @@ # Release History ## 1.0.0 (2021-03-29) - -### Breaking Change -- Changed the return type of the batch `Send` in `SmsClient` and `SmsAsyncClient` to `PagedIterable` and `PagedFlux`, respectively. +Updated `azure-communication-sms` version ## 1.0.0-beta.4 (2021-03-09) ### Added diff --git a/sdk/communication/azure-communication-sms/README.md b/sdk/communication/azure-communication-sms/README.md index ca7e48361cf94..07cce17e61b12 100644 --- a/sdk/communication/azure-communication-sms/README.md +++ b/sdk/communication/azure-communication-sms/README.md @@ -112,12 +112,12 @@ SmsSendOptions options = new SmsSendOptions(); options.setDeliveryReportEnabled(true); options.setTag("Marketing"); -Iterable sendResults = smsClient.send( +Iterable sendResults = smsClient.sendWithResponse( "", Arrays.asList("", ""), "Weekly Promotion", options /* Optional */, - Context.NONE); + Context.NONE).getValue(); for (SmsSendResult result : sendResults) { System.out.println("Message Id: " + result.getMessageId()); @@ -131,20 +131,21 @@ for (SmsSendResult result : sendResults) { SMS operations will throw an exception if the request to the server fails. Exceptions will not be thrown if the error is caused by an individual message, only if something fails with the overall request. Please use the `isSuccessful()` flag to validate each individual result to verify if the message was sent. - + ```java try { SmsSendOptions options = new SmsSendOptions(); options.setDeliveryReportEnabled(true); options.setTag("Marketing"); - PagedIterable smsSendResults = smsClient.send( + Response> sendResults = smsClient.sendWithResponse( "", Arrays.asList("", ""), "Weekly Promotion", options /* Optional */, Context.NONE); + Iterable smsSendResults = sendResults.getValue(); for (SmsSendResult result : smsSendResults) { if (result.isSuccessful()) { System.out.println("Successfully sent this message: " + result.getMessageId() + " to " + result.getTo()); diff --git a/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsAsyncClient.java b/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsAsyncClient.java index 427356d7409c1..6619b9e928ab8 100644 --- a/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsAsyncClient.java +++ b/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsAsyncClient.java @@ -14,8 +14,6 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.http.rest.PagedFlux; -import com.azure.core.http.rest.PagedResponseBase; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; @@ -97,9 +95,10 @@ Mono send(String from, String to, String message, SmsSendOptions * @param message message to send to recipient. * @return response for a successful send Sms request. */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux send(String from, Iterable to, String message) { - return send(from, to, message, null, null); + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> send(String from, Iterable to, String message) { + return sendWithResponse(from, to, message, null) + .map(response -> response.getValue()); } /** @@ -112,39 +111,28 @@ public PagedFlux send(String from, Iterable to, String me * for this message to the Azure Resource Event Grid. * @return response for a successful send Sms request. */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux send(String from, Iterable to, String message, SmsSendOptions options) { - return send(from, to, message, options, null); + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono>> sendWithResponse(String from, Iterable to, String message, SmsSendOptions options) { + return sendWithResponse(from, to, message, options, null); } - PagedFlux send(String from, Iterable to, String message, SmsSendOptions options, Context context) { + Mono>> sendWithResponse(String from, Iterable to, String message, SmsSendOptions options, Context context) { try { Objects.requireNonNull(from, "'from' cannot be null."); Objects.requireNonNull(to, "'to' cannot be null."); SendMessageRequest request = createSendMessageRequest(from, to, message, options); - - Mono>> responseMono = withContext(contextValue -> { + return withContext(contextValue -> { if (context != null) { contextValue = context; } return this.smsClient.sendWithResponseAsync(request, contextValue) .flatMap((Response response) -> { - List smsSendResults = convertSmsSendResults(response.getValue().getValue()); - return Mono.just(new SimpleResponse>(response, smsSendResults)); + Iterable smsSendResults = convertSmsSendResults(response.getValue().getValue()); + return Mono.just(new SimpleResponse>(response, smsSendResults)); }); }); - - return new PagedFlux<>(() -> responseMono.map(response -> new PagedResponseBase( - response.getRequest(), - response.getStatusCode(), - response.getHeaders(), - response.getValue(), - null, - null - ))); - } catch (RuntimeException ex) { - return new PagedFlux<>(() -> monoError(logger, ex)); + return monoError(logger, ex); } } diff --git a/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsClient.java b/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsClient.java index 5113a78d4cc42..b270fc2496667 100644 --- a/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsClient.java +++ b/sdk/communication/azure-communication-sms/src/main/java/com/azure/communication/sms/SmsClient.java @@ -8,7 +8,7 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; import com.azure.core.util.Context; /** @@ -59,8 +59,8 @@ public SmsSendResult send(String from, String to, String message, SmsSendOptions * @return response for a successful send Sms request. */ @ServiceMethod(returns = ReturnType.SINGLE) - public PagedIterable send(String from, Iterable to, String message) { - return new PagedIterable<>(smsAsyncClient.send(from, to, message)); + public Iterable send(String from, Iterable to, String message) { + return smsAsyncClient.send(from, to, message).block(); } /** @@ -75,7 +75,7 @@ public PagedIterable send(String from, Iterable to, Strin * @return response for a successful send Sms request. */ @ServiceMethod(returns = ReturnType.SINGLE) - public PagedIterable send(String from, Iterable to, String message, SmsSendOptions options, Context context) { - return new PagedIterable<>(smsAsyncClient.send(from, to, message, options, context)); + public Response> sendWithResponse(String from, Iterable to, String message, SmsSendOptions options, Context context) { + return smsAsyncClient.sendWithResponse(from, to, message, options, context).block(); } } diff --git a/sdk/communication/azure-communication-sms/src/samples/java/com/azure/communication/sms/samples/quickstart/ReadmeSamples.java b/sdk/communication/azure-communication-sms/src/samples/java/com/azure/communication/sms/samples/quickstart/ReadmeSamples.java index 62cc2f8c31486..1280d6289a99b 100644 --- a/sdk/communication/azure-communication-sms/src/samples/java/com/azure/communication/sms/samples/quickstart/ReadmeSamples.java +++ b/sdk/communication/azure-communication-sms/src/samples/java/com/azure/communication/sms/samples/quickstart/ReadmeSamples.java @@ -12,7 +12,7 @@ import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.netty.NettyAsyncHttpClientBuilder; -import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; import com.azure.core.util.Context; import com.azure.identity.DefaultAzureCredentialBuilder; @@ -117,12 +117,12 @@ public void sendMessageToGroupWithOptions() { options.setDeliveryReportEnabled(true); options.setTag("Marketing"); - Iterable sendResults = smsClient.send( + Iterable sendResults = smsClient.sendWithResponse( "", Arrays.asList("", ""), "Weekly Promotion", options /* Optional */, - Context.NONE); + Context.NONE).getValue(); for (SmsSendResult result : sendResults) { System.out.println("Message Id: " + result.getMessageId()); @@ -155,13 +155,14 @@ public void sendMessageTroubleShooting() { options.setDeliveryReportEnabled(true); options.setTag("Marketing"); - PagedIterable smsSendResults = smsClient.send( + Response> sendResults = smsClient.sendWithResponse( "", Arrays.asList("", ""), "Weekly Promotion", options /* Optional */, Context.NONE); + Iterable smsSendResults = sendResults.getValue(); for (SmsSendResult result : smsSendResults) { if (result.isSuccessful()) { System.out.println("Successfully sent this message: " + result.getMessageId() + " to " + result.getTo()); diff --git a/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsAsyncClientTests.java b/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsAsyncClientTests.java index b22d2fb41fac6..e46cfee308ada 100644 --- a/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsAsyncClientTests.java +++ b/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsAsyncClientTests.java @@ -7,12 +7,11 @@ import com.azure.communication.sms.models.SmsSendResult; import com.azure.core.credential.TokenCredential; import com.azure.core.exception.HttpResponseException; -import com.azure.core.http.rest.PagedFlux; -import com.azure.core.http.rest.PagedIterable; import com.azure.identity.DefaultAzureCredentialBuilder; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import com.azure.core.http.HttpClient; +import com.azure.core.http.rest.Response; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -62,9 +61,11 @@ public void sendSmsToGroup(HttpClient httpClient) { asyncClient = setupAsyncClient(builder, "sendSmsToGroup"); // Action & Assert - StepVerifier.create(asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE).next()) - .assertNext(result -> { - assertHappyPath(result); + StepVerifier.create(asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE)) + .assertNext((Iterable sendResults) -> { + for (SmsSendResult result : sendResults) { + assertHappyPath(result); + } }) .verifyComplete(); } @@ -80,11 +81,13 @@ public void sendSmsToGroupWithOptions(HttpClient httpClient) { options.setTag("New Tag"); // Action & Assert - PagedFlux response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE); - PagedIterable sendResults = new PagedIterable<>(response); - for (SmsSendResult result : sendResults) { - assertHappyPath(result); - } + StepVerifier.create(asyncClient.sendWithResponse(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE, options)) + .assertNext((Response> response) -> { + for (SmsSendResult result : response.getValue()) { + assertHappyPath(result); + } + }) + .verifyComplete(); } @ParameterizedTest @@ -95,11 +98,12 @@ public void sendSmsToSingleNumber(HttpClient httpClient) { asyncClient = setupAsyncClient(builder, "sendSmsToSingleNumber"); // Action & Assert - PagedFlux response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE); - PagedIterable sendResults = new PagedIterable<>(response); - for (SmsSendResult result : sendResults) { - assertHappyPath(result); - } + Mono response = asyncClient.send(FROM_PHONE_NUMBER, TO_PHONE_NUMBER, MESSAGE); + StepVerifier.create(response) + .assertNext(sendResult -> { + assertHappyPath(sendResult); + }) + .verifyComplete(); } @ParameterizedTest @@ -153,17 +157,17 @@ public void sendToFakePhoneNumber(HttpClient httpClient) { // Arrange SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient); asyncClient = setupAsyncClient(builder, "sendToFakePhoneNumber"); - PagedFlux smsSendResults = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList("+15550000000"), MESSAGE); + Mono> response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList("+15550000000"), MESSAGE); // Action & Assert - StepVerifier.create(smsSendResults) + StepVerifier.create(response) .assertNext(item -> { assertNotNull(item); }) .verifyComplete(); - Iterable smsSendResultList = smsSendResults.collectList().block(); - for (SmsSendResult result : smsSendResultList) { + Iterable smsSendResults = response.block(); + for (SmsSendResult result : smsSendResults) { assertFalse(result.isSuccessful()); assertEquals(result.getHttpStatusCode(), 400); } diff --git a/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsClientTests.java b/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsClientTests.java index ae8fe3a5473cb..dae2864c7a453 100644 --- a/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsClientTests.java +++ b/sdk/communication/azure-communication-sms/src/test/java/com/azure/communication/sms/SmsClientTests.java @@ -8,7 +8,7 @@ import com.azure.core.credential.TokenCredential; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; -import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; import com.azure.core.util.Context; import com.azure.identity.DefaultAzureCredentialBuilder; import org.junit.jupiter.params.ParameterizedTest; @@ -71,8 +71,8 @@ public void sendSmsToGroupWithOptions(HttpClient httpClient) { options.setDeliveryReportEnabled(true); options.setTag("New Tag"); // Action & Assert - PagedIterable sendResults = client.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE, options, Context.NONE); - for (SmsSendResult result : sendResults) { + Response> sendResults = client.sendWithResponse(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE, options, Context.NONE); + for (SmsSendResult result : sendResults.getValue()) { assertHappyPath(result); } } diff --git a/sdk/communication/pom.xml b/sdk/communication/pom.xml index 1cbea8ab15c22..6ba97b2dbc51e 100644 --- a/sdk/communication/pom.xml +++ b/sdk/communication/pom.xml @@ -24,17 +24,17 @@ com.azure azure-communication-chat - 1.0.0-beta.7 + 1.0.0 com.azure azure-communication-common - 1.0.0-beta.7 + 1.0.0 com.azure azure-communication-identity - 1.0.0-beta.7 + 1.0.0 com.azure @@ -44,7 +44,7 @@ com.azure azure-communication-sms - 1.0.0-beta.5 + 1.0.0