From 2db2b796845ea891a1e4c9ec438a961cd37c2e72 Mon Sep 17 00:00:00 2001 From: athakor Date: Mon, 3 Aug 2020 15:12:50 +0530 Subject: [PATCH] fix: implement writeWithResponse in FakeStorageRpc --- .../contrib/nio/testing/FakeStorageRpc.java | 15 ++++++++++++++- pom.xml | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java b/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java index 55d0b52b..f738b52e 100644 --- a/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java +++ b/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java @@ -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 diff --git a/pom.xml b/pom.xml index 14007055..bc01af06 100644 --- a/pom.xml +++ b/pom.xml @@ -87,7 +87,7 @@ com.google.cloud google-cloud-storage - 1.110.0 + 1.111.1 com.google.apis