Skip to content

Commit

Permalink
Address reviewer comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaiera committed Jun 25, 2018
1 parent 7725747 commit c2a591d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ static Request snapshotsStatus(SnapshotsStatusRequest snapshotsStatusRequest) {

Params parameters = new Params(request);
parameters.withMasterTimeout(snapshotsStatusRequest.masterNodeTimeout());
parameters.putParam("ignore_unavailable", Boolean.toString(snapshotsStatusRequest.ignoreUnavailable()));
parameters.withIgnoreUnavailable(snapshotsStatusRequest.ignoreUnavailable());
return request;
}

Expand Down Expand Up @@ -1155,7 +1155,7 @@ Params withWaitForActiveShards(ActiveShardCount activeShardCount, ActiveShardCou
}

Params withIndicesOptions(IndicesOptions indicesOptions) {
putParam("ignore_unavailable", Boolean.toString(indicesOptions.ignoreUnavailable()));
withIgnoreUnavailable(indicesOptions.ignoreUnavailable());
putParam("allow_no_indices", Boolean.toString(indicesOptions.allowNoIndices()));
String expandWildcards;
if (indicesOptions.expandWildcardsOpen() == false && indicesOptions.expandWildcardsClosed() == false) {
Expand All @@ -1174,6 +1174,13 @@ Params withIndicesOptions(IndicesOptions indicesOptions) {
return this;
}

Params withIgnoreUnavailable(boolean ignoreUnavailable) {
if (ignoreUnavailable) {
putParam("ignore_unavailable", Boolean.toString(ignoreUnavailable));
}
return this;
}

Params withHuman(boolean human) {
if (human) {
putParam("human", Boolean.toString(human));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ private PutRepositoryResponse createTestRepository(String repository, String typ
highLevelClient().snapshot()::createRepositoryAsync);
}

private Response createTestSnapshot(String repository, String snapshot) throws IOException {
Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repository, snapshot));
createSnapshot.addParameter("wait_for_completion", "true");
return highLevelClient().getLowLevelClient().performRequest(createSnapshot);
}

private Response createTestSnapshot(String repository, String snapshot, String index) throws IOException {
Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repository, snapshot));
createSnapshot.addParameter("wait_for_completion", "true");
Expand Down Expand Up @@ -132,33 +126,40 @@ public void testVerifyRepository() throws IOException {
}

public void testSnapshotsStatus() throws IOException {
PutRepositoryResponse putRepositoryResponse = createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}");
String testRepository = "test";
String testSnapshot = "snapshot";
String testIndex = "test_index";

PutRepositoryResponse putRepositoryResponse = createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}");
assertTrue(putRepositoryResponse.isAcknowledged());

createIndex("test_index", Settings.EMPTY);
createIndex(testIndex, Settings.EMPTY);

Response snapshotResponse = createTestSnapshot("test", "snapshot", "test_index");
Response snapshotResponse = createTestSnapshot(testRepository, testSnapshot, testIndex);
assertEquals(2, snapshotResponse.getHttpResponse().getStatusLine().getStatusCode() / 100);

SnapshotsStatusRequest request = new SnapshotsStatusRequest();
request.repository("test");
request.snapshots(new String[]{"snapshot"});
request.repository(testRepository);
request.snapshots(new String[]{testSnapshot});
SnapshotsStatusResponse response = execute(request, highLevelClient().snapshot()::snapshotsStatus,
highLevelClient().snapshot()::snapshotsStatusAsync);
assertThat(response.getSnapshots().size(), equalTo(1));
assertThat(response.getSnapshots().get(0).getSnapshot().getRepository(), equalTo("test"));
assertThat(response.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo("snapshot"));
assertThat(response.getSnapshots().get(0).getIndices().containsKey("test_index"), is(true));
assertThat(response.getSnapshots().get(0).getSnapshot().getRepository(), equalTo(testRepository));
assertThat(response.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo(testSnapshot));
assertThat(response.getSnapshots().get(0).getIndices().containsKey(testIndex), is(true));
}

public void testDeleteSnapshot() throws IOException {
String repository = "test_repository";
String snapshot = "test_snapshot";
String index = "test_index";

PutRepositoryResponse putRepositoryResponse = createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}");
assertTrue(putRepositoryResponse.isAcknowledged());

Response putSnapshotResponse = createTestSnapshot(repository, snapshot);
createIndex(index, Settings.EMPTY);

Response putSnapshotResponse = createTestSnapshot(repository, snapshot, index);
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
assertEquals(200, putSnapshotResponse.getStatusLine().getStatusCode());

Expand Down

0 comments on commit c2a591d

Please sign in to comment.