Skip to content

Commit

Permalink
Implement getIndexer() and tests (Azure#280)
Browse files Browse the repository at this point in the history
* implement getIndexer()
* Adding tests for getIndexer()
  • Loading branch information
rabee333 authored Nov 18, 2019
1 parent 89856e9 commit 59c2017
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ Mono<Response<Indexer>> createOrUpdateIndexerWithResponse(Indexer indexer,
* @return the indexer.
*/
public Mono<Indexer> getIndexer(String indexerName) {
throw logger.logExceptionAsError(
new NotImplementedException("not implemented."));
return this.getIndexerWithResponse(indexerName, null)
.map(Response::getValue);
}

/**
Expand All @@ -463,8 +463,8 @@ public Mono<Indexer> getIndexer(String indexerName) {
* @return the indexer.
*/
public Mono<Indexer> getIndexer(String indexerName, RequestOptions requestOptions) {
throw logger.logExceptionAsError(
new NotImplementedException("not implemented."));
return this.getIndexerWithResponse(indexerName, requestOptions)
.map(Response::getValue);
}

/**
Expand All @@ -476,13 +476,16 @@ public Mono<Indexer> getIndexer(String indexerName, RequestOptions requestOption
* @return a response containing the indexer.
*/
public Mono<Response<Indexer>> getIndexerWithResponse(String indexerName, RequestOptions requestOptions) {
throw logger.logExceptionAsError(
new NotImplementedException("not implemented."));
return withContext(
context -> this.getIndexerWithResponse(indexerName, requestOptions, context)
);
}

Mono<Response<Indexer>> getIndexerWithResponse(String indexerName, RequestOptions requestOptions, Context context) {
throw logger.logExceptionAsError(
new NotImplementedException("not implemented."));
return restClient
.indexers()
.getWithRestResponseAsync(indexerName, requestOptions, context)
.map(Function.identity());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.azure.search.models.RequestOptions;
import com.azure.search.models.Skillset;
import com.azure.search.models.SynonymMap;

import com.azure.search.models.TokenInfo;
import org.apache.commons.lang3.NotImplementedException;

Expand Down Expand Up @@ -378,7 +377,7 @@ public PagedResponse<Indexer> listIndexersWithResponse(String select,
* @return the indexer.
*/
public Indexer getIndexer(String indexerName) {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
return asyncClient.getIndexer(indexerName).block();
}

/**
Expand All @@ -390,7 +389,7 @@ public Indexer getIndexer(String indexerName) {
* @return the indexer.
*/
public Indexer getIndexer(String indexerName, RequestOptions requestOptions) {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
return asyncClient.getIndexer(indexerName, requestOptions).block();
}

/**
Expand All @@ -402,10 +401,9 @@ public Indexer getIndexer(String indexerName, RequestOptions requestOptions) {
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing the indexer.
*/
public Response<Indexer> getIndexerWithResponse(String indexerName,
RequestOptions requestOptions,
Context context) {
throw logger.logExceptionAsError(new NotImplementedException("not implemented."));
public Response<Indexer> getIndexerWithResponse(String indexerName, RequestOptions requestOptions,
Context context) {
return asyncClient.getIndexerWithResponse(indexerName, requestOptions, context).block();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ protected Indexer createIndexer(Indexer indexer) {
return client.createOrUpdateIndexer(indexer).block();
}

@Override
protected Indexer getIndexer(String indexerName) {
return client.getIndexer(indexerName).block();
}

@Override
protected Response<Void> deleteIndexer(Indexer indexer) {
return client.deleteIndexerWithResponse(indexer.getName(), null, null).block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected Indexer createIndexer(Indexer indexer) {
return client.createOrUpdateIndexer(indexer);
}

@Override
protected Indexer getIndexer(String indexerName) {
return client.getIndexer(indexerName);
}

@Override
protected Response<Void> deleteIndexer(Indexer indexer) {
return client.deleteIndexerWithResponse(indexer.getName(), null, null, Context.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
package com.azure.search;

import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.rest.Response;
import com.azure.search.models.DataSource;
import com.azure.search.models.DataType;
Expand Down Expand Up @@ -184,6 +185,30 @@ public void deleteIndexerIsIdempotent() {
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, result.getStatusCode());
}

@Test
public void canCreateAndGetIndexer() {
String indexerName = "indexer";

Index index = createTestIndexForLiveDatasource();
createIndex(index);

Indexer indexer = createTestDataSourceAndIndexer(indexerName);

createIndexer(indexer);

Indexer indexerResult = getIndexer(indexerName);

assertIndexersEqual(indexer, indexerResult);
}

@Test
public void getIndexerThrowsOnNotFound() {
assertException(
() -> getIndexer("thisindexerdoesnotexist"),
HttpResponseException.class,
"Indexer 'thisindexerdoesnotexist' was not found");
}

protected void assertIndexersEqual(Indexer expected, Indexer actual) {
expected.setETag("none");
actual.setETag("none");
Expand Down Expand Up @@ -251,16 +276,6 @@ protected Index createTestIndexForLiveDatasource() {
.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));
}
}

/**
* Creates the index and indexer in the search service and then update the indexer
* @param updatedIndexer the indexer to be updated
Expand Down Expand Up @@ -416,5 +431,7 @@ protected Indexer createIndexerWithStorageConfig() {

protected abstract Indexer createIndexer(Indexer indexer);

protected abstract Indexer getIndexer(String indexerName);

protected abstract Response<Void> deleteIndexer(Indexer indexer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://azs-sdkbef08910dea5.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" : "6cb922f4-c6c1-417d-877f-f55655520f53",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 16:27:18 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B7B03DC4B29\"",
"elapsed-time" : "119",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "383",
"Body" : "{\"@odata.context\":\"https://azs-sdkbef08910dea5.search.windows.net/$metadata#datasources/$entity\",\"@odata.etag\":\"\\\"0x8D76B7B03DC4B29\\\"\",\"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-sdkbef08910dea5.search.windows.net/datasources('azs-java-test-sql')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdkbef08910dea5.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" : "aaa1d436-eb58-489c-8eae-e837d6c65beb",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 16:27:22 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B7B05FD8C56\"",
"elapsed-time" : "702",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "970",
"Body" : "{\"@odata.context\":\"https://azs-sdkbef08910dea5.search.windows.net/$metadata#indexes/$entity\",\"@odata.etag\":\"\\\"0x8D76B7B05FD8C56\\\"\",\"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-sdkbef08910dea5.search.windows.net/indexes('indexforindexers')?allowIndexDowntime=false&api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://azs-sdkbef08910dea5.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" : "f0686678-da58-4d7b-a775-54ec0fee5f31",
"StatusCode" : "201",
"Date" : "Sun, 17 Nov 2019 16:27:24 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B7B07057841\"",
"elapsed-time" : "1300",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "405",
"Body" : "{\"@odata.context\":\"https://azs-sdkbef08910dea5.search.windows.net/$metadata#indexers/$entity\",\"@odata.etag\":\"\\\"0x8D76B7B07057841\\\"\",\"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\":null,\"fieldMappings\":[],\"outputFieldMappings\":[]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal",
"Location" : "https://azs-sdkbef08910dea5.search.windows.net/indexers('indexer')?api-version=2019-05-06"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://azs-sdkbef08910dea5.search.windows.net/indexers('indexer')?api-version=2019-05-06",
"Headers" : { },
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "a1a0c997-1115-4a1a-9356-1ad8ac12cf3f",
"StatusCode" : "200",
"Date" : "Sun, 17 Nov 2019 16:27:24 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"ETag" : "W/\"0x8D76B7B07057841\"",
"elapsed-time" : "13",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "405",
"Body" : "{\"@odata.context\":\"https://azs-sdkbef08910dea5.search.windows.net/$metadata#indexers/$entity\",\"@odata.etag\":\"\\\"0x8D76B7B07057841\\\"\",\"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\":null,\"fieldMappings\":[],\"outputFieldMappings\":[]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
} ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"networkCallRecords" : [ {
"Method" : "GET",
"Uri" : "https://azs-sdk47c65241770d.search.windows.net/indexers('thisindexerdoesnotexist')?api-version=2019-05-06",
"Headers" : { },
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "30436612-1964-4cc4-944f-87475d0f491b",
"StatusCode" : "404",
"Date" : "Sun, 17 Nov 2019 15:51:43 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "38",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "115",
"Body" : "{\"error\":{\"code\":\"\",\"message\":\"Indexer 'thisindexerdoesnotexist' was not found in service 'azs-sdk47c65241770d'.\"}}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Language" : "en",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
} ],
"variables" : [ ]
}

0 comments on commit 59c2017

Please sign in to comment.