diff options
author | 2016-09-22 13:59:02 -0800 | |
---|---|---|
committer | 2016-09-22 15:04:33 -0700 | |
commit | 937d11ae9bd5c36846389192d7475444abd663fb (patch) | |
tree | 0fb4f8b107332d7325bf506720211f1b513c46f3 /tensorflow/core/platform/cloud/gcs_file_system_test.cc | |
parent | 1ee41bd3280c07568a6f3edc5288a1f50a4d852d (diff) |
Safety check for cases when RenameFile tries to move a large object to a bucket with
a different location or storage class.
The situation when object.rewrite doesn't return done=true can occur when
1) the target bucket is in a different location or storage class
and
2) the object is relatively large
See comments for https://cloud.google.com/storage/docs/json_api/v1/objects/copy for details. This situations shouldn't happen in the TensorFlow scenarios, which typically
rename the object within the same bucket, but it's useful to have a safety
check with a meaningful failure message.
Change: 134004191
Diffstat (limited to 'tensorflow/core/platform/cloud/gcs_file_system_test.cc')
-rw-r--r-- | tensorflow/core/platform/cloud/gcs_file_system_test.cc | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/tensorflow/core/platform/cloud/gcs_file_system_test.cc b/tensorflow/core/platform/cloud/gcs_file_system_test.cc index 826bb1bfba..46e0a432f5 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system_test.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system_test.cc @@ -756,7 +756,7 @@ TEST(GcsFileSystemTest, RenameFile_Folder) { "path1%2F/rewriteTo/b/bucket/o/path2%2F\n" "Auth Token: fake_token\n" "Post: yes\n", - ""), + "{\"done\": true}"), // Deleting the original directory marker. new FakeHttpRequest( "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" @@ -771,7 +771,7 @@ TEST(GcsFileSystemTest, RenameFile_Folder) { "path2%2Fsubfolder%2Ffile1.txt\n" "Auth Token: fake_token\n" "Post: yes\n", - ""), + "{\"done\": true}"), // Deleting the first original file. new FakeHttpRequest( "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" @@ -785,7 +785,7 @@ TEST(GcsFileSystemTest, RenameFile_Folder) { "path1%2Ffile2.txt/rewriteTo/b/bucket/o/path2%2Ffile2.txt\n" "Auth Token: fake_token\n" "Post: yes\n", - ""), + "{\"done\": true}"), // Deleting the second original file. new FakeHttpRequest( "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" @@ -823,7 +823,7 @@ TEST(GcsFileSystemTest, RenameFile_Object) { "path%2Fsrc.txt/rewriteTo/b/bucket/o/path%2Fdst.txt\n" "Auth Token: fake_token\n" "Post: yes\n", - ""), + "{\"done\": true}"), // Deleting the original file. new FakeHttpRequest( "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" @@ -840,6 +840,41 @@ TEST(GcsFileSystemTest, RenameFile_Object) { fs.RenameFile("gs://bucket/path/src.txt", "gs://bucket/path/dst.txt")); } +/// Tests the case when rewrite couldn't complete in one RPC. +TEST(GcsFileSystemTest, RenameFile_Object_Incomplete) { + std::vector<HttpRequest*> requests( + {// IsDirectory is checking whether there are children objects. + new FakeHttpRequest( + "Uri: https://www.googleapis.com/storage/v1/b/bucket/o?" + "fields=items%2Fname%2CnextPageToken&prefix=path%2Fsrc.txt%2F" + "&maxResults=1\n" + "Auth Token: fake_token\n", + "{}"), + // IsDirectory is checking if the path exists as an object. + new FakeHttpRequest( + "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" + "path%2Fsrc.txt?fields=size%2Cupdated\n" + "Auth Token: fake_token\n", + strings::StrCat("{\"size\": \"1010\"," + "\"updated\": \"2016-04-29T23:15:24.896Z\"}")), + // Copying to the new location. + new FakeHttpRequest( + "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" + "path%2Fsrc.txt/rewriteTo/b/bucket/o/path%2Fdst.txt\n" + "Auth Token: fake_token\n" + "Post: yes\n", + "{\"done\": false}")}); + GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider), + std::unique_ptr<HttpRequest::Factory>( + new FakeHttpRequestFactory(&requests)), + 0 /* read ahead bytes */, 5 /* max upload attempts */); + + EXPECT_EQ( + errors::Code::UNIMPLEMENTED, + fs.RenameFile("gs://bucket/path/src.txt", "gs://bucket/path/dst.txt") + .code()); +} + TEST(GcsFileSystemTest, Stat_Object) { std::vector<HttpRequest*> requests({new FakeHttpRequest( "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/" |