Skip to content
Permalink
Browse files
fix: implement writeWithResponse in FakeStorageRpc (#187)
  • Loading branch information
athakor committed Aug 3, 2020
1 parent 0ef14c1 commit 10ddfae3923f1d5e64b151293db238f1af433d03
Showing with 15 additions and 2 deletions.
  1. +14 −1 google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java
  2. +1 −1 pom.xml
@@ -338,6 +338,17 @@ public String open(String signedURL) {
public void write(
String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last)
throws StorageException {
writeWithResponse(uploadId, toWrite, toWriteOffset, destOffset, length, last);
}

@Override
public StorageObject writeWithResponse(
String uploadId,
byte[] toWrite,
int toWriteOffset,
long destOffset,
int length,
boolean last) {
// this may have a lot more allocations than ideal, but it'll work.
byte[] bytes;
if (futureContents.containsKey(uploadId)) {
@@ -352,11 +363,12 @@ public void write(
}
System.arraycopy(toWrite, toWriteOffset, bytes, (int) destOffset, length);
// we want to mimic the GCS behavior that file contents are only visible on close.
StorageObject storageObject = null;
if (last) {
contents.put(uploadId, bytes);
futureContents.remove(uploadId);
if (metadata.containsKey(uploadId)) {
StorageObject storageObject = metadata.get(uploadId);
storageObject = metadata.get(uploadId);
Long generation = storageObject.getGeneration();
if (null == generation) {
generation = Long.valueOf(0);
@@ -367,6 +379,7 @@ public void write(
} else {
futureContents.put(uploadId, bytes);
}
return storageObject;
}

@Override
@@ -87,7 +87,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.110.0</version>
<version>1.111.1</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>

0 comments on commit 10ddfae

Please sign in to comment.