- * If logging configurations aren't provided HTTP requests and responses won't be logged. + * Sets the {@link HttpLogOptions logging configuration} to use when sending and receiving requests to and from + * the service. If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set. + * + *
Note: It is important to understand the precedence order of the HttpTrait APIs. In + * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and + * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally + * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this + * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the + * documentation of types that implement this trait to understand the full set of implications.
* - * @param logOptions The logging configuration for HTTP requests and responses. + * @param logOptions The {@link HttpLogOptions logging configuration} to use when sending and receiving requests to + * and from the service. * @return The updated SearchClientBuilder object. */ + @Override public SearchClientBuilder httpLogOptions(HttpLogOptions logOptions) { httpLogOptions = logOptions; return this; @@ -261,26 +292,44 @@ public static HttpLogOptions getDefaultLogOptions() { } /** - * Sets the client options such as application ID and custom headers to set on a request. + * Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is + * recommended that this method be called with an instance of the {@link HttpClientOptions} + * class (a subclass of the {@link ClientOptions} base class). The HttpClientOptions subclass provides more + * configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait + * interface. + * + *Note: It is important to understand the precedence order of the HttpTrait APIs. In + * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and + * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally + * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this + * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the + * documentation of types that implement this trait to understand the full set of implications.
* - * @param clientOptions The client options. + * @param clientOptions A configured instance of {@link HttpClientOptions}. * @return The updated SearchClientBuilder object. + * @see HttpClientOptions */ + @Override public SearchClientBuilder clientOptions(ClientOptions clientOptions) { this.clientOptions = clientOptions; return this; } /** - * Adds a pipeline policy to apply to each request sent. - *- * This method may be called multiple times, each time it is called the policy will be added to the end of added - * policy list. All policies will be added after the retry policy. + * Adds a {@link HttpPipelinePolicy pipeline policy} to apply on each request sent. + * + *
Note: It is important to understand the precedence order of the HttpTrait APIs. In + * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and + * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally + * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this + * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the + * documentation of types that implement this trait to understand the full set of implications.
* - * @param policy The pipeline policies to added to the policy list. + * @param policy A {@link HttpPipelinePolicy pipeline policy}. * @return The updated SearchClientBuilder object. * @throws NullPointerException If {@code policy} is null. */ + @Override public SearchClientBuilder addPolicy(HttpPipelinePolicy policy) { Objects.requireNonNull(policy, "'policy' cannot be null."); @@ -306,11 +355,19 @@ public SearchClientBuilder serializer(JsonSerializer jsonSerializer) { } /** - * Sets the HTTP client to use for sending requests and receiving responses. + * Sets the {@link HttpClient} to use for sending and receiving requests to and from the service. * - * @param client The HTTP client that will handle sending requests and receiving responses. + *Note: It is important to understand the precedence order of the HttpTrait APIs. In + * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and + * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally + * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this + * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the + * documentation of types that implement this trait to understand the full set of implications.
+ * + * @param client The {@link HttpClient} to use for requests. * @return The updated SearchClientBuilder object. */ + @Override public SearchClientBuilder httpClient(HttpClient client) { if (this.httpClient != null && client == null) { logger.info("HttpClient is being set to 'null' when it was previously configured."); @@ -321,14 +378,22 @@ public SearchClientBuilder httpClient(HttpClient client) { } /** - * Sets the HTTP pipeline to use for the service client. + * Sets the {@link HttpPipeline} to use for the service client. + * + *Note: It is important to understand the precedence order of the HttpTrait APIs. In + * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and + * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally + * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this + * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the + * documentation of types that implement this trait to understand the full set of implications.
** If {@code pipeline} is set, all other settings are ignored, aside from {@link #endpoint(String) endpoint} and * {@link #indexName(String) index} when building a {@link SearchClient} or {@link SearchAsyncClient}. * - * @param httpPipeline The HTTP pipeline to use for sending service requests and receiving responses. + * @param httpPipeline {@link HttpPipeline} to use for sending service requests and receiving responses. * @return The updated SearchClientBuilder object. */ + @Override public SearchClientBuilder pipeline(HttpPipeline httpPipeline) { if (this.httpPipeline != null && httpPipeline == null) { logger.info("HttpPipeline is being set to 'null' when it was previously configured."); @@ -347,6 +412,7 @@ public SearchClientBuilder pipeline(HttpPipeline httpPipeline) { * @param configuration The configuration store that will be used. * @return The updated SearchClientBuilder object. */ + @Override public SearchClientBuilder configuration(Configuration configuration) { this.configuration = configuration; return this; @@ -356,6 +422,8 @@ public SearchClientBuilder configuration(Configuration configuration) { * Sets the {@link HttpPipelinePolicy} that will attempt to retry requests when needed. *
* A default retry policy will be supplied if one isn't provided. + *
+ * Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}. * * @param retryPolicy The {@link RetryPolicy} that will attempt to retry requests when needed. * @return The updated SearchClientBuilder object. @@ -365,6 +433,27 @@ public SearchClientBuilder retryPolicy(RetryPolicy retryPolicy) { return this; } + /** + * Sets the {@link RetryOptions} for all the requests made through the client. + * + *
Note: It is important to understand the precedence order of the HttpTrait APIs. In + * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and + * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally + * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this + * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the + * documentation of types that implement this trait to understand the full set of implications.
+ *+ * Setting this is mutually exclusive with using {@link #retryPolicy(RetryPolicy)}. + * + * @param retryOptions The {@link RetryOptions} to use for all the requests made through the client. + * @return The updated SearchClientBuilder object. + */ + @Override + public SearchClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + /** * Sets the {@link SearchServiceVersion} that is used when making API requests. *
@@ -420,6 +509,8 @@ private SearchIndexingBufferedSenderBuilder() {
* @return A SearchIndexingBufferedSender with the options set from the builder.
* @throws NullPointerException If {@code indexName}, {@code endpoint}, or {@code documentKeyRetriever} are
* null.
+ * @throws IllegalStateException If both {@link #retryOptions(RetryOptions)}
+ * and {@link #retryPolicy(RetryPolicy)} have been set.
*/
public SearchIndexingBufferedSender
- * If logging configurations aren't provided HTTP requests and responses won't be logged.
+ * Sets the {@link HttpLogOptions logging configuration} to use when sending and receiving requests to and from
+ * the service. If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.
+ *
+ * Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications. Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications.
- * This method may be called multiple times, each time it is called the policy will be added to the end of added
- * policy list. All policies will be added after the retry policy.
+ * Adds a {@link HttpPipelinePolicy pipeline policy} to apply on each request sent.
+ *
+ * Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications. Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications. Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications.
* If {@code pipeline} is set, all other settings are ignored, aside from {@link #endpoint(String) endpoint} when
* building a {@link SearchIndexClient} or {@link SearchIndexAsyncClient}.
*
- * @param httpPipeline The HTTP pipeline to use for sending service requests and receiving responses.
+ * @param httpPipeline {@link HttpPipeline} to use for sending service requests and receiving responses.
* @return The updated SearchIndexClientBuilder object.
*/
+ @Override
public SearchIndexClientBuilder pipeline(HttpPipeline httpPipeline) {
if (this.httpPipeline != null && httpPipeline == null) {
logger.info("HttpPipeline is being set to 'null' when it was previously configured.");
@@ -278,6 +343,7 @@ public SearchIndexClientBuilder pipeline(HttpPipeline httpPipeline) {
* @param configuration The configuration store that will be used.
* @return The updated SearchIndexClientBuilder object.
*/
+ @Override
public SearchIndexClientBuilder configuration(Configuration configuration) {
this.configuration = configuration;
return this;
@@ -287,6 +353,8 @@ public SearchIndexClientBuilder configuration(Configuration configuration) {
* Sets the {@link HttpPipelinePolicy} that will attempt to retry requests when needed.
*
* A default retry policy will be supplied if one isn't provided.
+ *
+ * Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}.
*
* @param retryPolicy The {@link RetryPolicy} that will attempt to retry requests when needed.
* @return The updated SearchIndexClientBuilder object.
@@ -296,6 +364,27 @@ public SearchIndexClientBuilder retryPolicy(RetryPolicy retryPolicy) {
return this;
}
+ /**
+ * Sets the {@link RetryOptions} for all the requests made through the client.
+ *
+ * Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications.
+ * Setting this is mutually exclusive with using {@link #retryPolicy(RetryPolicy)}.
+ *
+ * @param retryOptions The {@link RetryOptions} to use for all the requests made through the client.
+ * @return The updated SearchIndexClientBuilder object.
+ */
+ @Override
+ public SearchIndexClientBuilder retryOptions(RetryOptions retryOptions) {
+ this.retryOptions = retryOptions;
+ return this;
+ }
+
/**
* Sets the {@link SearchServiceVersion} that is used when making API requests.
*
diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClientBuilder.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClientBuilder.java
index 1515b286a7449..2b5df0770113a 100644
--- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClientBuilder.java
+++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClientBuilder.java
@@ -4,16 +4,24 @@
package com.azure.search.documents.indexes;
import com.azure.core.annotation.ServiceClientBuilder;
+import com.azure.core.client.traits.AzureKeyCredentialTrait;
+import com.azure.core.client.traits.ConfigurationTrait;
+import com.azure.core.client.traits.EndpointTrait;
+import com.azure.core.client.traits.HttpTrait;
+import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelinePosition;
+import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
+import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
+import com.azure.core.util.HttpClientOptions;
import com.azure.core.util.logging.ClientLogger;
import com.azure.search.documents.SearchServiceVersion;
import com.azure.search.documents.implementation.util.Constants;
@@ -63,7 +71,12 @@
* @see SearchIndexerAsyncClient
*/
@ServiceClientBuilder(serviceClients = {SearchIndexerClient.class, SearchIndexerAsyncClient.class})
-public class SearchIndexerClientBuilder {
+public class SearchIndexerClientBuilder implements
+ AzureKeyCredentialTrait
- * If logging configurations aren't provided HTTP requests and responses won't be logged.
+ * Sets the {@link HttpLogOptions logging configuration} to use when sending and receiving requests to and from
+ * the service. If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.
+ *
+ * Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications. Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications.
- * This method may be called multiple times, each time it is called the policy will be added to the end of added
- * policy list. All policies will be added after the retry policy.
+ * Adds a {@link HttpPipelinePolicy pipeline policy} to apply on each request sent.
+ *
+ * Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications. Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications. Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications.
* If {@code pipeline} is set, all other settings are ignored, aside from {@link #endpoint(String) endpoint} when
* building a {@link SearchIndexerClient} or {@link SearchIndexerAsyncClient}.
*
- * @param httpPipeline The HTTP pipeline to use for sending service requests and receiving responses.
+ * @param httpPipeline {@link HttpPipeline} to use for sending service requests and receiving responses.
* @return The updated SearchIndexerClientBuilder object.
*/
+ @Override
public SearchIndexerClientBuilder pipeline(HttpPipeline httpPipeline) {
if (this.httpPipeline != null && httpPipeline == null) {
logger.info("HttpPipeline is being set to 'null' when it was previously configured.");
@@ -266,6 +332,7 @@ public SearchIndexerClientBuilder pipeline(HttpPipeline httpPipeline) {
* @param configuration The configuration store that will be used.
* @return The updated SearchIndexerClientBuilder object.
*/
+ @Override
public SearchIndexerClientBuilder configuration(Configuration configuration) {
this.configuration = configuration;
return this;
@@ -275,6 +342,8 @@ public SearchIndexerClientBuilder configuration(Configuration configuration) {
* Sets the {@link HttpPipelinePolicy} that will attempt to retry requests when needed.
*
* A default retry policy will be supplied if one isn't provided.
+ *
+ * Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}.
*
* @param retryPolicy The {@link RetryPolicy} that will attempt to retry requests when needed.
* @return The updated SearchIndexerClientBuilder object.
@@ -284,6 +353,27 @@ public SearchIndexerClientBuilder retryPolicy(RetryPolicy retryPolicy) {
return this;
}
+ /**
+ * Sets the {@link RetryOptions} for all the requests made through the client.
+ *
+ * Note: It is important to understand the precedence order of the HttpTrait APIs. In
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
+ * documentation of types that implement this trait to understand the full set of implications.
+ * Setting this is mutually exclusive with using {@link #retryPolicy(RetryPolicy)}.
+ *
+ * @param retryOptions The {@link RetryOptions} to use for all the requests made through the client.
+ * @return The updated SearchIndexerClientBuilder object.
+ */
+ @Override
+ public SearchIndexerClientBuilder retryOptions(RetryOptions retryOptions) {
+ this.retryOptions = retryOptions;
+ return this;
+ }
+
/**
* Sets the {@link SearchServiceVersion} that is used when making API requests.
*
diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java
index bdbe2dbc73d78..058c208fbb12d 100644
--- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java
+++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java
@@ -5,8 +5,10 @@
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.exception.HttpResponseException;
+import com.azure.core.http.policy.ExponentialBackoffOptions;
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.HttpLogOptions;
+import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.util.ClientOptions;
@@ -196,4 +198,16 @@ public void clientOptionHeadersAreAddedLast() {
assertThrows(HttpResponseException.class, searchClient::getDocumentCount);
}
+
+ @Test
+ public void bothRetryOptionsAndRetryPolicySet() {
+ assertThrows(IllegalStateException.class, () -> new SearchClientBuilder()
+ .endpoint(searchEndpoint)
+ .credential(searchApiKeyCredential)
+ .indexName(indexName)
+ .serviceVersion(apiVersion)
+ .retryOptions(new RetryOptions(new ExponentialBackoffOptions()))
+ .retryPolicy(new RetryPolicy())
+ .buildClient());
+ }
}
diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java
index 1b5f8fbf2d53a..0c2cfc79f8b09 100644
--- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java
+++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java
@@ -9,8 +9,10 @@
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
+import com.azure.core.http.policy.ExponentialBackoffOptions;
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.HttpLogOptions;
+import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.util.ClientOptions;
@@ -212,4 +214,15 @@ public void clientOptionHeadersAreAddedLast() {
assertThrows(HttpResponseException.class, searchIndexClient::getServiceStatistics);
}
+
+ @Test
+ public void bothRetryOptionsAndRetryPolicySet() {
+ assertThrows(IllegalStateException.class, () -> new SearchIndexClientBuilder()
+ .endpoint(searchEndpoint)
+ .credential(searchApiKeyCredential)
+ .serviceVersion(apiVersion)
+ .retryOptions(new RetryOptions(new ExponentialBackoffOptions()))
+ .retryPolicy(new RetryPolicy())
+ .buildClient());
+ }
}
diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java
index 463e0da2d685c..822bc0a7ac0fa 100644
--- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java
+++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java
@@ -9,8 +9,10 @@
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
+import com.azure.core.http.policy.ExponentialBackoffOptions;
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.HttpLogOptions;
+import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.util.ClientOptions;
@@ -212,4 +214,15 @@ public void clientOptionHeadersAreAddedLast() {
assertThrows(HttpResponseException.class, () -> searchIndexerClient.getIndexer("anindexer"));
}
+
+ @Test
+ public void bothRetryOptionsAndRetryPolicySet() {
+ assertThrows(IllegalStateException.class, () -> new SearchIndexerClientBuilder()
+ .endpoint(searchEndpoint)
+ .credential(searchApiKeyCredential)
+ .serviceVersion(apiVersion)
+ .retryOptions(new RetryOptions(new ExponentialBackoffOptions()))
+ .retryPolicy(new RetryPolicy())
+ .buildClient());
+ }
}