Skip to content

Commit

Permalink
[Tests] Extract the testing logic for Google Cloud Storage (#28576)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tlrx committed Feb 21, 2018
1 parent 6c62a07 commit 6f61a9b
Show file tree
Hide file tree
Showing 6 changed files with 594 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;

import java.io.IOException;
import java.util.Locale;

public class GoogleCloudStorageBlobStoreContainerTests extends ESBlobStoreContainerTestCase {

@Override
protected BlobStore newBlobStore() throws IOException {
protected BlobStore newBlobStore() {
String bucket = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockHttpTransport.newStorage(bucket, getTestName()));
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockStorage.newStorageClient(bucket, getTestName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void createTestRepository(String name) {

@BeforeClass
public static void setUpStorage() {
storage.set(MockHttpTransport.newStorage(BUCKET, GoogleCloudStorageBlobStoreRepositoryTests.class.getName()));
storage.set(MockStorage.newStorageClient(BUCKET, GoogleCloudStorageBlobStoreRepositoryTests.class.getName()));
}

public static class MockGoogleCloudStoragePlugin extends GoogleCloudStoragePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.repositories.ESBlobStoreTestCase;

import java.io.IOException;
import java.util.Locale;

public class GoogleCloudStorageBlobStoreTests extends ESBlobStoreTestCase {

@Override
protected BlobStore newBlobStore() throws IOException {
protected BlobStore newBlobStore() {
String bucket = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockHttpTransport.newStorage(bucket, getTestName()));
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockStorage.newStorageClient(bucket, getTestName()));
}
}
Loading

0 comments on commit 6f61a9b

Please sign in to comment.