Skip to content

Commit

Permalink
Switch url repository rest tests to new style requests (#31944)
Browse files Browse the repository at this point in the history
In #29623 we added `Request` object flavored requests to the low level
REST client and in #30315 we deprecated the old `performRequest`s. This
changes all calls in the `module/repository-url` project to use the new
versions.
  • Loading branch information
nik9000 committed Jul 11, 2018
1 parent d3d7309 commit d37ac56
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NStringEntity;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils;
Expand All @@ -44,7 +45,6 @@
import java.util.List;
import java.util.Map;

import static java.util.Collections.emptyMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
Expand All @@ -70,8 +70,10 @@ public static Iterable<Object[]> parameters() throws Exception {
**/
@Before
public void registerRepositories() throws IOException {
Response clusterSettingsResponse = client().performRequest("GET", "/_cluster/settings?include_defaults=true" +
"&filter_path=defaults.path.repo,defaults.repositories.url.allowed_urls");
Request clusterSettingsRequest = new Request("GET", "/_cluster/settings");
clusterSettingsRequest.addParameter("include_defaults", "true");
clusterSettingsRequest.addParameter("filter_path", "defaults.path.repo,defaults.repositories.url.allowed_urls");
Response clusterSettingsResponse = client().performRequest(clusterSettingsRequest);
Map<String, Object> clusterSettings = entityAsMap(clusterSettingsResponse);

@SuppressWarnings("unchecked")
Expand All @@ -83,13 +85,17 @@ public void registerRepositories() throws IOException {
final URI pathRepoUri = PathUtils.get(pathRepo).toUri().normalize();

// Create a FS repository using the path.repo location
Response createFsRepositoryResponse = client().performRequest("PUT", "_snapshot/repository-fs", emptyMap(),
buildRepositorySettings(FsRepository.TYPE, Settings.builder().put("location", pathRepo).build()));
Request createFsRepositoryRequest = new Request("PUT", "/_snapshot/repository-fs");
createFsRepositoryRequest.setEntity(buildRepositorySettings(FsRepository.TYPE,
Settings.builder().put("location", pathRepo).build()));
Response createFsRepositoryResponse = client().performRequest(createFsRepositoryRequest);
assertThat(createFsRepositoryResponse.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));

// Create a URL repository using the file://{path.repo} URL
Response createFileRepositoryResponse = client().performRequest("PUT", "_snapshot/repository-file", emptyMap(),
buildRepositorySettings(URLRepository.TYPE, Settings.builder().put("url", pathRepoUri.toString()).build()));
Request createFileRepositoryRequest = new Request("PUT", "/_snapshot/repository-file");
createFileRepositoryRequest.setEntity(buildRepositorySettings(URLRepository.TYPE,
Settings.builder().put("url", pathRepoUri.toString()).build()));
Response createFileRepositoryResponse = client().performRequest(createFileRepositoryRequest);
assertThat(createFileRepositoryResponse.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));

// Create a URL repository using the http://{fixture} URL
Expand All @@ -99,8 +105,10 @@ public void registerRepositories() throws IOException {
try {
InetAddress inetAddress = InetAddress.getByName(new URL(allowedUrl).getHost());
if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress()) {
Response createUrlRepositoryResponse = client().performRequest("PUT", "_snapshot/repository-url", emptyMap(),
buildRepositorySettings(URLRepository.TYPE, Settings.builder().put("url", allowedUrl).build()));
Request createUrlRepositoryRequest = new Request("PUT", "/_snapshot/repository-url");
createUrlRepositoryRequest.setEntity(buildRepositorySettings(URLRepository.TYPE,
Settings.builder().put("url", allowedUrl).build()));
Response createUrlRepositoryResponse = client().performRequest(createUrlRepositoryRequest);
assertThat(createUrlRepositoryResponse.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
break;
}
Expand All @@ -126,4 +134,3 @@ private static HttpEntity buildRepositorySettings(final String type, final Setti
}
}
}

0 comments on commit d37ac56

Please sign in to comment.