Skip to content

Commit 10ddfae

Browse files
authored
fix: implement writeWithResponse in FakeStorageRpc (#187)
1 parent 0ef14c1 commit 10ddfae

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ public String open(String signedURL) {
338338
public void write(
339339
String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last)
340340
throws StorageException {
341+
writeWithResponse(uploadId, toWrite, toWriteOffset, destOffset, length, last);
342+
}
343+
344+
@Override
345+
public StorageObject writeWithResponse(
346+
String uploadId,
347+
byte[] toWrite,
348+
int toWriteOffset,
349+
long destOffset,
350+
int length,
351+
boolean last) {
341352
// this may have a lot more allocations than ideal, but it'll work.
342353
byte[] bytes;
343354
if (futureContents.containsKey(uploadId)) {
@@ -352,11 +363,12 @@ public void write(
352363
}
353364
System.arraycopy(toWrite, toWriteOffset, bytes, (int) destOffset, length);
354365
// we want to mimic the GCS behavior that file contents are only visible on close.
366+
StorageObject storageObject = null;
355367
if (last) {
356368
contents.put(uploadId, bytes);
357369
futureContents.remove(uploadId);
358370
if (metadata.containsKey(uploadId)) {
359-
StorageObject storageObject = metadata.get(uploadId);
371+
storageObject = metadata.get(uploadId);
360372
Long generation = storageObject.getGeneration();
361373
if (null == generation) {
362374
generation = Long.valueOf(0);
@@ -367,6 +379,7 @@ public void write(
367379
} else {
368380
futureContents.put(uploadId, bytes);
369381
}
382+
return storageObject;
370383
}
371384

372385
@Override

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<dependency>
8888
<groupId>com.google.cloud</groupId>
8989
<artifactId>google-cloud-storage</artifactId>
90-
<version>1.110.0</version>
90+
<version>1.111.1</version>
9191
</dependency>
9292
<dependency>
9393
<groupId>com.google.apis</groupId>

0 commit comments

Comments
 (0)