Skip to content

Commit

Permalink
Migrate Cognitive Search to Test Proxy (#33952)
Browse files Browse the repository at this point in the history
Migrate Cognitive Search to Test Proxy
  • Loading branch information
alzimmermsft authored Apr 11, 2023
1 parent 54baab9 commit 6953909
Show file tree
Hide file tree
Showing 547 changed files with 332,141 additions and 55,970 deletions.
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,15 +72,13 @@ 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)));
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": {}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
{
"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" : "b395bf35-3765-49ad-bd85-3bed59ebde14",
"Content-Type" : "application/json"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "b395bf35-3765-49ad-bd85-3bed59ebde14",
"StatusCode" : "200",
"Date" : "Tue, 17 Jan 2023 20:21:12 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"client-request-id" : "b395bf35-3765-49ad-bd85-3bed59ebde14",
"elapsed-time" : "15",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "12",
"Body" : "{\"value\":[]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"x-ms-client-request-id" : "b395bf35-3765-49ad-bd85-3bed59ebde14",
"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": "94",
"Content-Type": "application/json",
"Date": "Thu, 09 Mar 2023 19:53:20 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": "54c34394-f175-4949-8cf1-a1a5876b298c"
},
"RequestBody": {
"search": "luxu",
"suggesterName": "sg",
"autocompleteMode": "oneTerm",
"searchFields": "HotelName"
},
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"client-request-id": "54c34394-f175-4949-8cf1-a1a5876b298c",
"Content-Length": "12",
"Content-Type": "application/json; odata.metadata=none",
"Date": "Thu, 09 Mar 2023 19:53:19 GMT",
"elapsed-time": "15",
"Expires": "-1",
"OData-Version": "4.0",
"Pragma": "no-cache",
"Preference-Applied": "odata.include-annotations=\u0022*\u0022",
"request-id": "54c34394-f175-4949-8cf1-a1a5876b298c",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"x-ms-client-request-id": "54c34394-f175-4949-8cf1-a1a5876b298c"
},
"ResponseBody": {
"value": []
}
}
],
"Variables": {}
}
Loading

0 comments on commit 6953909

Please sign in to comment.