|
@@ -12,27 +12,43 @@ import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequ
|
|
|
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
|
|
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
|
|
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
|
|
+import org.elasticsearch.action.bulk.BulkRequest;
|
|
|
+import org.elasticsearch.action.bulk.BulkResponse;
|
|
|
import org.elasticsearch.action.index.IndexRequest;
|
|
|
-import org.elasticsearch.action.index.IndexResponse;
|
|
|
import org.elasticsearch.action.search.SearchRequest;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.action.support.WriteRequest;
|
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
|
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
|
|
+import org.elasticsearch.client.searchable_snapshots.CachesStatsRequest;
|
|
|
+import org.elasticsearch.client.searchable_snapshots.CachesStatsResponse;
|
|
|
import org.elasticsearch.client.searchable_snapshots.MountSnapshotRequest;
|
|
|
+import org.elasticsearch.common.unit.ByteSizeUnit;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.repositories.fs.FsRepository;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
|
+import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
+import org.junit.Before;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
|
|
|
-import static org.hamcrest.Matchers.anEmptyMap;
|
|
|
+import static org.hamcrest.Matchers.aMapWithSize;
|
|
|
+import static org.hamcrest.Matchers.emptyOrNullString;
|
|
|
+import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.greaterThan;
|
|
|
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
+import static org.hamcrest.Matchers.not;
|
|
|
+import static org.hamcrest.Matchers.notNullValue;
|
|
|
|
|
|
public class SearchableSnapshotsIT extends ESRestHighLevelClientTestCase {
|
|
|
|
|
|
- public void testMountSnapshot() throws IOException {
|
|
|
+ @Before
|
|
|
+ public void init() throws Exception {
|
|
|
{
|
|
|
final CreateIndexRequest request = new CreateIndexRequest("index");
|
|
|
final CreateIndexResponse response = highLevelClient().indices().create(request, RequestOptions.DEFAULT);
|
|
@@ -40,11 +56,14 @@ public class SearchableSnapshotsIT extends ESRestHighLevelClientTestCase {
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- final IndexRequest request = new IndexRequest("index")
|
|
|
- .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
- .source("{}", XContentType.JSON);
|
|
|
- final IndexResponse response = highLevelClient().index(request, RequestOptions.DEFAULT);
|
|
|
- assertThat(response.status(), is(RestStatus.CREATED));
|
|
|
+ final BulkRequest request = new BulkRequest().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+ for (int i = 0; i < 100; i++) {
|
|
|
+ request.add(new IndexRequest("index")
|
|
|
+ .source(XContentType.JSON, "num", i, "text", randomAlphaOfLengthBetween(3, 10)));
|
|
|
+ }
|
|
|
+ final BulkResponse response = highLevelClient().bulk(request, RequestOptions.DEFAULT);
|
|
|
+ assertThat(response.status(), is(RestStatus.OK));
|
|
|
+ assertThat(response.hasFailures(), is(false));
|
|
|
}
|
|
|
|
|
|
{
|
|
@@ -57,11 +76,19 @@ public class SearchableSnapshotsIT extends ESRestHighLevelClientTestCase {
|
|
|
|
|
|
{
|
|
|
final CreateSnapshotRequest request =
|
|
|
- new CreateSnapshotRequest("repository", "snapshot").waitForCompletion(true);
|
|
|
+ new CreateSnapshotRequest("repository", "snapshot").waitForCompletion(true).includeGlobalState(false);
|
|
|
final CreateSnapshotResponse response = highLevelClient().snapshot().create(request, RequestOptions.DEFAULT);
|
|
|
assertThat(response.getSnapshotInfo().status(), is(RestStatus.OK));
|
|
|
}
|
|
|
|
|
|
+ {
|
|
|
+ final DeleteIndexRequest request = new DeleteIndexRequest("index");
|
|
|
+ final AcknowledgedResponse response = highLevelClient().indices().delete(request, RequestOptions.DEFAULT);
|
|
|
+ assertThat(response.isAcknowledged(), is(true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testMountSnapshot() throws IOException {
|
|
|
{
|
|
|
final MountSnapshotRequest request = new MountSnapshotRequest("repository", "snapshot", "index")
|
|
|
.waitForCompletion(true)
|
|
@@ -74,9 +101,48 @@ public class SearchableSnapshotsIT extends ESRestHighLevelClientTestCase {
|
|
|
{
|
|
|
final SearchRequest request = new SearchRequest("renamed_index");
|
|
|
final SearchResponse response = highLevelClient().search(request, RequestOptions.DEFAULT);
|
|
|
- assertThat(response.getHits().getTotalHits().value, is(1L));
|
|
|
- assertThat(response.getHits().getHits()[0].getSourceAsMap(), anEmptyMap());
|
|
|
+ assertThat(response.getHits().getTotalHits().value, is(100L));
|
|
|
+ assertThat(response.getHits().getHits()[0].getSourceAsMap(), aMapWithSize(2));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testCacheStats() throws Exception {
|
|
|
+ final SearchableSnapshotsClient client = new SearchableSnapshotsClient(highLevelClient());
|
|
|
+ {
|
|
|
+ final MountSnapshotRequest request = new MountSnapshotRequest("repository", "snapshot", "index")
|
|
|
+ .waitForCompletion(true)
|
|
|
+ .renamedIndex("mounted_index")
|
|
|
+ .storage(MountSnapshotRequest.Storage.SHARED_CACHE);
|
|
|
+ final RestoreSnapshotResponse response = execute(request, client::mountSnapshot, client::mountSnapshotAsync);
|
|
|
+ assertThat(response.getRestoreInfo().successfulShards(), is(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ final SearchRequest request = new SearchRequest("mounted_index")
|
|
|
+ .source(new SearchSourceBuilder().query(QueryBuilders.rangeQuery("num").from(50)));
|
|
|
+ final SearchResponse response = highLevelClient().search(request, RequestOptions.DEFAULT);
|
|
|
+ assertThat(response.getHits().getTotalHits().value, is(50L));
|
|
|
+ assertThat(response.getHits().getHits()[0].getSourceAsMap(), aMapWithSize(2));
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ final CachesStatsRequest request = new CachesStatsRequest();
|
|
|
+ final CachesStatsResponse response = execute(request, client::cacheStats, client::cacheStatsAsync);
|
|
|
+
|
|
|
+ final List<CachesStatsResponse.NodeCachesStats> nodesCachesStats = response.getNodeCachesStats();
|
|
|
+ assertThat(nodesCachesStats, notNullValue());
|
|
|
+ assertThat(nodesCachesStats.size(), equalTo(1));
|
|
|
+ assertThat(nodesCachesStats.get(0).getNodeId(), not(emptyOrNullString()));
|
|
|
+
|
|
|
+ final CachesStatsResponse.SharedCacheStats stats = nodesCachesStats.get(0).getSharedCacheStats();
|
|
|
+ assertThat(stats.getNumRegions(), equalTo(64));
|
|
|
+ assertThat(stats.getSize(), equalTo(ByteSizeUnit.MB.toBytes(1L)));
|
|
|
+ assertThat(stats.getRegionSize(), equalTo(ByteSizeUnit.KB.toBytes(16L)));
|
|
|
+ assertThat(stats.getWrites(), greaterThanOrEqualTo(1L));
|
|
|
+ assertThat(stats.getBytesWritten(), greaterThan(0L));
|
|
|
+ assertThat(stats.getReads(), greaterThanOrEqualTo(1L));
|
|
|
+ assertThat(stats.getBytesRead(), greaterThan(0L));
|
|
|
+ assertThat(stats.getEvictions(), equalTo(0L));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|