|
24 | 24 | import com.google.cloud.storage.StorageOptions;
|
25 | 25 | import com.sun.net.httpserver.HttpContext;
|
26 | 26 | import com.sun.net.httpserver.HttpServer;
|
| 27 | +import fixture.gcs.FakeOAuth2HttpHandler; |
27 | 28 | import org.apache.http.HttpStatus;
|
28 | 29 | import org.elasticsearch.common.Nullable;
|
29 | 30 | import org.elasticsearch.common.Strings;
|
|
68 | 69 | import java.util.concurrent.atomic.AtomicInteger;
|
69 | 70 | import java.util.concurrent.atomic.AtomicReference;
|
70 | 71 |
|
| 72 | +import static fixture.gcs.GoogleCloudStorageHttpHandler.getContentRangeEnd; |
| 73 | +import static fixture.gcs.GoogleCloudStorageHttpHandler.getContentRangeLimit; |
| 74 | +import static fixture.gcs.GoogleCloudStorageHttpHandler.getContentRangeStart; |
| 75 | +import static fixture.gcs.GoogleCloudStorageHttpHandler.parseMultipartRequestBody; |
71 | 76 | import static java.nio.charset.StandardCharsets.UTF_8;
|
72 | 77 | import static org.elasticsearch.repositories.ESBlobStoreTestCase.randomBytes;
|
73 | 78 | import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.CREDENTIALS_FILE_SETTING;
|
@@ -144,13 +149,7 @@ StorageOptions createStorageOptions(final GoogleCloudStorageClientSettings clien
|
144 | 149 |
|
145 | 150 | final List<HttpContext> httpContexts = Arrays.asList(
|
146 | 151 | // Auth
|
147 |
| - httpServer.createContext("/token", exchange -> { |
148 |
| - byte[] response = ("{\"access_token\":\"foo\",\"token_type\":\"Bearer\",\"expires_in\":3600}").getBytes(UTF_8); |
149 |
| - exchange.getResponseHeaders().add("Content-Type", "application/json"); |
150 |
| - exchange.sendResponseHeaders(HttpStatus.SC_OK, response.length); |
151 |
| - exchange.getResponseBody().write(response); |
152 |
| - exchange.close(); |
153 |
| - }), |
| 152 | + httpServer.createContext("/token", new FakeOAuth2HttpHandler()), |
154 | 153 | // Does bucket exists?
|
155 | 154 | httpServer.createContext("/storage/v1/b/bucket", exchange -> {
|
156 | 155 | byte[] response = ("{\"kind\":\"storage#bucket\",\"name\":\"bucket\",\"id\":\"0\"}").getBytes(UTF_8);
|
@@ -244,7 +243,7 @@ public void testWriteBlobWithRetries() throws Exception {
|
244 | 243 | httpServer.createContext("/upload/storage/v1/b/bucket/o", exchange -> {
|
245 | 244 | assertThat(exchange.getRequestURI().getQuery(), containsString("uploadType=multipart"));
|
246 | 245 | if (countDown.countDown()) {
|
247 |
| - Optional<Tuple<String, BytesArray>> content = TestUtils.parseMultipartRequestBody(exchange.getRequestBody()); |
| 246 | + Optional<Tuple<String, BytesArray>> content = parseMultipartRequestBody(exchange.getRequestBody()); |
248 | 247 | assertThat(content.isPresent(), is(true));
|
249 | 248 | assertThat(content.get().v1(), equalTo("write_blob_max_retries"));
|
250 | 249 | if (Objects.deepEquals(bytes, content.get().v2().array())) {
|
@@ -387,12 +386,12 @@ public void testWriteLargeBlob() throws IOException {
|
387 | 386 | final long bytesRead = Streams.copy(exchange.getRequestBody(), requestBody);
|
388 | 387 | assertThat(Math.toIntExact(bytesRead), anyOf(equalTo(defaultChunkSize), equalTo(lastChunkSize)));
|
389 | 388 |
|
390 |
| - final int rangeStart = TestUtils.getContentRangeStart(range); |
391 |
| - final int rangeEnd = TestUtils.getContentRangeEnd(range); |
| 389 | + final int rangeStart = getContentRangeStart(range); |
| 390 | + final int rangeEnd = getContentRangeEnd(range); |
392 | 391 | assertThat(rangeEnd + 1 - rangeStart, equalTo(Math.toIntExact(bytesRead)));
|
393 | 392 | assertArrayEquals(Arrays.copyOfRange(data, rangeStart, rangeEnd + 1), requestBody.toByteArray());
|
394 | 393 |
|
395 |
| - final Integer limit = TestUtils.getContentRangeLimit(range); |
| 394 | + final Integer limit = getContentRangeLimit(range); |
396 | 395 | if (limit != null) {
|
397 | 396 | exchange.sendResponseHeaders(RestStatus.OK.getStatus(), -1);
|
398 | 397 | exchange.close();
|
|
0 commit comments