| 52 | }; |
| 53 | |
| 54 | TEST(GcsFileSystemTest, NewRandomAccessFile_NoBlockCache) { |
| 55 | std::vector<HttpRequest*> requests( |
| 56 | {new FakeHttpRequest( |
| 57 | "Uri: https://storage.googleapis.com/bucket/random_access.txt\n" |
| 58 | "Auth Token: fake_token\n" |
| 59 | "Range: 0-5\n" |
| 60 | "Timeouts: 5 1 20\n", |
| 61 | "012345"), |
| 62 | new FakeHttpRequest( |
| 63 | "Uri: https://storage.googleapis.com/bucket/random_access.txt\n" |
| 64 | "Auth Token: fake_token\n" |
| 65 | "Range: 6-11\n" |
| 66 | "Timeouts: 5 1 20\n", |
| 67 | "6789")}); |
| 68 | GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider), |
| 69 | std::unique_ptr<HttpRequest::Factory>( |
| 70 | new FakeHttpRequestFactory(&requests)), |
| 71 | std::unique_ptr<ZoneProvider>(new FakeZoneProvider), |
| 72 | 0 /* block size */, 0 /* max bytes */, 0 /* max staleness */, |
| 73 | 0 /* stat cache max age */, 0 /* stat cache max entries */, |
| 74 | 0 /* matching paths cache max age */, |
| 75 | 0 /* matching paths cache max entries */, kTestRetryConfig, |
| 76 | kTestTimeoutConfig, *kAllowedLocationsDefault, |
| 77 | nullptr /* gcs additional header */); |
| 78 | |
| 79 | std::unique_ptr<RandomAccessFile> file; |
| 80 | TF_EXPECT_OK(fs.NewRandomAccessFile("gs://bucket/random_access.txt", &file)); |
| 81 | |
| 82 | StringPiece filename; |
| 83 | TF_EXPECT_OK(file->Name(&filename)); |
| 84 | EXPECT_EQ(filename, "gs://bucket/random_access.txt"); |
| 85 | |
| 86 | char scratch[6]; |
| 87 | StringPiece result; |
| 88 | |
| 89 | // Read the first chunk. |
| 90 | TF_EXPECT_OK(file->Read(0, sizeof(scratch), &result, scratch)); |
| 91 | EXPECT_EQ("012345", result); |
| 92 | |
| 93 | // Read the second chunk. |
| 94 | EXPECT_EQ( |
| 95 | errors::Code::OUT_OF_RANGE, |
| 96 | file->Read(sizeof(scratch), sizeof(scratch), &result, scratch).code()); |
| 97 | EXPECT_EQ("6789", result); |
| 98 | } |
| 99 | |
| 100 | TEST(GcsFileSystemTest, NewRandomAccessFile_Buffered) { |
| 101 | std::vector<HttpRequest*> requests({ |
nothing calls this directly
no test coverage detected