Skip to content

Commit 28b525d

Browse files
authored
deps: update dependency com.google.cloud:google-cloud-storage to v2.17.1 (#1086)
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.cloud:google-cloud-storage](https://togithub.com/googleapis/java-storage) | `2.16.0` -> `2.17.1` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-storage/2.17.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-storage/2.17.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-storage/2.17.1/compatibility-slim/2.16.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-storage/2.17.1/confidence-slim/2.16.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/java-storage</summary> ### [`v2.17.1`](https://togithub.com/googleapis/java-storage/blob/HEAD/CHANGELOG.md#&#8203;2171-httpsgithubcomgoogleapisjava-storagecomparev2170v2171-2023-01-13) [Compare Source](https://togithub.com/googleapis/java-storage/compare/v2.17.0...v2.17.1) ##### Bug Fixes - Update BaseStorageReadChannel to be left open unless explicitly closed ([#&#8203;1853](https://togithub.com/googleapis/java-storage/issues/1853)) ([1425dd9](https://togithub.com/googleapis/java-storage/commit/1425dd97cb7d4a58f0bbededeca543f1a89c7d5d)) ### [`v2.17.0`](https://togithub.com/googleapis/java-storage/blob/HEAD/CHANGELOG.md#&#8203;2170-httpsgithubcomgoogleapisjava-storagecomparev2160v2170-2023-01-12) [Compare Source](https://togithub.com/googleapis/java-storage/compare/v2.16.0...v2.17.0) ##### Features - Implement GrpcStorageImpl BucketAccessControl operations ([#&#8203;1816](https://togithub.com/googleapis/java-storage/issues/1816)) ([5c52079](https://togithub.com/googleapis/java-storage/commit/5c52079fb5f52caf39a49ccb96df6251a9c728d3)) - Implement GrpcStorageImpl ObjectAccessControl operations ([#&#8203;1818](https://togithub.com/googleapis/java-storage/issues/1818)) ([2eec791](https://togithub.com/googleapis/java-storage/commit/2eec791122bb1bb28a1ffb14beb7ce8776c5b5ec)) - Implement GrpcStorageImpl#createDefaultAcl & GrpcStorageImpl#updateDefaultAcl ([#&#8203;1806](https://togithub.com/googleapis/java-storage/issues/1806)) ([0f24a11](https://togithub.com/googleapis/java-storage/commit/0f24a11c5289a4c07f27d8a3c29fab34520b036f)) - Implement GrpcStorageImpl#deleteDefaultAcl ([#&#8203;1807](https://togithub.com/googleapis/java-storage/issues/1807)) ([c783277](https://togithub.com/googleapis/java-storage/commit/c78327717a7936492161ddcc64c86374db72c48c)) - Implement GrpcStorageImpl#getDefaultAcl ([#&#8203;1802](https://togithub.com/googleapis/java-storage/issues/1802)) ([b9b7c49](https://togithub.com/googleapis/java-storage/commit/b9b7c49fcfcab285da156b34b186a007150e876f)) - Implement GrpcStorageImpl#listDefaultAcl ([#&#8203;1805](https://togithub.com/googleapis/java-storage/issues/1805)) ([03c2e66](https://togithub.com/googleapis/java-storage/commit/03c2e6660721b4a8bfc09b241ef44f3e4e08865b)) - Improve throughput of http based storage#reader between 100 MiB/s and 200 MiB/s ([#&#8203;1799](https://togithub.com/googleapis/java-storage/issues/1799)) ([94cd288](https://togithub.com/googleapis/java-storage/commit/94cd2887f22f6d1bb82f9929b388c27c63353d77)) - Update GrpcBlobReadChannel to allow seek/limit after read ([#&#8203;1834](https://togithub.com/googleapis/java-storage/issues/1834)) ([45dc983](https://togithub.com/googleapis/java-storage/commit/45dc983a4af8e7feb937263ce611bd34eda37e03)) ##### Bug Fixes - Add missing preconditions and update samples ([#&#8203;1753](https://togithub.com/googleapis/java-storage/issues/1753)) ([96beca2](https://togithub.com/googleapis/java-storage/commit/96beca2465158fb4633d58fe09a9776a4b171811)) - **grpc:** Fix bucket logging conversion to allow clearing ([#&#8203;1822](https://togithub.com/googleapis/java-storage/issues/1822)) ([30e19dc](https://togithub.com/googleapis/java-storage/commit/30e19dc55c61917c3a73055091e9e6ca0744f172)) - Update gRPC object list implementation to include synthetic directories ([#&#8203;1824](https://togithub.com/googleapis/java-storage/issues/1824)) ([0665c24](https://togithub.com/googleapis/java-storage/commit/0665c2473b5b1a18061d1e58382320ae55295520)) - Update Grpc Write implementation to allow specifying expected md5 ([#&#8203;1815](https://togithub.com/googleapis/java-storage/issues/1815)) ([4662572](https://togithub.com/googleapis/java-storage/commit/46625729b6fd62d8f133c3fb2d8ee00eb64ee8e9)) - Update GrpcConversions to use Bucket.RetentionPolicy.retention_duration ([#&#8203;1798](https://togithub.com/googleapis/java-storage/issues/1798)) ([82fb014](https://togithub.com/googleapis/java-storage/commit/82fb014508178e8ad3fd08e9efc757a8e47564da)) - Update GrpcStorageImpl#update to support fine-grained update of BucketInfo.labels and BlobInfo.metadata ([#&#8203;1843](https://togithub.com/googleapis/java-storage/issues/1843)) ([c8bf3c7](https://togithub.com/googleapis/java-storage/commit/c8bf3c70cca81ed87a52939fe7da58889c8f55ce)) ##### Documentation - Document differing behavior of {get,list}{,default}Acl between HTTP and gRPC ([#&#8203;1820](https://togithub.com/googleapis/java-storage/issues/1820)) ([9511b17](https://togithub.com/googleapis/java-storage/commit/9511b173e84d2b28ab1a1625b16e3e648c3856fb)) ##### Dependencies - Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.1.1 ([#&#8203;1836](https://togithub.com/googleapis/java-storage/issues/1836)) ([3b71fab](https://togithub.com/googleapis/java-storage/commit/3b71fab11ac71039c2a9983821ce02ce25ce311d)) - Update dependency net.jqwik:jqwik to v1.7.2 ([#&#8203;1833](https://togithub.com/googleapis/java-storage/issues/1833)) ([83bc261](https://togithub.com/googleapis/java-storage/commit/83bc261130e89e5994f21e32422054ef6ea2fe8e)) - Update dependency org.junit.vintage:junit-vintage-engine to v5.9.2 ([#&#8203;1837](https://togithub.com/googleapis/java-storage/issues/1837)) ([5b38184](https://togithub.com/googleapis/java-storage/commit/5b381845b4f48a691aa3f0cb96599ddefc7e463f)) - Update junit-platform.version to v5.9.2 ([#&#8203;1838](https://togithub.com/googleapis/java-storage/issues/1838)) ([372521b](https://togithub.com/googleapis/java-storage/commit/372521ba80b12e52c74fae5ac766dbe6610ff0b2)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-storage-nio). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC43My4zIiwidXBkYXRlZEluVmVyIjoiMzQuNzMuMyJ9-->
1 parent 25d2367 commit 28b525d

File tree

4 files changed

+173
-7
lines changed

4 files changed

+173
-7
lines changed

google-cloud-nio/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<groupId>com.google.http-client</groupId>
4343
<artifactId>google-http-client</artifactId>
4444
</dependency>
45+
<!-- Used by tests, but can't be set to test scope otherwise it will be
46+
stripped as a transitive dependency of storage. -->
47+
<dependency>
48+
<groupId>com.google.http-client</groupId>
49+
<artifactId>google-http-client-gson</artifactId>
50+
</dependency>
4551
<dependency>
4652
<groupId>com.google.auto.value</groupId>
4753
<artifactId>auto-value-annotations</artifactId>

google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java

Lines changed: 162 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
package com.google.cloud.storage.contrib.nio.testing;
1818

19+
import com.google.api.client.http.HttpRequestInitializer;
20+
import com.google.api.client.http.HttpTransport;
21+
import com.google.api.client.http.LowLevelHttpRequest;
22+
import com.google.api.client.http.LowLevelHttpResponse;
23+
import com.google.api.client.json.gson.GsonFactory;
24+
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
25+
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
1926
import com.google.api.client.util.DateTime;
2027
import com.google.api.services.storage.model.Bucket;
2128
import com.google.api.services.storage.model.ServiceAccount;
@@ -25,10 +32,15 @@
2532
import com.google.cloud.storage.StorageException;
2633
import com.google.cloud.storage.spi.v1.StorageRpc;
2734
import com.google.cloud.storage.testing.StorageRpcTestBase;
35+
import com.google.common.base.Preconditions;
36+
import java.io.ByteArrayInputStream;
2837
import java.io.IOException;
2938
import java.io.InputStream;
3039
import java.io.OutputStream;
40+
import java.io.UnsupportedEncodingException;
3141
import java.math.BigInteger;
42+
import java.net.URLDecoder;
43+
import java.nio.charset.StandardCharsets;
3244
import java.nio.file.FileAlreadyExistsException;
3345
import java.text.SimpleDateFormat;
3446
import java.util.ArrayList;
@@ -37,6 +49,8 @@
3749
import java.util.List;
3850
import java.util.Map;
3951
import java.util.concurrent.ConcurrentHashMap;
52+
import java.util.regex.Matcher;
53+
import java.util.regex.Pattern;
4054
import javax.annotation.concurrent.NotThreadSafe;
4155

4256
/**
@@ -76,6 +90,11 @@ class FakeStorageRpc extends StorageRpcTestBase {
7690
private static final SimpleDateFormat RFC_3339_FORMATTER =
7791
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
7892

93+
private static final int OK = 200;
94+
private static final int PARTIAL_CONTENT = 206;
95+
private static final int NOT_FOUND = 404;
96+
private static final byte[] EMPTY_BYTES = new byte[0];
97+
7998
// fullname -> metadata
8099
Map<String, StorageObject> metadata = new ConcurrentHashMap<>();
81100
// fullname -> contents
@@ -244,7 +263,7 @@ public StorageObject compose(
244263
public byte[] load(StorageObject storageObject, Map<Option, ?> options) throws StorageException {
245264
String key = fullname(storageObject);
246265
if (!contents.containsKey(key)) {
247-
throw new StorageException(404, "File not found: " + key);
266+
throw new StorageException(NOT_FOUND, "File not found: " + key);
248267
}
249268
return contents.get(key);
250269
}
@@ -264,7 +283,7 @@ public Tuple<String, byte[]> read(
264283
}
265284
String key = fullname(from);
266285
if (!contents.containsKey(key)) {
267-
throw new StorageException(404, "File not found: " + key);
286+
throw new StorageException(NOT_FOUND, "File not found: " + key);
268287
}
269288
checkGeneration(key, generationMatch);
270289
long position = zposition;
@@ -299,7 +318,7 @@ public long read(
299318
}
300319
String key = fullname(from);
301320
if (!contents.containsKey(key)) {
302-
throw new StorageException(404, "File not found: " + key);
321+
throw new StorageException(NOT_FOUND, "File not found: " + key);
303322
}
304323
checkGeneration(key, generationMatch);
305324
if (position < 0) {
@@ -396,7 +415,7 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws Storage
396415

397416
// a little hackish, just good enough for the tests to work.
398417
if (!contents.containsKey(sourceKey)) {
399-
throw new StorageException(404, "File not found: " + sourceKey);
418+
throw new StorageException(NOT_FOUND, "File not found: " + sourceKey);
400419
}
401420

402421
// if non-null, then we check the file's at that generation.
@@ -444,7 +463,7 @@ private static DateTime now() {
444463
}
445464

446465
private String fullname(StorageObject so) {
447-
return (so.getBucket() + "/" + so.getName());
466+
return fullname(so.getBucket(), so.getName());
448467
}
449468

450469
private BigInteger size(StorageObject so) {
@@ -481,7 +500,8 @@ private void checkGeneration(String key, Long generationMatch) {
481500
Long generation = metadata.get(key).getGeneration();
482501
if (!generationMatch.equals(generation)) {
483502
throw new StorageException(
484-
404, "Generation mismatch. Requested " + generationMatch + " but got " + generation);
503+
NOT_FOUND,
504+
"Generation mismatch. Requested " + generationMatch + " but got " + generation);
485505
}
486506
}
487507
}
@@ -517,4 +537,140 @@ private static boolean processedAsFolder(
517537
public ServiceAccount getServiceAccount(String projectId) {
518538
return null;
519539
}
540+
541+
@Override
542+
public com.google.api.services.storage.Storage getStorage() {
543+
HttpTransport transport = new FakeStorageRpcHttpTransport();
544+
HttpRequestInitializer httpRequestInitializer = request -> {};
545+
return new com.google.api.services.storage.Storage(
546+
transport, new GsonFactory(), httpRequestInitializer);
547+
}
548+
549+
private static String fullname(String bucket, String object) {
550+
return String.format("%s/%s", bucket, object);
551+
}
552+
553+
private static final String KEY_PATTERN_DEFINITION = "^.*?/b/(.*?)/o/(.*?)(?:[?].*|$)";
554+
private static final Pattern KEY_PATTERN = Pattern.compile(KEY_PATTERN_DEFINITION);
555+
556+
MyMockLowLevelHttpRequest create(String url) {
557+
Matcher m = KEY_PATTERN.matcher(url);
558+
Preconditions.checkArgument(
559+
m.matches(),
560+
"Provided url '%s' does not match expected pattern '%s'",
561+
url,
562+
KEY_PATTERN_DEFINITION);
563+
564+
String bucket = m.group(1);
565+
String object = m.group(2);
566+
567+
String decode = urlDecode(object);
568+
String key = fullname(bucket, decode);
569+
return new MyMockLowLevelHttpRequest(url, key);
570+
}
571+
572+
private static String urlDecode(String object) {
573+
try {
574+
return URLDecoder.decode(object, StandardCharsets.UTF_8.name());
575+
} catch (UnsupportedEncodingException e) {
576+
throw new RuntimeException(e);
577+
}
578+
}
579+
580+
private class MyMockLowLevelHttpRequest extends MockLowLevelHttpRequest {
581+
582+
private final String key;
583+
584+
private MyMockLowLevelHttpRequest(String url, String key) {
585+
super(url);
586+
this.key = key;
587+
}
588+
589+
/**
590+
* {@link MockLowLevelHttpRequest#execute} tries to return a value, but we need to compute based
591+
* upon possible request mutations. So override it to call {@link #getResponse()}.
592+
*/
593+
@Override
594+
public LowLevelHttpResponse execute() throws IOException {
595+
return getResponse();
596+
}
597+
598+
@Override
599+
public MockLowLevelHttpResponse getResponse() {
600+
601+
MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
602+
byte[] bytes = contents.get(key);
603+
if (bytes == null) {
604+
resp.setStatusCode(NOT_FOUND);
605+
} else {
606+
int length = bytes.length;
607+
Map<String, List<String>> headers = getHeaders();
608+
List<String> range = headers.get("range");
609+
int begin = 0;
610+
int endInclusive = length - 1;
611+
if (range != null && !range.isEmpty()) {
612+
String rangeString = range.get(0).substring("range=".length());
613+
if ("0-".equals(rangeString)) {
614+
resp.setStatusCode(OK);
615+
} else if (rangeString.startsWith("-")) {
616+
// we don't support negative offsets yet
617+
resp.setStatusCode(400);
618+
return resp;
619+
} else if (rangeString.endsWith("-")) {
620+
// only lower bounded
621+
String beginS = rangeString.substring(0, rangeString.length() - 1);
622+
begin = Integer.parseInt(beginS);
623+
resp.setStatusCode(PARTIAL_CONTENT);
624+
} else {
625+
// otherwise a lower and upper bound
626+
int i = rangeString.indexOf('-');
627+
if (i == -1) {
628+
resp.setStatusCode(400);
629+
return resp;
630+
} else {
631+
String beginS = rangeString.substring(0, i);
632+
String endInclusiveS = rangeString.substring(i + 1);
633+
begin = Integer.parseInt(beginS);
634+
endInclusive = Integer.parseInt(endInclusiveS);
635+
resp.setStatusCode(PARTIAL_CONTENT);
636+
}
637+
}
638+
639+
if (begin > length) {
640+
resp.addHeader("Content-Range", String.format("bytes */%d", length));
641+
resp.setContent(EMPTY_BYTES);
642+
resp.setContent(new ByteArrayInputStream(EMPTY_BYTES));
643+
} else {
644+
int newLength = endInclusive - begin + 1;
645+
resp.addHeader("Content-Length", String.valueOf(newLength));
646+
// Content-Range: bytes 4-9/512
647+
resp.addHeader(
648+
"Content-Range", String.format("bytes %d-%d/%d", begin, endInclusive, length));
649+
byte[] content = Arrays.copyOfRange(bytes, begin, endInclusive + 1);
650+
resp.setContent(content);
651+
resp.setContent(new ByteArrayInputStream(content));
652+
}
653+
} else {
654+
resp.addHeader("Content-Length", String.valueOf(length));
655+
resp.setContent(bytes);
656+
resp.setContent(new ByteArrayInputStream(bytes));
657+
resp.setStatusCode(OK);
658+
}
659+
}
660+
return resp;
661+
}
662+
}
663+
664+
private class FakeStorageRpcHttpTransport extends HttpTransport {
665+
666+
@Override
667+
public boolean supportsMethod(String method) {
668+
return "GET".equals(method);
669+
}
670+
671+
@Override
672+
public LowLevelHttpRequest buildRequest(String method, String url) {
673+
return create(url);
674+
}
675+
}
520676
}

