Skip to content

Commit 9a0a65c

Browse files
committed
Apply feedback and add more doc
1 parent 46e0576 commit 9a0a65c

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

modules/repository-url/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.elasticsearch.gradle.test.AntFixture
2-
31
/*
42
* Licensed to Elasticsearch under one or more contributor
53
* license agreements. See the NOTICE file distributed with
@@ -18,6 +16,7 @@ import org.elasticsearch.gradle.test.AntFixture
1816
* specific language governing permissions and limitations
1917
* under the License.
2018
*/
19+
import org.elasticsearch.gradle.test.AntFixture
2120

2221
esplugin {
2322
description 'Module for URL repository'
@@ -33,7 +32,7 @@ forbiddenApisTest {
3332
// This directory is shared between two URL repositories and one FS repository in YAML integration tests
3433
File repositoryDir = new File(project.buildDir, "shared-repository")
3534

36-
/** A task to start the URLFixture that exposes the repositoryDir over HTTP **/
35+
/** A task to start the URLFixture which exposes the repositoryDir over HTTP **/
3736
task urlFixture(type: AntFixture) {
3837
doFirst {
3938
repositoryDir.mkdirs()
@@ -47,6 +46,6 @@ integTestCluster {
4746
dependsOn urlFixture
4847
// repositoryDir is used by a FS repository to create snapshots
4948
setting 'path.repo', "${repositoryDir.absolutePath}"
50-
// repositoryDir is used by a URL repository to restore snapshots
49+
// repositoryDir is used by two URL repositories to restore snapshots
5150
setting 'repositories.url.allowed_urls', "http://snapshot.test*,http://${ -> urlFixture.addressAndPort }"
5251
}

modules/repository-url/src/test/java/org/elasticsearch/repositories/url/RepositoryURLClientYamlTestSuiteIT.java

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public static Iterable<Object[]> parameters() throws Exception {
5858
return ESClientYamlSuiteTestCase.createParameters();
5959
}
6060

61+
/**
62+
* This method registers 3 snapshot/restore repositories:
63+
* - repository-fs: this FS repository is used to create snapshots.
64+
* - repository-url: this URL repository is used to restore snapshots created using the previous repository. It uses
65+
* the URLFixture to restore snapshots over HTTP.
66+
* - repository-file: similar as the previous repository but using a file:// prefix instead of http://.
67+
**/
6168
@Before
6269
public void registerRepositories() throws IOException {
6370
Response clusterSettingsResponse = client().performRequest("GET", "/_cluster/settings?include_defaults=true" +

modules/repository-url/src/test/java/org/elasticsearch/repositories/url/URLFixture.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.net.InetAddress;
3232
import java.net.InetSocketAddress;
3333
import java.net.SocketAddress;
34+
import java.nio.charset.StandardCharsets;
3435
import java.nio.file.Files;
3536
import java.nio.file.Path;
3637
import java.nio.file.Paths;
@@ -44,7 +45,7 @@
4445

4546
/**
4647
* This {@link URLFixture} exposes a filesystem directory over HTTP. It is used in repository-url
47-
* integration tests to expose a directory populated using a regular FS repository.
48+
* integration tests to expose a directory created by a regular FS repository.
4849
*/
4950
public class URLFixture {
5051

@@ -130,7 +131,8 @@ public void handle(HttpExchange exchange) throws IOException {
130131
response = new Response(RestStatus.FORBIDDEN, emptyMap(), "text/plain", new byte[0]);
131132
}
132133
} else {
133-
response = new Response(RestStatus.INTERNAL_SERVER_ERROR, emptyMap(), "text/plain", new byte[0]);
134+
response = new Response(RestStatus.INTERNAL_SERVER_ERROR, emptyMap(), "text/plain",
135+
"Unsupported HTTP method".getBytes(StandardCharsets.UTF_8));
134136
}
135137
exchange.sendResponseHeaders(response.status.getStatus(), response.body.length);
136138
if (response.body.length > 0) {

modules/repository-url/src/test/resources/rest-api-spec/test/repository_url/10_basic.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Integration tests for repository-url
2+
#
3+
# This test is based on 3 repositories, all registered before this
4+
# test is executed. The repository-fs is used to create snapshots
5+
# in a shared directory on the filesystem. Then the test uses a URL
6+
# repository with a "http://" prefix to test the restore of the
7+
# snapshots. In order to do that it uses a URLFixture that exposes
8+
# the content of the shared directory over HTTP. A second URL
9+
# repository is used to test the snapshot restore but this time
10+
# with a "file://" prefix.
211
setup:
312

413
# Ensure that the FS repository is registered, so we can create
@@ -103,7 +112,7 @@ teardown:
103112
- do:
104113
nodes.info: {}
105114

106-
- match: { nodes.$master.modules.0.name: repository-url }
115+
- match: { nodes.$master.modules.0.name: repository-url }
107116

108117
---
109118
"Restore with repository-url using http://":

modules/repository-url/src/test/resources/rest-api-spec/test/repository_url/20_repository.yml

+15
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@
1414
repository: test_repo1
1515

1616
- is_true : test_repo1
17+
18+
---
19+
"Repository cannot be be registered":
20+
21+
- do:
22+
catch: /doesn't match any of the locations specified by path.repo or repositories.url.allowed_urls/
23+
snapshot.create_repository:
24+
repository: test_repo2
25+
body:
26+
type: url
27+
settings:
28+
url: "http://snapshot.unknown"
29+
30+
31+

0 commit comments

Comments
 (0)