Skip to content

Commit

Permalink
fix: implement writeWithResponse in FakeStorageRpc (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
athakor authored Aug 3, 2020
1 parent 0ef14c1 commit 10ddfae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand All @@ -367,6 +379,7 @@ public void write(
} else {
futureContents.put(uploadId, bytes);
}
return storageObject;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 10ddfae

Please sign in to comment.