Skip to content

Commit abd969e

Browse files
Remove BlobContainer Tests against Mocks (#50194)
* Remove BlobContainer Tests against Mocks Removing all these weird mocks as asked for by #30424. All these tests are now part of real repository ITs and otherwise left unchanged if they had independent tests that didn't call the `createBlobStore` method previously. The HDFS tests also get added coverage as a side-effect because they did not have an implementation of the abstract repository ITs. Closes #30424
1 parent 7c559be commit abd969e

File tree

19 files changed

+314
-1445
lines changed

19 files changed

+314
-1445
lines changed

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureBlobContainerRetriesTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
import java.util.stream.Collectors;
7373

7474
import static java.nio.charset.StandardCharsets.UTF_8;
75-
import static org.elasticsearch.repositories.ESBlobStoreContainerTestCase.randomBytes;
7675
import static org.elasticsearch.repositories.azure.AzureRepository.Repository.CONTAINER_SETTING;
7776
import static org.elasticsearch.repositories.azure.AzureStorageSettings.ACCOUNT_SETTING;
7877
import static org.elasticsearch.repositories.azure.AzureStorageSettings.ENDPOINT_SUFFIX_SETTING;
7978
import static org.elasticsearch.repositories.azure.AzureStorageSettings.KEY_SETTING;
8079
import static org.elasticsearch.repositories.azure.AzureStorageSettings.MAX_RETRIES_SETTING;
8180
import static org.elasticsearch.repositories.azure.AzureStorageSettings.TIMEOUT_SETTING;
81+
import static org.elasticsearch.repositories.blobstore.ESBlobStoreRepositoryIntegTestCase.randomBytes;
8282
import static org.hamcrest.Matchers.containsString;
8383
import static org.hamcrest.Matchers.equalTo;
8484
import static org.hamcrest.Matchers.is;

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureBlobStoreContainerTests.java

-53
This file was deleted.

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceMock.java

-167
This file was deleted.

plugins/repository-gcs/src/test/java/com/google/cloud/storage/StorageRpcOptionUtils.java

-43
This file was deleted.

plugins/repository-gcs/src/test/java/com/google/cloud/storage/StorageTestUtils.java

-37
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import static fixture.gcs.GoogleCloudStorageHttpHandler.getContentRangeStart;
7575
import static fixture.gcs.GoogleCloudStorageHttpHandler.parseMultipartRequestBody;
7676
import static java.nio.charset.StandardCharsets.UTF_8;
77-
import static org.elasticsearch.repositories.ESBlobStoreContainerTestCase.randomBytes;
77+
import static org.elasticsearch.repositories.blobstore.ESBlobStoreRepositoryIntegTestCase.randomBytes;
7878
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.CREDENTIALS_FILE_SETTING;
7979
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.ENDPOINT_SETTING;
8080
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.READ_TIMEOUT_SETTING;

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

+2-45
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,14 @@
2626
import com.google.cloud.storage.StorageBatch;
2727
import com.google.cloud.storage.StorageBatchResult;
2828
import com.google.cloud.storage.StorageException;
29-
import org.apache.lucene.util.BytesRef;
30-
import org.apache.lucene.util.BytesRefBuilder;
3129
import org.elasticsearch.common.blobstore.BlobContainer;
3230
import org.elasticsearch.common.blobstore.BlobPath;
3331
import org.elasticsearch.common.blobstore.BlobStore;
34-
import org.elasticsearch.common.bytes.BytesArray;
35-
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
32+
import org.elasticsearch.test.ESTestCase;
3633

3734
import java.io.IOException;
38-
import java.io.InputStream;
3935
import java.util.Arrays;
4036
import java.util.List;
41-
import java.util.Locale;
42-
import java.util.concurrent.ConcurrentHashMap;
4337

4438
import static org.hamcrest.Matchers.instanceOf;
4539
import static org.mockito.Matchers.any;
@@ -51,44 +45,7 @@
5145
import static org.mockito.Mockito.mock;
5246
import static org.mockito.Mockito.when;
5347

54-
public class GoogleCloudStorageBlobStoreContainerTests extends ESBlobStoreContainerTestCase {
55-
56-
@Override
57-
protected BlobStore newBlobStore() {
58-
final String bucketName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
59-
final String clientName = randomAlphaOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
60-
final GoogleCloudStorageService storageService = mock(GoogleCloudStorageService.class);
61-
try {
62-
when(storageService.client(any(String.class))).thenReturn(new MockStorage(bucketName, new ConcurrentHashMap<>(), random()));
63-
} catch (final Exception e) {
64-
throw new RuntimeException(e);
65-
}
66-
return new GoogleCloudStorageBlobStore(bucketName, clientName, storageService);
67-
}
68-
69-
public void testWriteReadLarge() throws IOException {
70-
try(BlobStore store = newBlobStore()) {
71-
final BlobContainer container = store.blobContainer(new BlobPath());
72-
byte[] data = randomBytes(GoogleCloudStorageBlobStore.LARGE_BLOB_THRESHOLD_BYTE_SIZE + 1);
73-
writeBlob(container, "foobar", new BytesArray(data), randomBoolean());
74-
if (randomBoolean()) {
75-
// override file, to check if we get latest contents
76-
random().nextBytes(data);
77-
writeBlob(container, "foobar", new BytesArray(data), false);
78-
}
79-
try (InputStream stream = container.readBlob("foobar")) {
80-
BytesRefBuilder target = new BytesRefBuilder();
81-
while (target.length() < data.length) {
82-
byte[] buffer = new byte[scaledRandomIntBetween(1, data.length - target.length())];
83-
int offset = scaledRandomIntBetween(0, buffer.length - 1);
84-
int read = stream.read(buffer, offset, buffer.length - offset);
85-
target.append(new BytesRef(buffer, offset, read));
86-
}
87-
assertEquals(data.length, target.length());
88-
assertArrayEquals(data, Arrays.copyOfRange(target.bytes(), 0, target.length()));
89-
}
90-
}
91-
}
48+
public class GoogleCloudStorageBlobStoreContainerTests extends ESTestCase {
9249

9350
@SuppressWarnings("unchecked")
9451
public void testDeleteBlobsIgnoringIfNotExistsThrowsIOException() throws Exception {

0 commit comments

Comments
 (0)