Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Cognitive Search to Test Proxy #33952

Merged
merged 10 commits into from
Apr 11, 2023
Merged
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion sdk/search/azure-search-documents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.15.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.16.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -813,6 +813,12 @@ static Hotel preparePascalCaseFieldsHotel(String key) {

@SuppressWarnings({"deprecation", "UseOfObsoleteDateTimeApi"})
static Hotel prepareSelectedFieldsHotel(String key) {
// Since Date doesn't have time zone information to make this test durable against time zones create the Date
// from an OffsetDateTime.
OffsetDateTime dateTime = OffsetDateTime.parse("2010-06-26T17:00:00.000+00:00")
.atZoneSameInstant(ZoneId.systemDefault())
.toOffsetDateTime();

return new Hotel()
.hotelId(key)
.hotelName("Countryside Hotel")
Expand All @@ -822,7 +828,7 @@ static Hotel prepareSelectedFieldsHotel(String key) {
.tags(Arrays.asList("24-hour front desk service", "coffee in lobby", "restaurant"))
.parkingIncluded(false)
.smokingAllowed(true)
.lastRenovationDate(new Date(2010 - 1900, Calendar.JUNE, 26, 13, 0, 0))
.lastRenovationDate(new Date(dateTime.getYear() - 1900, dateTime.getMonth().ordinal(), dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute()))
.rating(3)
.location(new GeoPoint(-78.940483, 35.904160))
.address(new HotelAddress().streetAddress("6910 Fayetteville Rd").city("Durham").stateProvince("NC").country("USA").postalCode("27713"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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.TestBase;
import com.azure.search.documents.indexes.IndexesTestHelpers;
import com.azure.search.documents.indexes.SearchIndexAsyncClient;
import com.azure.search.documents.indexes.SearchIndexClient;
Expand All @@ -20,7 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class SearchServiceSubClientTests extends TestBase {
public class SearchServiceSubClientTests extends SearchTestBase {

@Test
public void canGetIndexClientFromSearchClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.util.Configuration;
import com.azure.core.util.logging.ClientLogger;
Expand Down Expand Up @@ -62,7 +62,7 @@
/**
* Abstract base class for all Search API tests
*/
public abstract class SearchTestBase extends TestBase {
public abstract class SearchTestBase extends TestProxyTestBase {
protected static final String HOTELS_TESTS_INDEX_DATA_JSON = "HotelsTestsIndexData.json";
protected static final String ENDPOINT = Configuration.getGlobalConfiguration()
.get("SEARCH_SERVICE_ENDPOINT", "https://playback.search.windows.net");
Expand All @@ -72,19 +72,27 @@ public abstract class SearchTestBase extends TestBase {

private static final String STORAGE_CONNECTION_STRING = Configuration.getGlobalConfiguration()
.get("SEARCH_STORAGE_CONNECTION_STRING", "connectionString");
private static final String BLOB_CONTAINER_NAME = Configuration.getGlobalConfiguration()
.get("SEARCH_STORAGE_CONTAINER_NAME", "container");
private static final String BLOB_CONTAINER_NAME = "searchcontainer";

protected static final TestMode TEST_MODE = initializeTestMode();

private static final String FAKE_DESCRIPTION = "Some data source";

static final String HOTELS_DATA_JSON = "HotelsDataArray.json";
static final String HOTELS_DATA_JSON_WITHOUT_FR_DESCRIPTION = "HotelsDataArrayWithoutFr.json";

static final RetryPolicy SERVICE_THROTTLE_SAFE_RETRY_POLICY =
new RetryPolicy(new FixedDelay(3, Duration.ofSeconds(60)));

// @Override
// public void beforeEach(ExtensionContext extensionContext) {
// super.beforeEach(extensionContext);
// interceptorManager.addMatchers(Collections.singletonList(new CustomMatcher()
// .setExcludedHeaders(Arrays.asList("Connection", "Content-Length"))));
// interceptorManager.addSanitizers(Arrays.asList(
// new TestProxySanitizer("api-key", "REDACTED", TestProxySanitizerType.HEADER)
// ));
// }

alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
protected String createHotelIndex() {
return setupIndexFromJsonFile(HOTELS_TESTS_INDEX_DATA_JSON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import com.azure.search.documents.models.SearchResult;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import reactor.test.StepVerifier;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -278,13 +280,19 @@ public void canAnalyzeWithAllPossibleNamesAsync() {
searchIndexClient.createIndex(index);
indexesToCleanup.add(index.getName());

LEXICAL_ANALYZER_NAMES.parallelStream()
.map(an -> new AnalyzeTextOptions("One two", an))
.forEach(r -> searchIndexAsyncClient.analyzeText(index.getName(), r).blockLast());

LEXICAL_TOKENIZER_NAMES.parallelStream()
.map(tn -> new AnalyzeTextOptions("One two", tn))
.forEach(r -> searchIndexAsyncClient.analyzeText(index.getName(), r).blockLast());
Flux.fromIterable(LEXICAL_ANALYZER_NAMES)
.parallel()
.runOn(Schedulers.boundedElastic())
.flatMap(an -> searchIndexAsyncClient.analyzeText(index.getName(), new AnalyzeTextOptions("One two", an)))
.then()
.block();

Flux.fromIterable(LEXICAL_TOKENIZER_NAMES)
.parallel()
.runOn(Schedulers.boundedElastic())
.flatMap(tn -> searchIndexAsyncClient.analyzeText(index.getName(), new AnalyzeTextOptions("One two", tn)))
.then()
.block();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://REDACTED.search.windows.net/indexes('azsearch-autocomplete-shared-instance')/docs/search.post.autocomplete?api-version=2021-04-30-Preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-search-documents/11.6.0-beta.4 (17.0.5; Windows 11; 10.0)",
"x-ms-client-request-id" : "2f169b9c-1c57-4ea3-a542-67e9ac561a52",
"Content-Type" : "application/json"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "2f169b9c-1c57-4ea3-a542-67e9ac561a52",
"StatusCode" : "200",
"Date" : "Tue, 17 Jan 2023 20:21:13 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"client-request-id" : "2f169b9c-1c57-4ea3-a542-67e9ac561a52",
"elapsed-time" : "17",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "222",
"Body" : "{\"value\":[{\"text\":\"point\",\"queryPlusText\":\"point\"},{\"text\":\"police\",\"queryPlusText\":\"police\"},{\"text\":\"polite\",\"queryPlusText\":\"polite\"},{\"text\":\"pool\",\"queryPlusText\":\"pool\"},{\"text\":\"popular\",\"queryPlusText\":\"popular\"}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"x-ms-client-request-id" : "2f169b9c-1c57-4ea3-a542-67e9ac561a52",
"Content-Type" : "application/json; odata.metadata=none"
},
"Exception" : null
} ],
"variables" : [ ]
}
"Entries": [
{
"RequestUri": "https://REDACTED/indexes(\u0027azsearch-autocomplete-shared-instance\u0027)/docs/search.post.autocomplete?api-version=2021-04-30-Preview",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json; odata.metadata=none",
"api-key": "REDACTED",
"Content-Length": "36",
"Content-Type": "application/json",
"Date": "Thu, 09 Mar 2023 19:53:21 GMT",
"return-client-request-id": "true",
"User-Agent": "azsdk-java-azure-search-documents/11.6.0-beta.6 (17.0.5; Windows 11; 10.0)",
"x-ms-client-request-id": "17e22cb0-757d-4529-978f-0ee16971851a"
},
"RequestBody": {
"search": "po",
"suggesterName": "sg"
},
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"client-request-id": "17e22cb0-757d-4529-978f-0ee16971851a",
"Content-Length": "222",
"Content-Type": "application/json; odata.metadata=none",
"Date": "Thu, 09 Mar 2023 19:53:20 GMT",
"elapsed-time": "16",
"Expires": "-1",
"OData-Version": "4.0",
"Pragma": "no-cache",
"Preference-Applied": "odata.include-annotations=\u0022*\u0022",
"request-id": "17e22cb0-757d-4529-978f-0ee16971851a",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"x-ms-client-request-id": "17e22cb0-757d-4529-978f-0ee16971851a"
},
"ResponseBody": {
"value": [
{
"text": "point",
"queryPlusText": "point"
},
{
"text": "police",
"queryPlusText": "police"
},
{
"text": "polite",
"queryPlusText": "polite"
},
{
"text": "pool",
"queryPlusText": "pool"
},
{
"text": "popular",
"queryPlusText": "popular"
}
]
}
}
],
"Variables": {}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://REDACTED.search.windows.net/indexes('azsearch-autocomplete-shared-instance')/docs/search.post.autocomplete?api-version=2021-04-30-Preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-search-documents/11.6.0-beta.4 (17.0.5; Windows 11; 10.0)",
"x-ms-client-request-id" : "5fdcd761-e82a-44f9-a5df-083224b58f57",
"Content-Type" : "application/json"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "5fdcd761-e82a-44f9-a5df-083224b58f57",
"StatusCode" : "200",
"Date" : "Tue, 17 Jan 2023 20:21:14 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"client-request-id" : "5fdcd761-e82a-44f9-a5df-083224b58f57",
"elapsed-time" : "15",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "222",
"Body" : "{\"value\":[{\"text\":\"point\",\"queryPlusText\":\"point\"},{\"text\":\"police\",\"queryPlusText\":\"police\"},{\"text\":\"polite\",\"queryPlusText\":\"polite\"},{\"text\":\"pool\",\"queryPlusText\":\"pool\"},{\"text\":\"popular\",\"queryPlusText\":\"popular\"}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"x-ms-client-request-id" : "5fdcd761-e82a-44f9-a5df-083224b58f57",
"Content-Type" : "application/json; odata.metadata=none"
},
"Exception" : null
} ],
"variables" : [ ]
}
"Entries": [
{
"RequestUri": "https://REDACTED/indexes(\u0027azsearch-autocomplete-shared-instance\u0027)/docs/search.post.autocomplete?api-version=2021-04-30-Preview",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json; odata.metadata=none",
"api-key": "REDACTED",
"Content-Length": "36",
"Content-Type": "application/json",
"Date": "Thu, 09 Mar 2023 19:53:22 GMT",
"return-client-request-id": "true",
"User-Agent": "azsdk-java-azure-search-documents/11.6.0-beta.6 (17.0.5; Windows 11; 10.0)",
"x-ms-client-request-id": "801398e5-eb80-4718-b0d2-d6917f46434c"
},
"RequestBody": {
"search": "po",
"suggesterName": "sg"
},
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"client-request-id": "801398e5-eb80-4718-b0d2-d6917f46434c",
"Content-Length": "222",
"Content-Type": "application/json; odata.metadata=none",
"Date": "Thu, 09 Mar 2023 19:53:21 GMT",
"elapsed-time": "17",
"Expires": "-1",
"OData-Version": "4.0",
"Pragma": "no-cache",
"Preference-Applied": "odata.include-annotations=\u0022*\u0022",
"request-id": "801398e5-eb80-4718-b0d2-d6917f46434c",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"x-ms-client-request-id": "801398e5-eb80-4718-b0d2-d6917f46434c"
},
"ResponseBody": {
"value": [
{
"text": "point",
"queryPlusText": "point"
},
{
"text": "police",
"queryPlusText": "police"
},
{
"text": "polite",
"queryPlusText": "polite"
},
{
"text": "pool",
"queryPlusText": "pool"
},
{
"text": "popular",
"queryPlusText": "popular"
}
]
}
}
],
"Variables": {}
}
Loading