google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/it/ITGcsNio.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public void testReadByteChannel() throws IOException {
415415
ByteBuffer buf = ByteBuffer.allocate(SML_SIZE);
416416
int read = 0;
417417
while (chan.isOpen()) {
418+
buf.clear();
418419
int rc = chan.read(buf);
419420
assertThat(chan.size()).isEqualTo(size);
420421
if (rc < 0) {
@@ -794,6 +795,7 @@ public void testFileChannelRead() throws IOException {
794795
ByteBuffer buf = ByteBuffer.allocate(SML_SIZE);
795796
int read = 0;
796797
while (chan.isOpen()) {
798+
buf.clear();
797799
int rc = chan.read(buf);
798800
assertThat(chan.size()).isEqualTo(size);
799801
if (rc < 0) {
@@ -954,6 +956,7 @@ public void testFileChannelTransferFrom() throws IOException {
954956
ByteBuffer buf = ByteBuffer.allocate(SML_SIZE);
955957
int read = 0;
956958
while (source.isOpen()) {
959+
buf.clear();
957960
int rc = source.read(buf);
958961
assertThat(source.size()).isEqualTo(size);
959962
if (rc < 0) {
@@ -997,6 +1000,7 @@ public void testFileChannelTransferTo() throws IOException {
9971000
ByteBuffer buf = ByteBuffer.allocate(SML_SIZE);
9981001
int read = 0;
9991002
while (source.isOpen()) {
1003+
buf.clear();
10001004
int rc = source.read(buf);
10011005
assertThat(source.size()).isEqualTo(size);
10021006
if (rc < 0) {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<dependency>
7979
<groupId>com.google.cloud</groupId>
8080
<artifactId>google-cloud-storage</artifactId>
81-
<version>2.16.0</version>
81+
<version>2.17.1</version>
8282
</dependency>
8383
<dependency>
8484
<groupId>com.google.apis</groupId>

0 commit comments

Comments
 (0)