|
17 | 17 |
|
18 | 18 | #include "recycler/s3_accessor.h"
|
19 | 19 |
|
| 20 | +#include <aws/s3/S3Client.h> |
20 | 21 | #include <aws/s3/model/ListObjectsV2Request.h>
|
21 | 22 | #include <butil/guid.h>
|
| 23 | +#include <gen_cpp/cloud.pb.h> |
22 | 24 | #include <gtest/gtest.h>
|
23 | 25 |
|
24 | 26 | #include <azure/storage/blobs/blob_options.hpp>
|
@@ -320,4 +322,70 @@ TEST(S3AccessorTest, gcs) {
|
320 | 322 | test_s3_accessor(*accessor);
|
321 | 323 | }
|
322 | 324 |
|
| 325 | +TEST(S3AccessorTest, path_style_test) { |
| 326 | + ObjectStoreInfoPB obj_info; |
| 327 | + obj_info.set_prefix("doris-debug-instance-prefix"); |
| 328 | + obj_info.set_provider(ObjectStoreInfoPB_Provider_S3); |
| 329 | + obj_info.set_ak("dummy_ak"); |
| 330 | + obj_info.set_sk("dummy_sk"); |
| 331 | + obj_info.set_endpoint("dummy-bucket"); |
| 332 | + obj_info.set_region("cn-north-1"); |
| 333 | + obj_info.set_bucket("dummy-bucket"); |
| 334 | + config::max_s3_client_retry = 0; |
| 335 | + |
| 336 | + auto* sp = SyncPoint::get_instance(); |
| 337 | + sp->enable_processing(); |
| 338 | + std::vector<SyncPoint::CallbackGuard> guards; |
| 339 | + |
| 340 | + std::string base_domain = "s3.cn-north-1.amazonaws.com.cn"; |
| 341 | + std::string domain_ip = "54.222.51.71"; // first ip of base_domain |
| 342 | + // to test custom_domain, add ${domain_ip} ${custom_domain} to /etc/hosts |
| 343 | + // otherwise the related cases will fail |
| 344 | + std::string custom_domain = "gavin.s3.aws.com"; |
| 345 | + // clang-format off |
| 346 | + // http code 403 means there is nothing wrong the given domain in objinfo |
| 347 | + // domain, use_path_style, http_code |
| 348 | + std::vector<std::tuple<std::string, bool, int>> inputs { |
| 349 | + {base_domain , false , 403}, // works |
| 350 | + {base_domain , true , 403}, // works |
| 351 | + {"http://" + base_domain , false , 403}, // works |
| 352 | + {"http://" + base_domain , true , 403}, // works |
| 353 | + {"https://" + base_domain , false , 403}, // works |
| 354 | + {"https://" + base_domain , true , 403}, // works |
| 355 | + {"http://" + domain_ip , false , 301}, // works, ip with virtual addressing |
| 356 | + {"http://" + domain_ip , true , 301}, // works, ip with path style |
| 357 | + {custom_domain , false , -1} , // custom_domain could not resolve with virtual addressing |
| 358 | + {custom_domain , true , 403}, // custom_domain working with path style |
| 359 | + {"http://" + custom_domain , false , -1} , // custom_domain could not resolve with virtual addressing |
| 360 | + {"https://" + custom_domain, true , -1}, // certificate issue, custom_domain does not attached with any certs |
| 361 | + // {"https://54.222.51.71" , false , -1} , // certificate issue |
| 362 | + // {"https://54.222.51.71" , true , -1} , // certificate issue |
| 363 | + }; |
| 364 | + |
| 365 | + int case_idx = 0; |
| 366 | + sp->set_call_back("S3ObjClient::delete_object", |
| 367 | + [&case_idx, &inputs](auto&& args) { |
| 368 | + auto* res = try_any_cast<Aws::S3::Model::DeleteObjectOutcome*>(args[0]); |
| 369 | + EXPECT_EQ(std::get<2>(inputs[case_idx]), static_cast<int>(res->GetError().GetResponseCode())) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx; |
| 370 | + case_idx++; |
| 371 | + }, |
| 372 | + &guards.emplace_back()); |
| 373 | + // clang-format on |
| 374 | + |
| 375 | + for (auto& i : inputs) { |
| 376 | + obj_info.set_endpoint(std::get<0>(i)); |
| 377 | + obj_info.set_use_path_style(std::get<1>(i)); |
| 378 | + auto s3_conf = S3Conf::from_obj_store_info(obj_info); |
| 379 | + EXPECT_EQ(s3_conf->use_virtual_addressing, !obj_info.use_path_style()) << case_idx; |
| 380 | + std::shared_ptr<S3Accessor> accessor; |
| 381 | + int ret = S3Accessor::create(*s3_conf, &accessor); |
| 382 | + EXPECT_EQ(ret, 0) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx; |
| 383 | + ret = accessor->init(); |
| 384 | + EXPECT_EQ(ret, 0) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx; |
| 385 | + // this function call will trigger syncpoint callback to increment case_idx |
| 386 | + accessor->delete_file("abc"); // try to delete a nonexisted file, ignore the result |
| 387 | + // EXPECT_EQ(ret, exp) << "<<<<<<<<<<<<<<<<<<<<< " << case_idx << " domain " << std::get<0>(i); |
| 388 | + } |
| 389 | +} |
| 390 | + |
323 | 391 | } // namespace doris::cloud
|
0 commit comments