Skip to content

Commit 9a95be3

Browse files
authored
[Tests] Extract the testing logic for Google Cloud Storage (#28576)
This pull request extracts in a dedicated class the request/response logic that "emulates" a Google Cloud Storage service in our repository-gcs tests. The idea behind this is to make the logic more reusable. The class MockHttpTransport has been renamed to MockStorage which now only takes care of instantiating a Storage client and does the low-level request/response plumbing needed by this client. The "Google Cloud Storage" logic has been extracted from MockHttpTransport and put in a new GoogleCloudStorageTestServer that is now independent from the google client testing framework.
1 parent 793cbc6 commit 9a95be3

6 files changed

+594
-440
lines changed

plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreContainerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
2525

26-
import java.io.IOException;
2726
import java.util.Locale;
2827

2928
public class GoogleCloudStorageBlobStoreContainerTests extends ESBlobStoreContainerTestCase {
29+
3030
@Override
31-
protected BlobStore newBlobStore() throws IOException {
31+
protected BlobStore newBlobStore() {
3232
String bucket = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
33-
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockHttpTransport.newStorage(bucket, getTestName()));
33+
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockStorage.newStorageClient(bucket, getTestName()));
3434
}
3535
}

plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected void createTestRepository(String name) {
6565

6666
@BeforeClass
6767
public static void setUpStorage() {
68-
storage.set(MockHttpTransport.newStorage(BUCKET, GoogleCloudStorageBlobStoreRepositoryTests.class.getName()));
68+
storage.set(MockStorage.newStorageClient(BUCKET, GoogleCloudStorageBlobStoreRepositoryTests.class.getName()));
6969
}
7070

7171
public static class MockGoogleCloudStoragePlugin extends GoogleCloudStoragePlugin {

plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.repositories.ESBlobStoreTestCase;
2525

26-
import java.io.IOException;
2726
import java.util.Locale;
2827

2928
public class GoogleCloudStorageBlobStoreTests extends ESBlobStoreTestCase {
3029

3130
@Override
32-
protected BlobStore newBlobStore() throws IOException {
31+
protected BlobStore newBlobStore() {
3332
String bucket = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
34-
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockHttpTransport.newStorage(bucket, getTestName()));
33+
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockStorage.newStorageClient(bucket, getTestName()));
3534
}
3635
}

0 commit comments

Comments
 (0)