Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CAS support for GCP test fixture #118236

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c9892d7
Implement CAS support for GCP test fixture
nicktindall Dec 9, 2024
0598380
Pass upload ID in when creating resumable
nicktindall Dec 9, 2024
655d1ac
Remove redundant code
nicktindall Dec 9, 2024
bd24892
Merge branch 'main' into ES-5679_implement_cas_support_gcp_test_fixture
nicktindall Dec 9, 2024
e8e60e4
Tidy
nicktindall Dec 9, 2024
685ddea
Remove redundant method
nicktindall Dec 9, 2024
70c5da2
Fail test on invalid long parameter
nicktindall Dec 10, 2024
fdf8992
Implement resumable uploads faithfully
nicktindall Dec 10, 2024
cfb70d6
Fix range arithmetic
nicktindall Dec 11, 2024
77dc333
Merge remote-tracking branch 'origin/main' into ES-5679_implement_cas…
nicktindall Dec 11, 2024
5703b9b
Implement streaming uploads and status checks
nicktindall Dec 11, 2024
41e661b
Implement ifGenerationMatch for resumable uploads
nicktindall Dec 11, 2024
d218c31
Fix javadoc
nicktindall Dec 11, 2024
f42e97d
Remove body read check (it seemed to throw?!)
nicktindall Dec 11, 2024
74e1a2e
Update test
nicktindall Dec 11, 2024
07cced3
Tidy
nicktindall Dec 11, 2024
8764886
Merge branch 'main' into ES-5679_implement_cas_support_gcp_test_fixture
nicktindall Dec 11, 2024
78fb6f3
Merge remote-tracking branch 'origin/main' into ES-5679_implement_cas…
nicktindall Dec 18, 2024
c3eea61
Update GCS tests to work with new implementation
nicktindall Dec 18, 2024
dd20d09
Add tests for ifGenerationMatch, de-dupe some of the request creation
nicktindall Dec 19, 2024
b6ea31a
Remove copy-paste artifact
nicktindall Dec 19, 2024
3502439
Use random upload type, tidy
nicktindall Dec 19, 2024
c0de484
Merge branch 'main' into ES-5679_implement_cas_support_gcp_test_fixture
nicktindall Dec 19, 2024
2796005
Ask the server for blob generation
nicktindall Dec 19, 2024
093765d
Avoid name collision for new file tests
nicktindall Dec 19, 2024
8364c15
Use headerString instead of toString
nicktindall Dec 19, 2024
84d0549
Merge remote-tracking branch 'origin/main' into ES-5679_implement_cas…
nicktindall Dec 19, 2024
5f46a3c
Merge branch 'main' into ES-5679_implement_cas_support_gcp_test_fixture
nicktindall Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update GCS tests to work with new implementation
  • Loading branch information
nicktindall committed Dec 18, 2024
commit c3eea61998ecfa0ccd4c87ce95f1522d79b4a284
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,16 @@ private void sendError(HttpExchange exchange, MockGcsBlobStore.GcsRestException
}

private String buildBlobInfoJson(MockGcsBlobStore.BlobVersion blobReference) {
return String.format(Locale.ROOT, """
{"kind":"storage#object","bucket":"%s","name":"%s","id":"%s","size":"%s", "generation": "%d"}
""", bucket, blobReference.path(), blobReference.path(), blobReference.contents().length(), blobReference.generation());
return String.format(
Locale.ROOT,
"""
{"kind":"storage#object","bucket":"%s","name":"%s","id":"%s","size":"%s","generation":"%d"}""",
bucket,
blobReference.path(),
blobReference.path(),
blobReference.contents().length(),
blobReference.generation()
);
}

