2016-06-03 17:15:16 +02:00
|
|
|
// Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2016-06-03 17:15:16 +02:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2017-01-26 00:54:09 +01:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
2016-06-03 17:15:16 +02:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
class EnvRegistryTest : public testing::Test {
|
|
|
|
public:
|
|
|
|
static int num_a, num_b;
|
|
|
|
};
|
|
|
|
|
|
|
|
int EnvRegistryTest::num_a = 0;
|
|
|
|
int EnvRegistryTest::num_b = 0;
|
|
|
|
|
2018-03-05 22:08:17 +01:00
|
|
|
static Registrar<Env> test_reg_a("a://.*",
|
|
|
|
[](const std::string& /*uri*/,
|
|
|
|
std::unique_ptr<Env>* /*env_guard*/) {
|
|
|
|
++EnvRegistryTest::num_a;
|
|
|
|
return Env::Default();
|
|
|
|
});
|
2016-06-03 17:15:16 +02:00
|
|
|
|
2018-03-05 22:08:17 +01:00
|
|
|
static Registrar<Env> test_reg_b("b://.*", [](const std::string& /*uri*/,
|
2017-01-26 00:54:09 +01:00
|
|
|
std::unique_ptr<Env>* env_guard) {
|
2016-06-03 17:15:16 +02:00
|
|
|
++EnvRegistryTest::num_b;
|
|
|
|
// Env::Default() is a singleton so we can't grant ownership directly to the
|
|
|
|
// caller - we must wrap it first.
|
|
|
|
env_guard->reset(new EnvWrapper(Env::Default()));
|
|
|
|
return env_guard->get();
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST_F(EnvRegistryTest, Basics) {
|
|
|
|
std::unique_ptr<Env> env_guard;
|
2017-01-26 00:54:09 +01:00
|
|
|
auto res = NewCustomObject<Env>("a://test", &env_guard);
|
2016-06-03 17:15:16 +02:00
|
|
|
ASSERT_NE(res, nullptr);
|
|
|
|
ASSERT_EQ(env_guard, nullptr);
|
|
|
|
ASSERT_EQ(1, num_a);
|
|
|
|
ASSERT_EQ(0, num_b);
|
|
|
|
|
2017-01-26 00:54:09 +01:00
|
|
|
res = NewCustomObject<Env>("b://test", &env_guard);
|
2016-06-03 17:15:16 +02:00
|
|
|
ASSERT_NE(res, nullptr);
|
|
|
|
ASSERT_NE(env_guard, nullptr);
|
|
|
|
ASSERT_EQ(1, num_a);
|
|
|
|
ASSERT_EQ(1, num_b);
|
|
|
|
|
2017-01-26 00:54:09 +01:00
|
|
|
res = NewCustomObject<Env>("c://test", &env_guard);
|
2016-06-03 17:15:16 +02:00
|
|
|
ASSERT_EQ(res, nullptr);
|
|
|
|
ASSERT_EQ(env_guard, nullptr);
|
|
|
|
ASSERT_EQ(1, num_a);
|
|
|
|
ASSERT_EQ(1, num_b);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // ROCKSDB_LITE
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-04-16 02:19:57 +02:00
|
|
|
int main(int /*argc*/, char** /*argv*/) {
|
2016-06-03 17:15:16 +02:00
|
|
|
fprintf(stderr, "SKIPPED as EnvRegistry is not supported in ROCKSDB_LITE\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|