Skip to content

Commit

Permalink
Merge branch 'main' into AzCore_DontLetLinkageErrorsLeakFromSpiLoading
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft committed Sep 23, 2024
2 parents e1dc87a + 537d6e0 commit 2874b28
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion sdk/fabric/azure-resourcemanager-fabric/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.26.2</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.27.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ private HttpPipeline getHttpPipeline() {
* Sets the service endpoint for the Azure AI Search instance.
*
* @param endpoint The URL of the Azure AI Search instance.
* @return The updated SearchClientBuilder object.
* @throws IllegalArgumentException If {@code endpoint} is null or it cannot be parsed into a valid URL.
* @return The updated SearchClientBuilder object.0ed into a valid URL.
*/
@Override
public SearchClientBuilder endpoint(String endpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void buildSyncClientTest() {
.credential(SEARCH_CREDENTIAL)
.indexName(INDEX_NAME)
.serviceVersion(API_VERSION)
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildClient();

assertNotNull(client);
Expand All @@ -59,6 +60,7 @@ public void buildSyncClientUsingDefaultApiVersionTest() {
.endpoint(SEARCH_ENDPOINT)
.credential(SEARCH_CREDENTIAL)
.indexName(INDEX_NAME)
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildClient();

assertNotNull(client);
Expand All @@ -72,6 +74,7 @@ public void buildAsyncClientTest() {
.credential(SEARCH_CREDENTIAL)
.indexName(INDEX_NAME)
.serviceVersion(API_VERSION)
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildAsyncClient();

assertNotNull(client);
Expand All @@ -84,6 +87,7 @@ public void buildAsyncClientUsingDefaultApiVersionTest() {
.endpoint(SEARCH_ENDPOINT)
.credential(SEARCH_CREDENTIAL)
.indexName(INDEX_NAME)
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildAsyncClient();

assertNotNull(client);
Expand All @@ -96,6 +100,7 @@ public void whenBuildClientAndVerifyPropertiesThenSuccess() {
.endpoint(SEARCH_ENDPOINT)
.credential(SEARCH_CREDENTIAL)
.indexName(INDEX_NAME)
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildClient();

assertEquals(SEARCH_ENDPOINT, client.getEndpoint());
Expand All @@ -105,6 +110,7 @@ public void whenBuildClientAndVerifyPropertiesThenSuccess() {
.endpoint(SEARCH_ENDPOINT)
.credential(SEARCH_CREDENTIAL)
.indexName(INDEX_NAME)
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildAsyncClient();

assertEquals(SEARCH_ENDPOINT, asyncClient.getEndpoint());
Expand Down Expand Up @@ -214,6 +220,7 @@ public void bothRetryOptionsAndRetryPolicySet() {
.serviceVersion(API_VERSION)
.retryOptions(new RetryOptions(new ExponentialBackoffOptions()))
.retryPolicy(new RetryPolicy())
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.buildClient());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ public void batchSplitsUntilOneAndPartiallyFailsAsync() {
public void operationsThrowAfterClientIsClosed(
Consumer<SearchIndexingBufferedSender<Map<String, Object>>> operation) {
SearchIndexingBufferedSender<Map<String, Object>> batchingClient = getSearchClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.bufferedSender(HOTEL_DOCUMENT_TYPE)
.documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER)
.autoFlush(false)
Expand Down Expand Up @@ -968,6 +969,7 @@ static Stream<Consumer<SearchIndexingBufferedSender<Map<String, Object>>>> opera
public void operationsThrowAfterClientIsClosedAsync(
Function<SearchIndexingBufferedAsyncSender<Map<String, Object>>, Mono<Void>> operation) {
SearchIndexingBufferedAsyncSender<Map<String, Object>> batchingClient = getSearchClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.bufferedSender(HOTEL_DOCUMENT_TYPE)
.documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER)
.autoFlush(false)
Expand Down Expand Up @@ -999,6 +1001,7 @@ static Stream<Function<SearchIndexingBufferedAsyncSender<Map<String, Object>>, M
@Test
public void closingTwiceDoesNotThrow() {
SearchIndexingBufferedSender<Map<String, Object>> batchingClient = getSearchClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.bufferedSender(HOTEL_DOCUMENT_TYPE)
.documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER)
.autoFlush(false)
Expand All @@ -1012,6 +1015,7 @@ public void closingTwiceDoesNotThrow() {
@Test
public void closingTwiceDoesNotThrowAsync() {
SearchIndexingBufferedAsyncSender<Map<String, Object>> batchingClient = getSearchClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.bufferedSender(HOTEL_DOCUMENT_TYPE)
.documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER)
.autoFlush(false)
Expand Down Expand Up @@ -1453,6 +1457,7 @@ public void delayResetsAfterNo503sAsync() {
public void emptyBatchIsNeverSent() {
AtomicInteger requestCount = new AtomicInteger();
SearchIndexingBufferedSender<Map<String, Object>> batchingClient = getSearchClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.addPolicy((context, next) -> {
requestCount.incrementAndGet();
return next.process();
Expand All @@ -1474,6 +1479,7 @@ public void emptyBatchIsNeverSent() {
public void emptyBatchIsNeverSentAsync() {
AtomicInteger requestCount = new AtomicInteger();
SearchIndexingBufferedAsyncSender<Map<String, Object>> batchingClient = getSearchClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.addPolicy((context, next) -> {
requestCount.incrementAndGet();
return next.process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.search.documents.indexes.IndexesTestHelpers;
import com.azure.search.documents.indexes.SearchIndexAsyncClient;
import com.azure.search.documents.indexes.SearchIndexClient;
import com.azure.search.documents.indexes.SearchIndexClientBuilder;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.time.Duration;
Expand Down Expand Up @@ -96,6 +98,7 @@ private SearchIndexClient getSearchIndexClient() {

private SearchIndexClient getSearchIndexClient(RetryPolicy retryPolicy) {
return new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint("https://test1.search.windows.net")
.credential(new AzureKeyCredential("api-key"))
.retryPolicy(retryPolicy)
Expand All @@ -104,6 +107,7 @@ private SearchIndexClient getSearchIndexClient(RetryPolicy retryPolicy) {

private SearchIndexAsyncClient getSearchIndexAsyncClient() {
return new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint("https://test1.search.windows.net")
.credential(new AzureKeyCredential("api-key"))
.buildAsyncClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ public class IndexManagementTests extends SearchTestBase {

@BeforeAll
public static void setupSharedResources() {
sharedSynonymMap = new SynonymMap("sharedhotelmotel").setSynonyms("hotel,motel");

if (TEST_MODE == TestMode.PLAYBACK) {
return;
}

sharedIndexClient = new SearchIndexClientBuilder()
.endpoint(ENDPOINT)
.credential(TestHelpers.getTestTokenCredential())
.buildClient();

sharedSynonymMap = new SynonymMap("sharedhotelmotel").setSynonyms("hotel,motel");

if (TEST_MODE != TestMode.PLAYBACK) {
sharedSynonymMap = sharedIndexClient.createSynonymMap(sharedSynonymMap);
}
sharedSynonymMap = sharedIndexClient.createSynonymMap(sharedSynonymMap);
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ private void createAndValidateIndexerAsync(SearchIndexer indexer) {

@BeforeAll
public static void setupSharedResources() {
sharedSkillset = createSkillsetObject();
sharedDatasource = createSharedDataSource();
sharedIndex = createTestIndexForLiveDatasource();

if (TEST_MODE == TestMode.PLAYBACK) {
return;
}

sharedIndexerClient = new SearchIndexerClientBuilder()
.endpoint(ENDPOINT)
.credential(TestHelpers.getTestTokenCredential())
Expand All @@ -130,15 +138,9 @@ public static void setupSharedResources() {
.credential(TestHelpers.getTestTokenCredential())
.buildClient();

sharedSkillset = createSkillsetObject();
sharedDatasource = createSharedDataSource();
sharedIndex = createTestIndexForLiveDatasource();

if (TEST_MODE != TestMode.PLAYBACK) {
sharedSkillset = sharedIndexerClient.createSkillset(sharedSkillset);
sharedDatasource = sharedIndexerClient.createOrUpdateDataSourceConnection(sharedDatasource);
sharedIndex = sharedIndexClient.createIndex(sharedIndex);
}
sharedSkillset = sharedIndexerClient.createSkillset(sharedSkillset);
sharedDatasource = sharedIndexerClient.createOrUpdateDataSourceConnection(sharedDatasource);
sharedIndex = sharedIndexClient.createIndex(sharedIndex);
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package com.azure.search.documents.indexes;

import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.test.http.MockHttpResponse;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.util.stream.Stream;
Expand All @@ -26,6 +28,7 @@ public void apiCallReturnsError(Publisher<?> apiCall) {

static Stream<Publisher<?>> apiCallReturnsErrorSupplier() {
SearchIndexerAsyncClient client = new SearchIndexerClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint("https://fake.com")
.credential(new AzureKeyCredential("fake"))
.buildAsyncClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class SearchIndexClientBuilderTests {
@Test
public void buildSyncClientTest() {
SearchIndexClient client = new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.serviceVersion(apiVersion)
Expand All @@ -61,6 +63,7 @@ public void buildSyncClientTest() {
@Test
public void buildSyncClientUsingDefaultApiVersionTest() {
SearchIndexClient client = new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.buildClient();
Expand All @@ -72,6 +75,7 @@ public void buildSyncClientUsingDefaultApiVersionTest() {
@Test
public void buildAsyncClientTest() {
SearchIndexAsyncClient client = new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.serviceVersion(apiVersion)
Expand All @@ -84,6 +88,7 @@ public void buildAsyncClientTest() {
@Test
public void buildAsyncClientUsingDefaultApiVersionTest() {
SearchIndexAsyncClient client = new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.buildAsyncClient();
Expand All @@ -95,13 +100,15 @@ public void buildAsyncClientUsingDefaultApiVersionTest() {
@Test
public void whenBuildClientAndVerifyPropertiesThenSuccess() {
SearchIndexClient client = new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.buildClient();

assertEquals(searchEndpoint, client.getEndpoint());

SearchIndexAsyncClient asyncClient = new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.serviceVersion(apiVersion)
Expand Down Expand Up @@ -141,7 +148,7 @@ public void serviceClientFreshDateOnRetry() throws MalformedURLException {

public static HttpRequest request(String url) throws MalformedURLException {
return new HttpRequest(HttpMethod.HEAD,
new URL(url), new HttpHeaders().set("Content-Length", "0"),
new URL(url), new HttpHeaders().set(HttpHeaderName.CONTENT_LENGTH, "0"),
Flux.empty());
}

Expand All @@ -151,11 +158,11 @@ public static final class FreshDateTestClient implements HttpClient {
@Override
public Mono<HttpResponse> send(HttpRequest request) {
if (firstDate == null) {
firstDate = convertToDateObject(request.getHeaders().getValue("Date"));
firstDate = convertToDateObject(request.getHeaders().getValue(HttpHeaderName.DATE));
return Mono.error(new IOException("IOException!"));
}

assert !firstDate.equals(convertToDateObject(request.getHeaders().getValue("Date")));
assert !firstDate.equals(convertToDateObject(request.getHeaders().getValue(HttpHeaderName.DATE)));
return Mono.just(new MockHttpResponse(request, 200));
}

Expand Down Expand Up @@ -195,7 +202,7 @@ public void applicationIdFallsBackToLogOptions() {
.httpLogOptions(new HttpLogOptions().setApplicationId("anOldApplication"))
.retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1))))
.httpClient(httpRequest -> {
assertTrue(httpRequest.getHeaders().getValue("User-Agent").contains("anOldApplication"));
assertTrue(httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT).contains("anOldApplication"));
return Mono.just(new MockHttpResponse(httpRequest, 400));
})
.buildClient();
Expand All @@ -212,7 +219,7 @@ public void clientOptionHeadersAreAddedLast() {
.setHeaders(Collections.singletonList(new Header("User-Agent", "custom"))))
.retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1))))
.httpClient(httpRequest -> {
assertEquals("custom", httpRequest.getHeaders().getValue("User-Agent"));
assertEquals("custom", httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT));
return Mono.just(new MockHttpResponse(httpRequest, 400));
})
.buildClient();
Expand All @@ -223,6 +230,7 @@ public void clientOptionHeadersAreAddedLast() {
@Test
public void bothRetryOptionsAndRetryPolicySet() {
assertThrows(IllegalStateException.class, () -> new SearchIndexClientBuilder()
.httpClient(request -> Mono.just(new MockHttpResponse(request, 200)))
.endpoint(searchEndpoint)
.credential(searchApiKeyCredential)
.serviceVersion(apiVersion)
Expand Down
Loading

0 comments on commit 2874b28

Please sign in to comment.