|
26 | 26 | import com.google.cloud.storage.StorageBatch;
|
27 | 27 | import com.google.cloud.storage.StorageBatchResult;
|
28 | 28 | import com.google.cloud.storage.StorageException;
|
29 |
| -import org.apache.lucene.util.BytesRef; |
30 |
| -import org.apache.lucene.util.BytesRefBuilder; |
31 | 29 | import org.elasticsearch.common.blobstore.BlobContainer;
|
32 | 30 | import org.elasticsearch.common.blobstore.BlobPath;
|
33 | 31 | 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; |
36 | 33 |
|
37 | 34 | import java.io.IOException;
|
38 |
| -import java.io.InputStream; |
39 | 35 | import java.util.Arrays;
|
40 | 36 | import java.util.List;
|
41 |
| -import java.util.Locale; |
42 |
| -import java.util.concurrent.ConcurrentHashMap; |
43 | 37 |
|
44 | 38 | import static org.hamcrest.Matchers.instanceOf;
|
45 | 39 | import static org.mockito.Matchers.any;
|
|
51 | 45 | import static org.mockito.Mockito.mock;
|
52 | 46 | import static org.mockito.Mockito.when;
|
53 | 47 |
|
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 { |
92 | 49 |
|
93 | 50 | @SuppressWarnings("unchecked")
|
94 | 51 | public void testDeleteBlobsIgnoringIfNotExistsThrowsIOException() throws Exception {
|
|
0 commit comments