public Map<String, BytesReference> blobs() {
Expand Down Expand Up @@ -379,7 +386,7 @@ private static String requireHeader(HttpExchange exchange, String headerName) {

private static Long parseOptionalLongParameter(HttpExchange exchange, String parameterName) {
final Map<String, String> params = new HashMap<>();
RestUtils.decodeQueryString(exchange.getRequestURI().getQuery(), 0, params);
RestUtils.decodeQueryString(exchange.getRequestURI(), params);
if (params.containsKey(parameterName)) {
try {
return Long.parseLong(params.get(parameterName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public void testSimpleObjectOperations() {
);

assertEquals(new TestHttpResponse(RestStatus.OK, Strings.format("""
{"kind":"storage#objects","items":[{"kind":"storage#object","bucket":"%s","name":"path/blob","id":"path/blob","size":"50"}
],"prefixes":[]}""", bucket)), handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o"));
{"kind":"storage#objects","items":[{"kind":"storage#object","bucket":"%s","name":"path/blob","id":"path/blob","size":"50",\
"generation":"1"}],"prefixes":[]}""", bucket)), handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o"));

assertEquals(new TestHttpResponse(RestStatus.OK, Strings.format("""
{"kind":"storage#objects","items":[{"kind":"storage#object","bucket":"%s","name":"path/blob","id":"path/blob","size":"50"}
],"prefixes":[]}""", bucket)), handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o?prefix=path/"));
{"kind":"storage#objects","items":[{"kind":"storage#object","bucket":"%s","name":"path/blob","id":"path/blob","size":"50",\
"generation":"1"}],"prefixes":[]}""", bucket)), handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o?prefix=path/"));

assertEquals(
new TestHttpResponse(RestStatus.OK, """
Expand Down Expand Up @@ -211,19 +211,19 @@ public void testResumableUpload() {

final var part1 = randomAlphaOfLength(50);
final var uploadPart1Response = handleRequest(handler, "PUT", sessionURI, part1, contentRangeHeader(0, 50, null));
assertEquals(new TestHttpResponse(RESUME_INCOMPLETE, rangeHeader(0, 50)), uploadPart1Response);
assertEquals(new TestHttpResponse(RESUME_INCOMPLETE, rangeHeader(0, 49)), uploadPart1Response);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned range headers were actually wrong previously. Range is supposed to be inclusive.


assertEquals(
new TestHttpResponse(RESUME_INCOMPLETE, TestHttpExchange.EMPTY_HEADERS),
new TestHttpResponse(RESUME_INCOMPLETE, rangeHeader(0, 49)),
handleRequest(handler, "PUT", sessionURI, BytesArray.EMPTY, contentRangeHeader(null, null, null))
);

final var part2 = randomAlphaOfLength(50);
final var uploadPart2Response = handleRequest(handler, "PUT", sessionURI, part2, contentRangeHeader(51, 100, null));
assertEquals(new TestHttpResponse(RESUME_INCOMPLETE, rangeHeader(51, 100)), uploadPart2Response);
final var uploadPart2Response = handleRequest(handler, "PUT", sessionURI, part2, contentRangeHeader(50, 99, null));
assertEquals(new TestHttpResponse(RESUME_INCOMPLETE, rangeHeader(0, 99)), uploadPart2Response);

final var part3 = randomAlphaOfLength(30);
final var uploadPart3Response = handleRequest(handler, "PUT", sessionURI, part3, contentRangeHeader(101, 130, 130));
final var uploadPart3Response = handleRequest(handler, "PUT", sessionURI, part3, contentRangeHeader(100, 129, 130));
assertEquals(new TestHttpResponse(RestStatus.OK, TestHttpExchange.EMPTY_HEADERS), uploadPart3Response);

// complete upload should be visible now
Expand All @@ -235,14 +235,27 @@ public void testResumableUpload() {
);

// can see in listing
assertEquals(new TestHttpResponse(RestStatus.OK, Strings.format("""
{"kind":"storage#objects","items":[{"kind":"storage#object","bucket":"%s","name":"%s","id":"%s","size":"130"}
],"prefixes":[]}""", bucket, blobName, blobName)), handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o"));
assertEquals(
new TestHttpResponse(RestStatus.OK, Strings.format("""
{"kind":"storage#objects","items":[{"kind":"storage#object","bucket":"%s","name":"%s","id":"%s","size":"130",\
"generation":"1"}],"prefixes":[]}""", bucket, blobName, blobName)),
handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o")
);

// can get metadata
assertEquals(new TestHttpResponse(RestStatus.OK, Strings.format("""
{"kind":"storage#object","bucket":"%s","name":"%s","id":"%s","size":"130"}
""", bucket, blobName, blobName)), handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o/" + blobName));
assertEquals(
new TestHttpResponse(
RestStatus.OK,
Strings.format(
"""
{"kind":"storage#object","bucket":"%s","name":"%s","id":"%s","size":"130","generation":"1"}""",
bucket,
blobName,
blobName
)
),
handleRequest(handler, "GET", "/storage/v1/b/" + bucket + "/o/" + blobName)
);
}

private record TestHttpResponse(int status, BytesReference body, Headers headers) {
Expand Down