|
10 | 10 |
|
11 | 11 | import fixture.gcs.FakeOAuth2HttpHandler; |
12 | 12 | import fixture.gcs.GoogleCloudStorageHttpHandler; |
| 13 | +import fixture.gcs.MultipartUpload; |
13 | 14 |
|
14 | 15 | import com.google.api.client.http.HttpExecuteInterceptor; |
15 | 16 | import com.google.api.client.http.HttpRequestInitializer; |
|
43 | 44 | import org.elasticsearch.core.Nullable; |
44 | 45 | import org.elasticsearch.core.SuppressForbidden; |
45 | 46 | import org.elasticsearch.core.TimeValue; |
46 | | -import org.elasticsearch.core.Tuple; |
47 | 47 | import org.elasticsearch.http.ResponseInjectingHttpHandler; |
48 | 48 | import org.elasticsearch.repositories.blobstore.AbstractBlobContainerRetriesTestCase; |
49 | 49 | import org.elasticsearch.repositories.blobstore.ESMockAPIBasedRepositoryIntegTestCase; |
|
62 | 62 | import java.util.Locale; |
63 | 63 | import java.util.Map; |
64 | 64 | import java.util.Objects; |
65 | | -import java.util.Optional; |
66 | 65 | import java.util.Queue; |
67 | 66 | import java.util.concurrent.ConcurrentHashMap; |
68 | 67 | import java.util.concurrent.ConcurrentLinkedQueue; |
69 | 68 | import java.util.concurrent.atomic.AtomicBoolean; |
70 | 69 | import java.util.concurrent.atomic.AtomicInteger; |
71 | 70 | import java.util.concurrent.atomic.AtomicReference; |
72 | 71 |
|
73 | | -import static fixture.gcs.GoogleCloudStorageHttpHandler.parseMultipartRequestBody; |
74 | 72 | import static fixture.gcs.TestUtils.createServiceAccount; |
75 | 73 | import static java.nio.charset.StandardCharsets.UTF_8; |
76 | 74 | import static org.elasticsearch.repositories.blobstore.BlobStoreTestUtil.randomPurpose; |
|
80 | 78 | import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.ENDPOINT_SETTING; |
81 | 79 | import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.READ_TIMEOUT_SETTING; |
82 | 80 | import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.TOKEN_URI_SETTING; |
83 | | -import static org.elasticsearch.test.hamcrest.OptionalMatchers.isPresent; |
84 | 81 | import static org.hamcrest.Matchers.anyOf; |
85 | 82 | import static org.hamcrest.Matchers.containsString; |
86 | 83 | import static org.hamcrest.Matchers.equalTo; |
@@ -268,17 +265,16 @@ public void testWriteBlobWithRetries() throws Exception { |
268 | 265 | final CountDown countDown = new CountDown(maxRetries); |
269 | 266 |
|
270 | 267 | final BlobContainer blobContainer = blobContainerBuilder().maxRetries(maxRetries).build(); |
271 | | - final byte[] bytes = randomBlobContent(); |
| 268 | + final byte[] bytes = randomBlobContent(0); |
272 | 269 | httpServer.createContext("/upload/storage/v1/b/bucket/o", safeHandler(exchange -> { |
273 | 270 | assertThat(exchange.getRequestURI().getQuery(), containsString("uploadType=multipart")); |
274 | 271 | if (countDown.countDown()) { |
275 | | - Optional<Tuple<String, BytesReference>> content = parseMultipartRequestBody(exchange.getRequestBody()); |
276 | | - assertThat(content, isPresent()); |
277 | | - assertThat(content.get().v1(), equalTo(blobContainer.path().buildAsString() + "write_blob_max_retries")); |
278 | | - if (Objects.deepEquals(bytes, BytesReference.toBytes(content.get().v2()))) { |
| 272 | + MultipartUpload multipartUpload = MultipartUpload.parseBody(exchange, exchange.getRequestBody()); |
| 273 | + assertEquals(multipartUpload.name(), blobContainer.path().buildAsString() + "write_blob_max_retries"); |
| 274 | + if (multipartUpload.content().equals(new BytesArray(bytes))) { |
279 | 275 | byte[] response = Strings.format(""" |
280 | 276 | {"bucket":"bucket","name":"%s"} |
281 | | - """, content.get().v1()).getBytes(UTF_8); |
| 277 | + """, multipartUpload.name()).getBytes(UTF_8); |
282 | 278 | exchange.getResponseHeaders().add("Content-Type", "application/json"); |
283 | 279 | exchange.sendResponseHeaders(RestStatus.OK.getStatus(), response.length); |
284 | 280 | exchange.getResponseBody().write(response); |
|
0 commit comments