-
Notifications
You must be signed in to change notification settings - Fork 69
refactor: Restructure catalog module #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |||||||
|
|
||||||||
| iceberg_install_all_headers(iceberg/catalog) | ||||||||
|
|
||||||||
| add_subdirectory(memory) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| if(ICEBERG_BUILD_REST) | ||||||||
| add_subdirectory(rest) | ||||||||
| endif() | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| iceberg_install_all_headers(iceberg/catalog/memory) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,23 @@ | |
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| fetchcontent_declare(cpp-httplib | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @WillAyd Do you have any comment?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming this is in the context of Meson then no - this package is available in the wrapdb so it's easy to integrate |
||
| GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git | ||
| GIT_TAG 89c932f313c6437c38f2982869beacc89c2f2246 #release-0.26.0 | ||
| ) | ||
|
|
||
| fetchcontent_declare(googletest | ||
| GIT_REPOSITORY https://github.com/google/googletest.git | ||
| GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2 | ||
| FIND_PACKAGE_ARGS | ||
| NAMES | ||
| GTest) | ||
| fetchcontent_makeavailable(googletest) | ||
|
|
||
| if(ICEBERG_BUILD_REST) | ||
| fetchcontent_makeavailable(cpp-httplib googletest) | ||
| else() | ||
| fetchcontent_makeavailable(googletest) | ||
| endif() | ||
|
|
||
| set(ICEBERG_TEST_RESOURCES "${CMAKE_SOURCE_DIR}/src/iceberg/test/resources") | ||
|
|
||
|
|
@@ -136,3 +146,9 @@ if(ICEBERG_BUILD_BUNDLE) | |
| add_iceberg_test(scan_test USE_BUNDLE SOURCES file_scan_task_test.cc) | ||
|
|
||
| endif() | ||
|
|
||
| if(ICEBERG_BUILD_REST) | ||
| add_iceberg_test(rest_catalog_test SOURCES rest_catalog_test.cc) | ||
| target_link_libraries(rest_catalog_test PRIVATE iceberg_rest_static) | ||
| target_include_directories(rest_catalog_test PRIVATE ${cpp-httplib_SOURCE_DIR}) | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include "iceberg/catalog/rest/rest_catalog.h" | ||
|
|
||
| #include <httplib.h> | ||
|
|
||
| #include <memory> | ||
| #include <thread> | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
| #include <nlohmann/json.hpp> | ||
HeartLinked marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace iceberg::catalog::rest { | ||
|
|
||
| class RestCatalogIntegrationTest : public ::testing::Test { | ||
| protected: | ||
| void SetUp() override { | ||
| server_ = std::make_unique<httplib::Server>(); | ||
| port_ = server_->bind_to_any_port("127.0.0.1"); | ||
|
|
||
| server_thread_ = std::thread([this]() { server_->listen_after_bind(); }); | ||
| } | ||
|
|
||
| void TearDown() override { | ||
| server_->stop(); | ||
| if (server_thread_.joinable()) { | ||
| server_thread_.join(); | ||
| } | ||
| } | ||
|
|
||
| std::unique_ptr<httplib::Server> server_; | ||
| int port_ = -1; | ||
| std::thread server_thread_; | ||
| }; | ||
|
|
||
| TEST_F(RestCatalogIntegrationTest, GetConfigSuccessfully) { | ||
| server_->Get("/v1/config", [](const httplib::Request&, httplib::Response& res) { | ||
| res.status = 200; | ||
| res.set_content(R"({"warehouse": "s3://test-bucket"})", "application/json"); | ||
| }); | ||
|
|
||
| std::string base_uri = "http://127.0.0.1:" + std::to_string(port_); | ||
| RestCatalog catalog(base_uri); | ||
| cpr::Response response = catalog.GetConfig(); | ||
|
|
||
| ASSERT_EQ(response.error.code, cpr::ErrorCode::OK); | ||
| ASSERT_EQ(response.status_code, 200); | ||
|
|
||
| auto json_body = nlohmann::json::parse(response.text); | ||
| EXPECT_EQ(json_body["warehouse"], "s3://test-bucket"); | ||
| } | ||
|
|
||
| TEST_F(RestCatalogIntegrationTest, ListNamespacesReturnsMultipleResults) { | ||
| server_->Get("/v1/namespaces", [](const httplib::Request&, httplib::Response& res) { | ||
| res.status = 200; | ||
| res.set_content(R"({ | ||
| "namespaces": [ | ||
| ["accounting", "db"], | ||
| ["production", "db"] | ||
| ] | ||
| })", | ||
| "application/json"); | ||
| }); | ||
|
|
||
| std::string base_uri = "http://127.0.0.1:" + std::to_string(port_); | ||
| RestCatalog catalog(base_uri); | ||
| cpr::Response response = catalog.ListNamespaces(); | ||
|
|
||
| ASSERT_EQ(response.error.code, cpr::ErrorCode::OK); | ||
| ASSERT_EQ(response.status_code, 200); | ||
|
|
||
| auto json_body = nlohmann::json::parse(response.text); | ||
| ASSERT_TRUE(json_body.contains("namespaces")); | ||
| EXPECT_EQ(json_body["namespaces"].size(), 2); | ||
| EXPECT_THAT(json_body["namespaces"][0][0], "accounting"); | ||
| } | ||
|
|
||
| TEST_F(RestCatalogIntegrationTest, HandlesServerError) { | ||
| server_->Get("/v1/config", [](const httplib::Request&, httplib::Response& res) { | ||
| res.status = 500; | ||
| res.set_content("Internal Server Error", "text/plain"); | ||
| }); | ||
|
|
||
| std::string base_uri = "http://127.0.0.1:" + std::to_string(port_); | ||
| RestCatalog catalog(base_uri); | ||
| cpr::Response response = catalog.GetConfig(); | ||
|
|
||
| ASSERT_EQ(response.error.code, cpr::ErrorCode::OK); | ||
| ASSERT_EQ(response.status_code, 500); | ||
| ASSERT_EQ(response.text, "Internal Server Error"); | ||
| } | ||
|
|
||
| } // namespace iceberg::catalog::rest | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI since the in_memory_catalog.h header was moved, this no longer installs anything. Maybe worth removing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!