|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | +package org.elasticsearch.http.snapshots; |
| 9 | + |
| 10 | +import org.apache.http.client.methods.HttpGet; |
| 11 | +import org.elasticsearch.client.Request; |
| 12 | +import org.elasticsearch.client.Response; |
| 13 | +import org.elasticsearch.common.io.Streams; |
| 14 | +import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; |
| 15 | +import org.hamcrest.Matchers; |
| 16 | + |
| 17 | +import java.io.InputStream; |
| 18 | +import java.net.HttpURLConnection; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +public class RestCatSnapshotsIT extends AbstractSnapshotRestTestCase { |
| 22 | + |
| 23 | + public void testCatSnapshotsDefaultsToAllRepositories() throws Exception { |
| 24 | + final String repoName1 = "test-repo-1"; |
| 25 | + final String repoName2 = "test-repo-2"; |
| 26 | + AbstractSnapshotIntegTestCase.createRepository(logger, repoName1, "fs"); |
| 27 | + AbstractSnapshotIntegTestCase.createRepository(logger, repoName2, "fs"); |
| 28 | + final int snapshotsRepo1 = randomIntBetween(1, 20); |
| 29 | + AbstractSnapshotIntegTestCase.createNSnapshots(logger, repoName1, snapshotsRepo1); |
| 30 | + final int snapshotsRepo2 = randomIntBetween(1, 20); |
| 31 | + AbstractSnapshotIntegTestCase.createNSnapshots(logger, repoName2, snapshotsRepo2); |
| 32 | + final Response response = getRestClient().performRequest(new Request(HttpGet.METHOD_NAME, "/_cat/snapshots")); |
| 33 | + assertEquals(HttpURLConnection.HTTP_OK, response.getStatusLine().getStatusCode()); |
| 34 | + final List<String> allLines; |
| 35 | + try (InputStream in = response.getEntity().getContent()) { |
| 36 | + allLines = Streams.readAllLines(in); |
| 37 | + } |
| 38 | + assertThat(allLines, Matchers.hasSize(snapshotsRepo1 + snapshotsRepo2)); |
| 39 | + assertEquals(allLines.stream().filter(l -> l.contains(repoName1)).count(), snapshotsRepo1); |
| 40 | + assertEquals(allLines.stream().filter(l -> l.contains(repoName2)).count(), snapshotsRepo2); |
| 41 | + } |
| 42 | +} |
0 commit comments