|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +#include <chrono> |
| 18 | +#include <cstdint> |
| 19 | +#include <future> |
| 20 | +#include <string> |
| 21 | +#include <unordered_set> |
| 22 | +#include <vector> |
| 23 | + |
17 | 24 | #include "gtest/gtest.h" |
18 | 25 | #include "paimon/fs/jindo/jindo_file_system_factory.h" |
19 | 26 | #include "paimon/testing/utils/testharness.h" |
| 27 | + |
20 | 28 | namespace paimon::jindo::test { |
| 29 | + |
21 | 30 | // This test shows inconsistent behavior with the local file system in some abnormal scenarios. |
22 | 31 | class JindoFileSystemTest : public ::testing::Test { |
23 | 32 | public: |
@@ -124,4 +133,73 @@ TEST_F(JindoFileSystemTest, TestSeek) { |
124 | 133 | ASSERT_OK(in_stream->Close()); |
125 | 134 | } |
126 | 135 |
|
| 136 | +TEST(JindoFileSystemPaginationTest, TestListDirAcrossOssPageBoundary) { |
| 137 | + constexpr int32_t kFileCount = 1234; |
| 138 | + const std::string test_dir = "oss://paimon-unittest/test_data/jindo_listdir_truncated_1234/"; |
| 139 | + std::map<std::string, std::string> options = paimon::test::GetJindoTestOptions(); |
| 140 | + |
| 141 | + auto fs_factory = std::make_shared<JindoFileSystemFactory>(); |
| 142 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<FileSystem> fs, fs_factory->Create(test_dir, options)); |
| 143 | + |
| 144 | + std::vector<std::unique_ptr<BasicFileStatus>> file_statuses; |
| 145 | + ASSERT_OK(fs->ListDir(test_dir, &file_statuses)); |
| 146 | + ASSERT_EQ(file_statuses.size(), kFileCount); |
| 147 | + |
| 148 | + std::unordered_set<std::string> actual_paths; |
| 149 | + for (const std::unique_ptr<BasicFileStatus>& file_status : file_statuses) { |
| 150 | + ASSERT_TRUE(actual_paths.insert(file_status->GetPath()).second) |
| 151 | + << "duplicate path: " << file_status->GetPath(); |
| 152 | + } |
| 153 | + for (int32_t i = 0; i < kFileCount; ++i) { |
| 154 | + std::string index = std::to_string(i); |
| 155 | + index.insert(/*pos=*/0, /*count=*/4 - index.size(), /*ch=*/'0'); |
| 156 | + ASSERT_NE(actual_paths.find(test_dir + "file-" + index + ".txt"), actual_paths.end()); |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +TEST(JindoFileSystemAsyncReadTest, TestConcurrentReadAsyncAndReadFromOss) { |
| 161 | + constexpr int32_t kConcurrentReads = 64; |
| 162 | + constexpr int64_t kAsyncReadSize = 7; |
| 163 | + const std::string file_path = "oss://paimon-unittest/test_data/jindo_read_async_128mb.bin"; |
| 164 | + std::map<std::string, std::string> options = paimon::test::GetJindoTestOptions(); |
| 165 | + auto fs_factory = std::make_shared<JindoFileSystemFactory>(); |
| 166 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<FileSystem> fs, fs_factory->Create(file_path, options)); |
| 167 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<InputStream> input_stream, fs->Open(file_path)); |
| 168 | + |
| 169 | + std::vector<std::vector<char>> async_buffers(kConcurrentReads, |
| 170 | + std::vector<char>(kAsyncReadSize)); |
| 171 | + std::vector<std::promise<Status>> promises(kConcurrentReads); |
| 172 | + std::vector<std::future<Status>> futures; |
| 173 | + futures.reserve(kConcurrentReads); |
| 174 | + for (std::promise<Status>& promise : promises) { |
| 175 | + futures.push_back(promise.get_future()); |
| 176 | + } |
| 177 | + |
| 178 | + std::vector<Status> sync_read_statuses; |
| 179 | + std::vector<int64_t> sync_read_sizes; |
| 180 | + sync_read_statuses.reserve(kConcurrentReads); |
| 181 | + sync_read_sizes.reserve(kConcurrentReads); |
| 182 | + for (int32_t i = 0; i < kConcurrentReads; ++i) { |
| 183 | + input_stream->ReadAsync( |
| 184 | + async_buffers[i].data(), async_buffers[i].size(), /*offset=*/0, |
| 185 | + [&promises, i](Status status) { promises[i].set_value(std::move(status)); }); |
| 186 | + |
| 187 | + char sync_buffer = 0; |
| 188 | + Result<int64_t> sync_read_result = |
| 189 | + input_stream->Read(&sync_buffer, /*size=*/1, /*offset=*/i); |
| 190 | + sync_read_statuses.push_back(sync_read_result.status()); |
| 191 | + sync_read_sizes.push_back(sync_read_result.ok() ? sync_read_result.value() : -1); |
| 192 | + } |
| 193 | + |
| 194 | + for (int32_t i = 0; i < kConcurrentReads; ++i) { |
| 195 | + ASSERT_EQ(futures[i].wait_for(std::chrono::seconds(60)), std::future_status::ready) |
| 196 | + << "async read=" << i; |
| 197 | + ASSERT_OK(futures[i].get()); |
| 198 | + } |
| 199 | + for (int32_t i = 0; i < kConcurrentReads; ++i) { |
| 200 | + ASSERT_OK(sync_read_statuses[i]) << "sync read=" << i; |
| 201 | + ASSERT_EQ(sync_read_sizes[i], 1) << "sync read=" << i; |
| 202 | + } |
| 203 | +} |
| 204 | + |
127 | 205 | } // namespace paimon::jindo::test |
0 commit comments