diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementAsyncTests.java b/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementAsyncTests.java index 020926ff2c94..091fe1880709 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementAsyncTests.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementAsyncTests.java @@ -98,36 +98,50 @@ public void createIndexerFailsWithUsefulMessageOnUserError() { @Override public void canUpdateIndexer() { - Indexer updatedExpected = changeIndexerBasic(); + Indexer updatedExpected = createIndexerWithDifferentDescription(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); } @Override public void canUpdateIndexerFieldMapping() { - Indexer updatedExpected = changeIndexerFieldMapping(); + Indexer updatedExpected = createIndexerWithDifferentFieldMapping(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); } @Override public void canUpdateIndexerDisabled() { - Indexer updatedExpected = changeIndexerDisabled(); + Indexer updatedExpected = createDisabledIndexer(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); } @Override public void canUpdateIndexerSchedule() { - Indexer updatedExpected = changeIndexerSchedule(); + Indexer updatedExpected = createIndexerWithDifferentSchedule(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); + } + + @Override + public void canCreateIndexerWithSchedule() { + Indexer indexer = createIndexerWithDifferentSchedule(); + + createAndValidateIndexer(indexer); } @Override public void canUpdateIndexerBatchSizeMaxFailedItems() { - Indexer updatedExpected = changeIndexerBatchSizeMaxFailedItems(); + Indexer updatedExpected = createIndexerWithDifferentIndexingParameters(); + + createUpdateAndValidateIndexer(updatedExpected); + } + + @Override + public void canCreateIndexerWithBatchSizeMaxFailedItems() { + Indexer indexer = createIndexerWithDifferentIndexingParameters(); - createUpdateValidateIndexer(updatedExpected); + createAndValidateIndexer(indexer); } } diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementSyncTests.java b/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementSyncTests.java index cbc2f5d73a8f..bbdca57944c8 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementSyncTests.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementSyncTests.java @@ -101,36 +101,50 @@ public void createIndexerFailsWithUsefulMessageOnUserError() { @Override public void canUpdateIndexer() { - Indexer updatedExpected = changeIndexerBasic(); + Indexer updatedExpected = createIndexerWithDifferentDescription(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); } @Override public void canUpdateIndexerFieldMapping() { - Indexer updatedExpected = changeIndexerFieldMapping(); + Indexer updatedExpected = createIndexerWithDifferentFieldMapping(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); } @Override public void canUpdateIndexerDisabled() { - Indexer updatedExpected = changeIndexerDisabled(); + Indexer updatedExpected = createDisabledIndexer(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); } @Override public void canUpdateIndexerSchedule() { - Indexer updatedExpected = changeIndexerSchedule(); + Indexer updatedExpected = createIndexerWithDifferentSchedule(); - createUpdateValidateIndexer(updatedExpected); + createUpdateAndValidateIndexer(updatedExpected); + } + + @Override + public void canCreateIndexerWithSchedule() { + Indexer indexer = createIndexerWithDifferentSchedule(); + + createAndValidateIndexer(indexer); } @Override public void canUpdateIndexerBatchSizeMaxFailedItems() { - Indexer updatedExpected = changeIndexerBatchSizeMaxFailedItems(); + Indexer updatedExpected = createIndexerWithDifferentIndexingParameters(); + + createUpdateAndValidateIndexer(updatedExpected); + } + + @Override + public void canCreateIndexerWithBatchSizeMaxFailedItems() { + Indexer indexer = createIndexerWithDifferentIndexingParameters(); - createUpdateValidateIndexer(updatedExpected); + createAndValidateIndexer(indexer); } } diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementTestBase.java b/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementTestBase.java index 4df4f3c97eff..1c4bfd907871 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementTestBase.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementTestBase.java @@ -15,7 +15,7 @@ import java.time.Duration; import java.util.Arrays; -import java.util.LinkedList; +import java.util.Collections; import java.util.List; import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals; @@ -44,9 +44,15 @@ public abstract class IndexersManagementTestBase extends SearchServiceTestBase { @Test public abstract void canUpdateIndexerSchedule(); + @Test + public abstract void canCreateIndexerWithSchedule(); + @Test public abstract void canUpdateIndexerBatchSizeMaxFailedItems(); + @Test + public abstract void canCreateIndexerWithBatchSizeMaxFailedItems(); + protected void assertIndexersEqual(Indexer expected, Indexer actual) { expected.setETag("none"); actual.setETag("none"); @@ -112,9 +118,8 @@ void assertException(Runnable exceptionThrower, Class expec * Creates the index and indexer in the search service and then update the indexer * @param updatedIndexer the indexer to be updated */ - protected void createUpdateValidateIndexer(Indexer updatedIndexer) { - // Create the data source, note it's a valid DS with actual - // connection string + void createUpdateAndValidateIndexer(Indexer updatedIndexer) { + // Create the data source, note it's a valid DS with actual connection string DataSource datasource = createTestSqlDataSource(); createDatasource(datasource); @@ -138,94 +143,105 @@ protected void createUpdateValidateIndexer(Indexer updatedIndexer) { assertIndexersEqual(updatedIndexer, updatedResponse); } + void createAndValidateIndexer(Indexer indexer) { + // Create the data source, note it's a valid DS with actual connection string + DataSource datasource = createTestSqlDataSource(); + createDatasource(datasource); + + // Create an index + Index index = createTestIndexForLiveDatasource(); + createIndex(index); + + // create this indexer in the service + Indexer indexerResponse = createIndexer(indexer); + + // verify the returned indexer is as expected + assertIndexersEqual(indexer, indexerResponse); + } + /** - * Change a basic property of an indexer and return it - * @return the updated indexer + * Create a new indexer and change its description property + * @return the created indexer */ - protected Indexer changeIndexerBasic() { - // create another indexer object - Indexer updatedExpected = - createTestIndexer("indexer"); + Indexer createIndexerWithDifferentDescription() { + // create a new indexer object + Indexer indexer = createTestIndexer("indexer"); // modify it - updatedExpected.setDescription("somethingdifferent"); + indexer.setDescription("somethingdifferent"); - return updatedExpected; + return indexer; } /** - * Change the field mappings property of an indexer and return it - * @return the updated indexer + * Create a new indexer and change its field mappings property + * @return the created indexer */ - protected Indexer changeIndexerFieldMapping() { - // Check field mappings can be changed - List lst = new LinkedList<>(); - FieldMapping fm = new FieldMapping(); - fm.setSourceFieldName("state_alpha"); - fm.setTargetFieldName("state"); - lst.add(fm); - + Indexer createIndexerWithDifferentFieldMapping() { + // create a new indexer object + Indexer indexer = createTestIndexer("indexer"); - // create another indexer object - Indexer updatedExpected = - createTestIndexer("indexer"); + // Create field mappings + List fieldMappings = Collections.singletonList(new FieldMapping() + .setSourceFieldName("state_alpha") + .setTargetFieldName("state")); - // modify it - updatedExpected.setFieldMappings(lst); + // modify the indexer + indexer.setFieldMappings(fieldMappings); - return updatedExpected; + return indexer; } /** - * Change the Disabled property of an indexer and return it - * @return the updated indexer + * Create a new indexer and set the Disabled property to true + * @return the created indexer */ - protected Indexer changeIndexerDisabled() { - // create another indexer object - Indexer updatedExpected = - createTestIndexer("indexer"); + Indexer createDisabledIndexer() { + // create a new indexer object + Indexer indexer = createTestIndexer("indexer"); // modify it - updatedExpected.setIsDisabled(false); + indexer.setIsDisabled(false); - return updatedExpected; + return indexer; } /** - * Change the schedule property of an indexer and return it - * @return the updated indexer + * Create a new indexer and change its schedule property + * @return the created indexer */ - protected Indexer changeIndexerSchedule() { - // create another indexer object - Indexer updatedExpected = - createTestIndexer("indexer"); + Indexer createIndexerWithDifferentSchedule() { + // create a new indexer object + Indexer indexer = createTestIndexer("indexer"); - IndexingSchedule is = new IndexingSchedule(); - is.setInterval(Duration.ofMinutes(10)); + IndexingSchedule is = new IndexingSchedule() + .setInterval(Duration.ofMinutes(10)); - // modify it - updatedExpected.setSchedule(is); + // modify the indexer + indexer.setSchedule(is); - return updatedExpected; + return indexer; } - protected Indexer changeIndexerBatchSizeMaxFailedItems() { - // create another indexer object - Indexer updatedExpected = - createTestIndexer("indexer"); + /** + * Create a new indexer and change its indexing parameters + * @return the created indexer + */ + Indexer createIndexerWithDifferentIndexingParameters() { + // create a new indexer object + Indexer indexer = createTestIndexer("indexer"); - IndexingParameters ip = new IndexingParameters(); - ip.setMaxFailedItems(121); - ip.setMaxFailedItemsPerBatch(11); + IndexingParameters ip = new IndexingParameters() + .setMaxFailedItems(121) + .setMaxFailedItemsPerBatch(11) + .setBatchSize(20); - ip.setBatchSize(20); - // modify it - updatedExpected.setParameters(ip); + // modify the indexer + indexer.setParameters(ip); - return updatedExpected; + return indexer; } - protected abstract Index createIndex(Index index); protected abstract DataSource createDatasource(DataSource datasource); diff --git a/sdk/search/azure-search/src/test/resources/session-records/canCreateIndexerWithBatchSizeMaxFailedItems.json b/sdk/search/azure-search/src/test/resources/session-records/canCreateIndexerWithBatchSizeMaxFailedItems.json new file mode 100644 index 000000000000..0a4435b840f6 --- /dev/null +++ b/sdk/search/azure-search/src/test/resources/session-records/canCreateIndexerWithBatchSizeMaxFailedItems.json @@ -0,0 +1,79 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://azs-sdk7ae81392dc35.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "2ddde1b4-2f56-49b1-af23-e89f49ad10d4", + "StatusCode" : "201", + "Date" : "Tue, 12 Nov 2019 14:46:06 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "ETag" : "W/\"0x8D7677F0D1C61E8\"", + "elapsed-time" : "97", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "383", + "Body" : "{\"@odata.context\":\"https://azs-sdk7ae81392dc35.search.windows.net/$metadata#datasources/$entity\",\"@odata.etag\":\"\\\"0x8D7677F0D1C61E8\\\"\",\"name\":\"azs-java-test-sql\",\"description\":\"Some data source\",\"type\":\"azuresql\",\"subtype\":null,\"credentials\":{\"connectionString\":null},\"container\":{\"name\":\"GeoNamesRI\",\"query\":null},\"dataChangeDetectionPolicy\":null,\"dataDeletionDetectionPolicy\":null}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal", + "Location" : "https://azs-sdk7ae81392dc35.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://azs-sdk7ae81392dc35.search.windows.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "64208c3a-5c54-4418-aba2-9ccf82a392a4", + "StatusCode" : "201", + "Date" : "Tue, 12 Nov 2019 14:46:07 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "ETag" : "W/\"0x8D7677F0D7EB7BC\"", + "elapsed-time" : "447", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "970", + "Body" : "{\"@odata.context\":\"https://azs-sdk7ae81392dc35.search.windows.net/$metadata#indexes/$entity\",\"@odata.etag\":\"\\\"0x8D7677F0D7EB7BC\\\"\",\"name\":\"indexforindexers\",\"defaultScoringProfile\":null,\"fields\":[{\"name\":\"county_name\",\"type\":\"Edm.String\",\"searchable\":false,\"filterable\":true,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":false,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]},{\"name\":\"state\",\"type\":\"Edm.String\",\"searchable\":true,\"filterable\":true,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":false,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]},{\"name\":\"feature_id\",\"type\":\"Edm.String\",\"searchable\":true,\"filterable\":false,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":true,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]}],\"scoringProfiles\":[],\"corsOptions\":null,\"suggesters\":[],\"analyzers\":[],\"tokenizers\":[],\"tokenFilters\":[],\"charFilters\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal", + "Location" : "https://azs-sdk7ae81392dc35.search.windows.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://azs-sdk7ae81392dc35.search.windows.net/indexers('indexer')?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "65bcfd1e-ef80-47fe-88ef-668c089e25ce", + "StatusCode" : "201", + "Date" : "Tue, 12 Nov 2019 14:46:08 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "ETag" : "W/\"0x8D7677F0E1482D3\"", + "elapsed-time" : "849", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "509", + "Body" : "{\"@odata.context\":\"https://azs-sdk7ae81392dc35.search.windows.net/$metadata#indexers/$entity\",\"@odata.etag\":\"\\\"0x8D7677F0E1482D3\\\"\",\"name\":\"indexer\",\"description\":null,\"dataSourceName\":\"azs-java-test-sql\",\"skillsetName\":null,\"targetIndexName\":\"indexforindexers\",\"disabled\":null,\"schedule\":{\"interval\":\"P1D\",\"startTime\":\"0001-01-01T00:00:00Z\"},\"parameters\":{\"batchSize\":20,\"maxFailedItems\":121,\"maxFailedItemsPerBatch\":11,\"base64EncodeKeys\":null,\"configuration\":{}},\"fieldMappings\":[],\"outputFieldMappings\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal", + "Location" : "https://azs-sdk7ae81392dc35.search.windows.net/indexers('indexer')?api-version=2019-05-06" + }, + "Exception" : null + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search/src/test/resources/session-records/canCreateIndexerWithSchedule.json b/sdk/search/azure-search/src/test/resources/session-records/canCreateIndexerWithSchedule.json new file mode 100644 index 000000000000..8fae3842d95c --- /dev/null +++ b/sdk/search/azure-search/src/test/resources/session-records/canCreateIndexerWithSchedule.json @@ -0,0 +1,79 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://azs-sdkd2414253ac7f.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "b244e2e8-f239-4dde-a209-df7293325347", + "StatusCode" : "201", + "Date" : "Tue, 12 Nov 2019 15:08:29 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "ETag" : "W/\"0x8D767822DB8D7ED\"", + "elapsed-time" : "50", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "383", + "Body" : "{\"@odata.context\":\"https://azs-sdkd2414253ac7f.search.windows.net/$metadata#datasources/$entity\",\"@odata.etag\":\"\\\"0x8D767822DB8D7ED\\\"\",\"name\":\"azs-java-test-sql\",\"description\":\"Some data source\",\"type\":\"azuresql\",\"subtype\":null,\"credentials\":{\"connectionString\":null},\"container\":{\"name\":\"GeoNamesRI\",\"query\":null},\"dataChangeDetectionPolicy\":null,\"dataDeletionDetectionPolicy\":null}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal", + "Location" : "https://azs-sdkd2414253ac7f.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://azs-sdkd2414253ac7f.search.windows.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "f9479e44-3a04-4557-a73b-cf5b9b87e046", + "StatusCode" : "201", + "Date" : "Tue, 12 Nov 2019 15:08:30 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "ETag" : "W/\"0x8D767822E0ED539\"", + "elapsed-time" : "405", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "970", + "Body" : "{\"@odata.context\":\"https://azs-sdkd2414253ac7f.search.windows.net/$metadata#indexes/$entity\",\"@odata.etag\":\"\\\"0x8D767822E0ED539\\\"\",\"name\":\"indexforindexers\",\"defaultScoringProfile\":null,\"fields\":[{\"name\":\"county_name\",\"type\":\"Edm.String\",\"searchable\":false,\"filterable\":true,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":false,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]},{\"name\":\"state\",\"type\":\"Edm.String\",\"searchable\":true,\"filterable\":true,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":false,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]},{\"name\":\"feature_id\",\"type\":\"Edm.String\",\"searchable\":true,\"filterable\":false,\"retrievable\":true,\"sortable\":true,\"facetable\":true,\"key\":true,\"indexAnalyzer\":null,\"searchAnalyzer\":null,\"analyzer\":null,\"synonymMaps\":[]}],\"scoringProfiles\":[],\"corsOptions\":null,\"suggesters\":[],\"analyzers\":[],\"tokenizers\":[],\"tokenFilters\":[],\"charFilters\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal", + "Location" : "https://azs-sdkd2414253ac7f.search.windows.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://azs-sdkd2414253ac7f.search.windows.net/indexers('indexer')?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "828d310b-8723-4db0-830b-efa88fb93888", + "StatusCode" : "201", + "Date" : "Tue, 12 Nov 2019 15:08:30 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "ETag" : "W/\"0x8D767822E61EB9B\"", + "elapsed-time" : "401", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "407", + "Body" : "{\"@odata.context\":\"https://azs-sdkd2414253ac7f.search.windows.net/$metadata#indexers/$entity\",\"@odata.etag\":\"\\\"0x8D767822E61EB9B\\\"\",\"name\":\"indexer\",\"description\":null,\"dataSourceName\":\"azs-java-test-sql\",\"skillsetName\":null,\"targetIndexName\":\"indexforindexers\",\"disabled\":null,\"schedule\":{\"interval\":\"PT10M\",\"startTime\":\"0001-01-01T00:00:00Z\"},\"parameters\":null,\"fieldMappings\":[],\"outputFieldMappings\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal", + "Location" : "https://azs-sdkd2414253ac7f.search.windows.net/indexers('indexer')?api-version=2019-05-06" + }, + "Exception" : null + } ], + "variables" : [ ] +} \ No newline at end of file