From f5c5411fe8dcfe4a099d0d43d816065ed80d01e3 Mon Sep 17 00:00:00 2001
From: Tanguy Leroux <tlrx.dev@gmail.com>
Date: Tue, 1 Oct 2019 08:39:55 +0200
Subject: [PATCH] Differentiate base paths in repository integration tests
 (#47284) (#47300)

This commit change the repositories base paths used in Azure/S3/GCS
integration tests so that they don't conflict with each other when tests
 run in parallel on real storage services.

Closes #47202
---
 plugins/repository-azure/build.gradle               |  2 +-
 .../qa/microsoft-azure-storage/build.gradle         |  2 +-
 .../test/repository_azure/10_repository.yml         |  3 ---
 plugins/repository-gcs/build.gradle                 |  2 +-
 .../qa/google-cloud-storage/build.gradle            |  2 +-
 .../repositories/hdfs/HdfsRepositoryTests.java      | 13 ++++++++++++-
 plugins/repository-s3/build.gradle                  |  6 +++---
 .../AbstractThirdPartyRepositoryTestCase.java       |  6 ++++++
 8 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/plugins/repository-azure/build.gradle b/plugins/repository-azure/build.gradle
index 47ee57d3a3e..49451984843 100644
--- a/plugins/repository-azure/build.gradle
+++ b/plugins/repository-azure/build.gradle
@@ -88,7 +88,7 @@ task thirdPartyTest(type: Test) {
   systemProperty 'test.azure.key', azureKey ? azureKey : ""
   systemProperty 'test.azure.sas_token', azureSasToken ? azureSasToken : ""
   systemProperty 'test.azure.container', azureContainer ? azureContainer : ""
-  systemProperty 'test.azure.base', azureBasePath ? azureBasePath : ""
+  systemProperty 'test.azure.base', (azureBasePath ? azureBasePath : "") + "_third_party_tests_" + project.testSeed
 }
 
 if (azureAccount || azureKey || azureContainer || azureBasePath || azureSasToken) {
diff --git a/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle b/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle
index ddde107413c..4720fe29edf 100644
--- a/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle
+++ b/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle
@@ -54,7 +54,7 @@ task azureStorageFixture(type: AntFixture) {
 
 Map<String, Object> expansions = [
         'container': azureContainer,
-        'base_path': azureBasePath
+        'base_path': azureBasePath + "_integration_tests"
 ]
 
 processTestResources {
diff --git a/plugins/repository-azure/qa/microsoft-azure-storage/src/test/resources/rest-api-spec/test/repository_azure/10_repository.yml b/plugins/repository-azure/qa/microsoft-azure-storage/src/test/resources/rest-api-spec/test/repository_azure/10_repository.yml
index 735915adaa6..92866190959 100644
--- a/plugins/repository-azure/qa/microsoft-azure-storage/src/test/resources/rest-api-spec/test/repository_azure/10_repository.yml
+++ b/plugins/repository-azure/qa/microsoft-azure-storage/src/test/resources/rest-api-spec/test/repository_azure/10_repository.yml
@@ -15,9 +15,6 @@ setup:
 
 ---
 "Snapshot/Restore with repository-azure":
-  - skip:
-      version: "all"
-      reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/47201"
 
   # Get repository
   - do:
diff --git a/plugins/repository-gcs/build.gradle b/plugins/repository-gcs/build.gradle
index f16a82fc558..2e67f5273f4 100644
--- a/plugins/repository-gcs/build.gradle
+++ b/plugins/repository-gcs/build.gradle
@@ -137,7 +137,7 @@ task thirdPartyTest(type: Test) {
   include '**/GoogleCloudStorageThirdPartyTests.class'
   systemProperty 'test.google.account', gcsServiceAccount ? Base64.encoder.encodeToString(Files.readAllBytes(file(gcsServiceAccount).toPath())) : ""
   systemProperty 'test.google.bucket', gcsBucket ? gcsBucket : ""
-  systemProperty 'test.google.base', gcsBasePath ? gcsBasePath : "/"
+  systemProperty 'test.google.base', (gcsBasePath ? gcsBasePath : "/") + "_third_party_tests_" + project.testSeed
 }
 
 if (gcsServiceAccount || gcsBucket || gcsBasePath) {
diff --git a/plugins/repository-gcs/qa/google-cloud-storage/build.gradle b/plugins/repository-gcs/qa/google-cloud-storage/build.gradle
index d2411c75776..c3a8d95d2f7 100644
--- a/plugins/repository-gcs/qa/google-cloud-storage/build.gradle
+++ b/plugins/repository-gcs/qa/google-cloud-storage/build.gradle
@@ -78,7 +78,7 @@ task createServiceAccountFile() {
 
 Map<String, Object> expansions = [
         'bucket': gcsBucket,
-        'base_path': gcsBasePath
+        'base_path': gcsBasePath + "_integration_tests"
 ]
 
 processTestResources {
diff --git a/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryTests.java b/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryTests.java
index d65db92f067..63496c00db8 100644
--- a/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryTests.java
+++ b/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryTests.java
@@ -46,9 +46,16 @@ public class HdfsRepositoryTests extends AbstractThirdPartyRepositoryTestCase {
         return new MockSecureSettings();
     }
 
+    @Override
+    public void tearDown() throws Exception {
+        if (isJava11() == false) {
+            super.tearDown();
+        }
+    }
+
     @Override
     protected void createRepository(String repoName) {
-        assumeFalse("https://github.com/elastic/elasticsearch/issues/31498", JavaVersion.current().equals(JavaVersion.parse("11")));
+        assumeFalse("https://github.com/elastic/elasticsearch/issues/31498", isJava11());
         AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(repoName)
             .setType("hdfs")
             .setSettings(Settings.builder()
@@ -70,4 +77,8 @@ public class HdfsRepositoryTests extends AbstractThirdPartyRepositoryTestCase {
             assertThat(response.result().blobs(), equalTo(0L));
         }
     }
+
+    private static boolean isJava11() {
+        return JavaVersion.current().equals(JavaVersion.parse("11"));
+    }
 }
diff --git a/plugins/repository-s3/build.gradle b/plugins/repository-s3/build.gradle
index 2d7e60ae16e..96be32277f4 100644
--- a/plugins/repository-s3/build.gradle
+++ b/plugins/repository-s3/build.gradle
@@ -141,7 +141,7 @@ task thirdPartyTest(type: Test) {
   systemProperty 'test.s3.account', s3PermanentAccessKey
   systemProperty 'test.s3.key', s3PermanentSecretKey
   systemProperty 'test.s3.bucket', s3PermanentBucket
-  systemProperty 'test.s3.base', s3PermanentBasePath
+  systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + project.testSeed
 }
 
 if (useFixture) {
@@ -255,9 +255,9 @@ task s3Fixture(type: AntFixture) {
 processTestResources {
   Map<String, Object> expansions = [
           'permanent_bucket': s3PermanentBucket,
-          'permanent_base_path': s3PermanentBasePath,
+          'permanent_base_path': s3PermanentBasePath + "_integration_tests",
           'temporary_bucket': s3TemporaryBucket,
-          'temporary_base_path': s3TemporaryBasePath,
+          'temporary_base_path': s3TemporaryBasePath + "_integration_tests",
           'ec2_bucket': s3EC2Bucket,
           'ec2_base_path': s3EC2BasePath,
           'ecs_bucket': s3ECSBucket,
diff --git a/test/framework/src/main/java/org/elasticsearch/repositories/AbstractThirdPartyRepositoryTestCase.java b/test/framework/src/main/java/org/elasticsearch/repositories/AbstractThirdPartyRepositoryTestCase.java
index 4dff0401b5a..afb8ac9454f 100644
--- a/test/framework/src/main/java/org/elasticsearch/repositories/AbstractThirdPartyRepositoryTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/repositories/AbstractThirdPartyRepositoryTestCase.java
@@ -72,6 +72,12 @@ public abstract class AbstractThirdPartyRepositoryTestCase extends ESSingleNodeT
         deleteAndAssertEmpty(getRepository().basePath());
     }
 
+    @Override
+    public void tearDown() throws Exception {
+        deleteAndAssertEmpty(getRepository().basePath());
+        super.tearDown();
+    }
+
     private void deleteAndAssertEmpty(BlobPath path) throws Exception {
         final BlobStoreRepository repo = getRepository();
         final PlainActionFuture<Void> future = PlainActionFuture.newFuture();