Skip to content

Commit

Permalink
Fix UT build with serialization disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunrd0 committed Jan 28, 2025
1 parent 608ffd6 commit f6f85d6
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 63 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ if (TILEDB_SERIALIZATION)
src/unit-capi-serialized_queries.cc
src/unit-QueryCondition-serialization.cc
src/unit-curl.cc
src/unit-rest-client-remote.cc
)
endif()

Expand Down
63 changes: 0 additions & 63 deletions test/src/unit-ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@

#include <test/support/tdb_catch.h>
#include "test/support/src/helpers.h"
#include "test/support/src/vfs_helpers.h"
#include "tiledb/api/c_api/context/context_api_internal.h"
#include "tiledb/sm/c_api/tiledb_struct_def.h"
#include "tiledb/sm/cpp_api/tiledb"
#include "tiledb/sm/rest/rest_client_remote.h"

#include <cstring>
#include <iostream>
Expand Down Expand Up @@ -105,64 +103,3 @@ TEST_CASE("C++ API: Test context tags", "[cppapi][ctx-tags]") {
}
}
}

TEST_CASE("REST capabilities endpoint", "[rest][version]") {
tiledb::test::VFSTestSetup vfs_test_setup;
if (vfs_test_setup.is_rest()) {
tiledb::Config config;
std::string serialization_format = GENERATE("JSON", "CAPNP");
config["rest.server_serialization_format"] = serialization_format;

auto expected_version =
std::make_from_tuple<tiledb::sm::RestCapabilities::TileDBVersion>(
tiledb::version());
tiledb::common::ThreadPool tp(1);
DYNAMIC_SECTION(
"GET request to retrieve REST tiledb version - "
<< serialization_format) {
auto rest_client = tiledb::sm::RestClientRemote(
tiledb::test::g_helper_stats,
config.ptr()->config(),
tp,
*tiledb::test::g_helper_logger(),
tiledb::test::get_test_memory_tracker());
tiledb::sm::RestCapabilities expected_capabilities(
expected_version,
{expected_version.major_,
expected_version.minor_ - 1,
expected_version.patch_});
// Check on construction the capabilities are not initialized.
REQUIRE(!rest_client.rest_capabilities_detected());
auto actual_capabilities = rest_client.get_capabilities_from_rest();
// GET request above initializes RestCapabilities and contents are valid.
REQUIRE(expected_capabilities == actual_capabilities);
REQUIRE(rest_client.rest_capabilities_detected());
}
DYNAMIC_SECTION(
"Initialization of rest_tiledb_version_ on first access - "
<< serialization_format) {
// Construct enabled Stats for this test to verify http request count.
auto stats = tiledb::sm::stats::Stats("capabilities_stats");
auto rest_client = tiledb::sm::RestClientRemote(
stats,
config.ptr()->config(),
tp,
*tiledb::test::g_helper_logger(),
tiledb::test::get_test_memory_tracker());
// Here we don't call `get_capabilities_from_rest`, but instead attempt to
// first access RestCapabilities directly. The RestClient should submit
// the GET request and initialize RestCapabilities, returning the result.
REQUIRE(!rest_client.rest_capabilities_detected());
REQUIRE(rest_client.rest_tiledb_version() == expected_version);
auto match_request_count = Catch::Matchers::ContainsSubstring(
"\"capabilities_stats.RestClient.rest_http_requests\": 1");
REQUIRE_THAT(stats.dump(0, 0), match_request_count);

// After the access above, RestCapabilities has been initialized.
// Subsequent access attempts should not submit any additional requests.
REQUIRE(rest_client.rest_capabilities_detected());
REQUIRE(rest_client.rest_tiledb_version() == expected_version);
REQUIRE_THAT(stats.dump(0, 0), match_request_count);
}
}
}
98 changes: 98 additions & 0 deletions test/src/unit-rest-client-remote.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @file unit-rest-client-remote.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2025 TileDB Inc.
* @copyright Copyright (c) 2016 MIT and Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* Tests for RestClientRemote class. This class and the tests in this file are
* only compiled when TILEDB_SERIALIZATION is enabled.
*/

#include <test/support/tdb_catch.h>
#include "test/support/src/vfs_helpers.h"
#include "tiledb/sm/rest/rest_client_remote.h"

TEST_CASE("REST capabilities endpoint", "[rest][version]") {
tiledb::test::VFSTestSetup vfs_test_setup;
if (vfs_test_setup.is_rest()) {
tiledb::Config config;
std::string serialization_format = GENERATE("JSON", "CAPNP");
config["rest.server_serialization_format"] = serialization_format;

auto expected_version =
std::make_from_tuple<tiledb::sm::RestCapabilities::TileDBVersion>(
tiledb::version());
tiledb::common::ThreadPool tp(1);
DYNAMIC_SECTION(
"GET request to retrieve REST tiledb version - "
<< serialization_format) {
auto rest_client = tiledb::sm::RestClientRemote(
tiledb::test::g_helper_stats,
config.ptr()->config(),
tp,
*tiledb::test::g_helper_logger(),
tiledb::test::get_test_memory_tracker());
tiledb::sm::RestCapabilities expected_capabilities(
expected_version,
{expected_version.major_,
expected_version.minor_ - 1,
expected_version.patch_});
// Check on construction the capabilities are not initialized.
REQUIRE(!rest_client.rest_capabilities_detected());
auto actual_capabilities = rest_client.get_capabilities_from_rest();
// GET request above initializes RestCapabilities and contents are valid.
REQUIRE(expected_capabilities == actual_capabilities);
REQUIRE(rest_client.rest_capabilities_detected());
}
DYNAMIC_SECTION(
"Initialization of rest_tiledb_version_ on first access - "
<< serialization_format) {
// Construct enabled Stats for this test to verify http request count.
auto stats = tiledb::sm::stats::Stats("capabilities_stats");
auto rest_client = tiledb::sm::RestClientRemote(
stats,
config.ptr()->config(),
tp,
*tiledb::test::g_helper_logger(),
tiledb::test::get_test_memory_tracker());
// Here we don't call `get_capabilities_from_rest`, but instead attempt to
// first access RestCapabilities directly. The RestClient should submit
// the GET request and initialize RestCapabilities, returning the result.
REQUIRE(!rest_client.rest_capabilities_detected());
REQUIRE(rest_client.rest_tiledb_version() == expected_version);
auto match_request_count = Catch::Matchers::ContainsSubstring(
"\"capabilities_stats.RestClient.rest_http_requests\": 1");
REQUIRE_THAT(stats.dump(0, 0), match_request_count);

// After the access above, RestCapabilities has been initialized.
// Subsequent access attempts should not submit any additional requests.
REQUIRE(rest_client.rest_capabilities_detected());
REQUIRE(rest_client.rest_tiledb_version() == expected_version);
REQUIRE_THAT(stats.dump(0, 0), match_request_count);
}
}
}

0 comments on commit f6f85d6

Please sign in to comment.