|
@@ -0,0 +1,142 @@
|
|
|
+/*
|
|
|
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
+ * or more contributor license agreements. Licensed under the Elastic License
|
|
|
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
|
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
|
+ * Side Public License, v 1.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.elasticsearch.test.simulatedlatencyrepo;
|
|
|
+
|
|
|
+import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
|
|
+import org.elasticsearch.client.internal.Client;
|
|
|
+import org.elasticsearch.cluster.service.ClusterService;
|
|
|
+import org.elasticsearch.common.Strings;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.util.BigArrays;
|
|
|
+import org.elasticsearch.env.Environment;
|
|
|
+import org.elasticsearch.index.query.QueryBuilders;
|
|
|
+import org.elasticsearch.indices.recovery.RecoverySettings;
|
|
|
+import org.elasticsearch.license.LicenseSettings;
|
|
|
+import org.elasticsearch.plugins.Plugin;
|
|
|
+import org.elasticsearch.plugins.RepositoryPlugin;
|
|
|
+import org.elasticsearch.repositories.Repository;
|
|
|
+import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
|
|
|
+import org.elasticsearch.snapshots.SnapshotInfo;
|
|
|
+import org.elasticsearch.xcontent.NamedXContentRegistry;
|
|
|
+import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
|
|
|
+import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
|
|
|
+import org.junit.AfterClass;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.LongAdder;
|
|
|
+
|
|
|
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
|
|
+import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.greaterThan;
|
|
|
+
|
|
|
+public class LatencySimulatingBlobStoreRepositoryTests extends AbstractSnapshotIntegTestCase {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean addMockInternalEngine() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static final String REPO_TYPE = "countingFs";
|
|
|
+
|
|
|
+ public static final LongAdder COUNTS = new LongAdder();
|
|
|
+
|
|
|
+ public static class TestPlugin extends Plugin implements RepositoryPlugin {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Repository.Factory> getRepositories(
|
|
|
+ Environment env,
|
|
|
+ NamedXContentRegistry namedXContentRegistry,
|
|
|
+ ClusterService clusterService,
|
|
|
+ BigArrays bigArrays,
|
|
|
+ RecoverySettings recoverySettings
|
|
|
+ ) {
|
|
|
+ return Map.of(
|
|
|
+ REPO_TYPE,
|
|
|
+ metadata -> new LatencySimulatingBlobStoreRepository(
|
|
|
+ metadata,
|
|
|
+ env,
|
|
|
+ namedXContentRegistry,
|
|
|
+ clusterService,
|
|
|
+ bigArrays,
|
|
|
+ recoverySettings,
|
|
|
+ COUNTS::increment
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterClass
|
|
|
+ public static void resetCounts() {
|
|
|
+ COUNTS.reset();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Collection<Class<? extends Plugin>> nodePlugins() {
|
|
|
+ List<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins());
|
|
|
+ plugins.add(TestPlugin.class);
|
|
|
+ plugins.add(LocalStateSearchableSnapshots.class);
|
|
|
+ return plugins;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
|
|
|
+ Settings.Builder builder = Settings.builder();
|
|
|
+ builder.put(otherSettings);
|
|
|
+ builder.put(LicenseSettings.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial");
|
|
|
+ return builder.build();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testRetrieveSnapshots() throws Exception {
|
|
|
+ final Client client = client();
|
|
|
+ final String repositoryName = "test-repo";
|
|
|
+
|
|
|
+ logger.info("--> creating repository");
|
|
|
+ createRepository(repositoryName, REPO_TYPE, Settings.builder().put("location", randomRepoPath()));
|
|
|
+
|
|
|
+ logger.info("--> creating an index and indexing documents");
|
|
|
+ final String indexName = "test-idx";
|
|
|
+ createIndex(indexName);
|
|
|
+ ensureGreen();
|
|
|
+ int numDocs = randomIntBetween(10, 20);
|
|
|
+ for (int i = 0; i < numDocs; i++) {
|
|
|
+ String id = Integer.toString(i);
|
|
|
+ client().prepareIndex(indexName).setId(id).setSource("text", "sometext").get();
|
|
|
+ }
|
|
|
+ indicesAdmin().prepareFlush(indexName).get();
|
|
|
+
|
|
|
+ SnapshotInfo si = createSnapshot(repositoryName, "test-snap-1", List.of(indexName));
|
|
|
+
|
|
|
+ logger.info("--> delete index");
|
|
|
+ assertAcked(client.admin().indices().prepareDelete("test-idx").get());
|
|
|
+
|
|
|
+ logger.info("--> mount snapshot");
|
|
|
+ final MountSearchableSnapshotRequest req = new MountSearchableSnapshotRequest(
|
|
|
+ "test-idx",
|
|
|
+ repositoryName,
|
|
|
+ si.snapshotId().getName(),
|
|
|
+ indexName,
|
|
|
+ Settings.EMPTY,
|
|
|
+ Strings.EMPTY_ARRAY,
|
|
|
+ true,
|
|
|
+ MountSearchableSnapshotRequest.Storage.FULL_COPY
|
|
|
+ );
|
|
|
+
|
|
|
+ final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
|
|
|
+ assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
|
|
|
+
|
|
|
+ logger.info("--> run a search");
|
|
|
+ var searchResponse = client.prepareSearch("test-idx").setQuery(QueryBuilders.termQuery("text", "sometext")).get();
|
|
|
+
|
|
|
+ assertThat(searchResponse.getHits().getTotalHits().value, greaterThan(0L));
|
|
|
+ assertThat(COUNTS.intValue(), greaterThan(0));
|
|
|
+ }
|
|
|
+}
|