forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Indexers - createOrUpdate, List indexers and matching UTs (Azure#222)
* indexers create - wip * Adds APIs for checking synonym map existence (Azure#209) * Adds APIs for checking synonym map existence * Adds createOrUpdateSynonymMap client methods (Azure#210) * createOrUpdateSynonym map if not exists tests (Azure#216) createOrUpdateSynonymMapIfNotExistsFailsOnExistingResource and createOrUpdateSynonymMapIfNotExistsSucceedsOnNoResource tests * createOrUpdateSynonym map if exists tests (Azure#217) createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource and createOrUpdateSynonymMapIfExistsSucceedsOnExistingResource tests * assertReflectionEquals - index management objects (Azure#214) * removing index management equal comparison annd replacing with reflection equal method * Indexers - createOrUpdate, List indexers and matching UTs * style fix * fix merge issues * style fixes * changed list overload * changed list overload * changed list overload * fix style
- Loading branch information
Showing
11 changed files
with
973 additions
and
323 deletions.
There are no files selected for viewing
288 changes: 187 additions & 101 deletions
288
sdk/search/azure-search/src/main/java/com/azure/search/SearchServiceAsyncClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
200 changes: 128 additions & 72 deletions
200
sdk/search/azure-search/src/main/java/com/azure/search/SearchServiceClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementAsyncTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.search; | ||
|
||
import com.azure.core.exception.HttpResponseException; | ||
import com.azure.core.http.rest.PagedFlux; | ||
import com.azure.search.models.DataSource; | ||
import com.azure.search.models.Index; | ||
import com.azure.search.models.Indexer; | ||
import com.azure.search.models.IndexingParameters; | ||
import org.junit.Assert; | ||
import reactor.test.StepVerifier; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class IndexersManagementAsyncTests extends IndexersManagementTestBase { | ||
private SearchServiceAsyncClient client; | ||
|
||
@Override | ||
public void createIndexerReturnsCorrectDefinition() { | ||
client = getSearchServiceClientBuilder().buildAsyncClient(); | ||
Indexer expectedIndexer = createTestIndexer("indexer"); | ||
expectedIndexer.setIsDisabled(true); | ||
expectedIndexer.setParameters( | ||
new IndexingParameters() | ||
.setBatchSize(50) | ||
.setMaxFailedItems(10) | ||
.setMaxFailedItemsPerBatch(10)); | ||
|
||
Indexer actualIndexer = client.createOrUpdateIndexer(expectedIndexer).block(); | ||
|
||
IndexingParameters ip = new IndexingParameters(); | ||
Map<String, Object> config = new HashMap<>(); | ||
ip.setConfiguration(config); | ||
expectedIndexer.setParameters(ip); // Get returns empty dictionary. | ||
expectSameStartTime(expectedIndexer, actualIndexer); | ||
|
||
assertIndexersEqual(expectedIndexer, actualIndexer); | ||
} | ||
|
||
@Override | ||
public void canCreateAndListIndexers() { | ||
client = getSearchServiceClientBuilder().buildAsyncClient(); | ||
|
||
// Create the data source, note it a valid DS with actual | ||
// connection string | ||
DataSource datasource = createTestSqlDataSource(); | ||
client.createOrUpdateDataSource(datasource).block(); | ||
|
||
// Create an index | ||
Index index = createTestIndexForLiveDatasource(); | ||
client.createOrUpdateIndex(index).block(); | ||
|
||
|
||
// Create two indexers | ||
Indexer indexer1 = createTestIndexer("i1"); | ||
Indexer indexer2 = createTestIndexer("i2"); | ||
client.createOrUpdateIndexer(indexer1).block(); | ||
client.createOrUpdateIndexer(indexer2).block(); | ||
|
||
PagedFlux<Indexer> returnedIndexersLst = client.listIndexers(); | ||
StepVerifier | ||
.create(returnedIndexersLst.collectList()) | ||
.assertNext(indexers -> { | ||
Assert.assertEquals(2, indexers.size()); | ||
Assert.assertTrue(indexers.get(0).getName().equals(indexer1.getName())); | ||
Assert.assertTrue(indexers.get(1).getName().equals(indexer2.getName())); | ||
}) | ||
.verifyComplete(); | ||
} | ||
|
||
@Override | ||
public void createIndexerFailsWithUsefulMessageOnUserError() { | ||
client = getSearchServiceClientBuilder().buildAsyncClient(); | ||
Indexer indexer = createTestIndexer("indexer"); | ||
indexer.setDataSourceName("thisdatasourcedoesnotexist"); | ||
|
||
assertException( | ||
() -> client.createOrUpdateIndexer(indexer).block(), | ||
HttpResponseException.class, | ||
"This indexer refers to a data source 'thisdatasourcedoesnotexist' that doesn't exist"); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementSyncTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.search; | ||
|
||
import com.azure.core.exception.HttpResponseException; | ||
import com.azure.search.models.DataSource; | ||
import com.azure.search.models.Index; | ||
import com.azure.search.models.Indexer; | ||
import com.azure.search.models.IndexingParameters; | ||
import org.junit.Assert; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class IndexersManagementSyncTests extends IndexersManagementTestBase { | ||
private SearchServiceClient client; | ||
|
||
@Override | ||
public void createIndexerReturnsCorrectDefinition() { | ||
client = getSearchServiceClientBuilder().buildClient(); | ||
Indexer expectedIndexer = | ||
createTestIndexer("indexer") | ||
.setIsDisabled(true) | ||
.setParameters( | ||
new IndexingParameters() | ||
.setBatchSize(50) | ||
.setMaxFailedItems(10) | ||
.setMaxFailedItemsPerBatch(10)); | ||
|
||
Indexer actualIndexer = client.createOrUpdateIndexer(expectedIndexer); | ||
|
||
IndexingParameters ip = new IndexingParameters(); | ||
Map<String, Object> config = new HashMap<>(); | ||
ip.setConfiguration(config); | ||
expectedIndexer.setParameters(ip); // Get returns empty dictionary. | ||
expectSameStartTime(expectedIndexer, actualIndexer); | ||
|
||
assertIndexersEqual(expectedIndexer, actualIndexer); | ||
} | ||
|
||
@Override | ||
public void canCreateAndListIndexers() { | ||
client = getSearchServiceClientBuilder().buildClient(); | ||
|
||
// Create the data source, note it a valid DS with actual | ||
// connection string | ||
DataSource datasource = createTestSqlDataSource(); | ||
client.createOrUpdateDataSource(datasource); | ||
|
||
// Create an index | ||
Index index = createTestIndexForLiveDatasource(); | ||
client.createOrUpdateIndex(index); | ||
|
||
|
||
// Create two indexers | ||
Indexer indexer1 = createTestIndexer("i1"); | ||
Indexer indexer2 = createTestIndexer("i2"); | ||
client.createOrUpdateIndexer(indexer1); | ||
client.createOrUpdateIndexer(indexer2); | ||
|
||
List<Indexer> indexers = client.listIndexers().stream().collect(Collectors.toList()); | ||
Assert.assertEquals(2, indexers.size()); | ||
|
||
Assert.assertTrue( | ||
indexers.stream() | ||
.anyMatch(item -> indexer1.getName().equals(item.getName()))); | ||
Assert.assertTrue( | ||
indexers.stream() | ||
.anyMatch(item -> indexer2.getName().equals(item.getName()))); | ||
} | ||
|
||
@Override | ||
public void createIndexerFailsWithUsefulMessageOnUserError() { | ||
client = getSearchServiceClientBuilder().buildClient(); | ||
Indexer indexer = createTestIndexer("indexer"); | ||
indexer.setDataSourceName("thisdatasourcedoesnotexist"); | ||
|
||
assertException( | ||
() -> client.createOrUpdateIndexer(indexer), | ||
HttpResponseException.class, | ||
"This indexer refers to a data source 'thisdatasourcedoesnotexist' that doesn't exist"); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
sdk/search/azure-search/src/test/java/com/azure/search/IndexersManagementTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.search; | ||
|
||
import com.azure.search.models.DataType; | ||
import com.azure.search.models.Field; | ||
import com.azure.search.models.Index; | ||
import com.azure.search.models.Indexer; | ||
import com.azure.search.models.IndexingSchedule; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.Arrays; | ||
|
||
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals; | ||
import static org.unitils.reflectionassert.ReflectionComparatorMode.IGNORE_DEFAULTS; | ||
|
||
public abstract class IndexersManagementTestBase extends SearchServiceTestBase { | ||
|
||
@Test | ||
public abstract void createIndexerReturnsCorrectDefinition(); | ||
|
||
@Test | ||
public abstract void canCreateAndListIndexers(); | ||
|
||
@Test | ||
public abstract void createIndexerFailsWithUsefulMessageOnUserError(); | ||
|
||
protected void assertIndexersEqual(Indexer expected, Indexer actual) { | ||
expected.setETag("none"); | ||
actual.setETag("none"); | ||
|
||
// we ignore defaults as when properties are not set they are returned from the service with | ||
// default values | ||
assertReflectionEquals(expected, actual, IGNORE_DEFAULTS); | ||
} | ||
|
||
protected Indexer createTestIndexer(String indexerName) { | ||
return new Indexer() | ||
.setName(indexerName) | ||
.setDataSourceName("azs-java-test-sql") | ||
.setTargetIndexName("indexforindexers") | ||
.setSchedule(new IndexingSchedule().setInterval(Duration.ofDays(1))); | ||
} | ||
|
||
protected static void expectSameStartTime(Indexer expected, Indexer actual) { | ||
// There ought to be a start time in the response; We just can't know what it is because it would | ||
// make the test timing-dependent. | ||
expected.getSchedule().setStartTime(actual.getSchedule().getStartTime()); | ||
} | ||
|
||
/** | ||
* This index contains fields that are declared on the live datasource | ||
* we use to test the indexers | ||
* | ||
* @return the newly created Index object | ||
*/ | ||
protected Index createTestIndexForLiveDatasource() { | ||
return new Index() | ||
.setName("indexforindexers") | ||
.setFields(Arrays.asList( | ||
new Field() | ||
.setName("county_name") | ||
.setType(DataType.EDM_STRING) | ||
.setSearchable(Boolean.FALSE) | ||
.setFilterable(Boolean.TRUE), | ||
new Field() | ||
.setName("state") | ||
.setType(DataType.EDM_STRING) | ||
.setSearchable(Boolean.TRUE) | ||
.setFilterable(Boolean.TRUE), | ||
new Field() | ||
.setName("feature_id") | ||
.setType(DataType.EDM_STRING) | ||
.setKey(Boolean.TRUE) | ||
.setSearchable(Boolean.TRUE) | ||
.setFilterable(Boolean.FALSE))); | ||
} | ||
|
||
void assertException(Runnable exceptionThrower, Class<? extends Exception> expectedExceptionType, String expectedMessage) { | ||
try { | ||
exceptionThrower.run(); | ||
Assert.fail(); | ||
} catch (Throwable ex) { | ||
Assert.assertEquals(expectedExceptionType, ex.getClass()); | ||
Assert.assertTrue(ex.getMessage().contains(expectedMessage)); | ||
} | ||
} | ||
} |
Oops, something went wrong.