|
|
|
@ -18,10 +18,12 @@ |
|
|
|
|
#include "options/options_helper.h" |
|
|
|
|
#include "options/options_parser.h" |
|
|
|
|
#include "rocksdb/convenience.h" |
|
|
|
|
#include "rocksdb/flush_block_policy.h" |
|
|
|
|
#include "rocksdb/secondary_cache.h" |
|
|
|
|
#include "rocksdb/utilities/customizable_util.h" |
|
|
|
|
#include "rocksdb/utilities/object_registry.h" |
|
|
|
|
#include "rocksdb/utilities/options_type.h" |
|
|
|
|
#include "table/block_based/flush_block_policy.h" |
|
|
|
|
#include "table/mock_table.h" |
|
|
|
|
#include "test_util/testharness.h" |
|
|
|
|
#include "test_util/testutil.h" |
|
|
|
@ -56,7 +58,6 @@ class TestCustomizable : public Customizable { |
|
|
|
|
// Method to allow CheckedCast to work for this class
|
|
|
|
|
static const char* kClassName() { |
|
|
|
|
return "TestCustomizable"; |
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char* Name() const override { return name_.c_str(); } |
|
|
|
@ -873,8 +874,8 @@ TEST_F(CustomizableTest, MutableOptionsTest) { |
|
|
|
|
|
|
|
|
|
class TestSecondaryCache : public SecondaryCache { |
|
|
|
|
public: |
|
|
|
|
const char* Name() const override { return kClassName(); } |
|
|
|
|
static const char* kClassName() { return "Test"; } |
|
|
|
|
const char* Name() const override { return kClassName(); } |
|
|
|
|
Status Insert(const Slice& /*key*/, void* /*value*/, |
|
|
|
|
const Cache::CacheItemHelper* /*helper*/) override { |
|
|
|
|
return Status::NotSupported(); |
|
|
|
@ -916,10 +917,33 @@ static int RegisterTestObjects(ObjectLibrary& library, |
|
|
|
|
return static_cast<int>(library.GetFactoryCount(&num_types)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TestFlushBlockPolicyFactory : public FlushBlockPolicyFactory { |
|
|
|
|
public: |
|
|
|
|
TestFlushBlockPolicyFactory() {} |
|
|
|
|
|
|
|
|
|
static const char* kClassName() { return "TestFlushBlockPolicyFactory"; } |
|
|
|
|
const char* Name() const override { return kClassName(); } |
|
|
|
|
|
|
|
|
|
FlushBlockPolicy* NewFlushBlockPolicy( |
|
|
|
|
const BlockBasedTableOptions& /*table_options*/, |
|
|
|
|
const BlockBuilder& /*data_block_builder*/) const override { |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static int RegisterLocalObjects(ObjectLibrary& library, |
|
|
|
|
const std::string& /*arg*/) { |
|
|
|
|
size_t num_types; |
|
|
|
|
// Load any locally defined objects here
|
|
|
|
|
library.Register<FlushBlockPolicyFactory>( |
|
|
|
|
TestFlushBlockPolicyFactory::kClassName(), |
|
|
|
|
[](const std::string& /*uri*/, |
|
|
|
|
std::unique_ptr<FlushBlockPolicyFactory>* guard, |
|
|
|
|
std::string* /* errmsg */) { |
|
|
|
|
guard->reset(new TestFlushBlockPolicyFactory()); |
|
|
|
|
return guard->get(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
library.Register<SecondaryCache>( |
|
|
|
|
TestSecondaryCache::kClassName(), |
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<SecondaryCache>* guard, |
|
|
|
@ -954,6 +978,7 @@ class LoadCustomizableTest : public testing::Test { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
TEST_F(LoadCustomizableTest, LoadTableFactoryTest) { |
|
|
|
|
ColumnFamilyOptions cf_opts; |
|
|
|
|
std::shared_ptr<TableFactory> factory; |
|
|
|
|
ASSERT_NOK( |
|
|
|
|
TableFactory::CreateFromString(config_options_, "MockTable", &factory)); |
|
|
|
@ -961,12 +986,27 @@ TEST_F(LoadCustomizableTest, LoadTableFactoryTest) { |
|
|
|
|
config_options_, TableFactory::kBlockBasedTableName(), &factory)); |
|
|
|
|
ASSERT_NE(factory, nullptr); |
|
|
|
|
ASSERT_STREQ(factory->Name(), TableFactory::kBlockBasedTableName()); |
|
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE |
|
|
|
|
std::string opts_str = "table_factory="; |
|
|
|
|
ASSERT_OK(GetColumnFamilyOptionsFromString( |
|
|
|
|
config_options_, ColumnFamilyOptions(), |
|
|
|
|
opts_str + TableFactory::kBlockBasedTableName(), &cf_opts)); |
|
|
|
|
ASSERT_NE(cf_opts.table_factory.get(), nullptr); |
|
|
|
|
ASSERT_STREQ(cf_opts.table_factory->Name(), |
|
|
|
|
TableFactory::kBlockBasedTableName()); |
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
if (RegisterTests("Test")) { |
|
|
|
|
ASSERT_OK( |
|
|
|
|
TableFactory::CreateFromString(config_options_, "MockTable", &factory)); |
|
|
|
|
ASSERT_NE(factory, nullptr); |
|
|
|
|
ASSERT_STREQ(factory->Name(), "MockTable"); |
|
|
|
|
#ifndef ROCKSDB_LITE |
|
|
|
|
ASSERT_OK( |
|
|
|
|
GetColumnFamilyOptionsFromString(config_options_, ColumnFamilyOptions(), |
|
|
|
|
opts_str + "MockTable", &cf_opts)); |
|
|
|
|
ASSERT_NE(cf_opts.table_factory.get(), nullptr); |
|
|
|
|
ASSERT_STREQ(cf_opts.table_factory->Name(), "MockTable"); |
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1007,6 +1047,52 @@ TEST_F(LoadCustomizableTest, LoadComparatorTest) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(LoadCustomizableTest, LoadFlushBlockPolicyFactoryTest) { |
|
|
|
|
std::shared_ptr<TableFactory> table; |
|
|
|
|
std::shared_ptr<FlushBlockPolicyFactory> result; |
|
|
|
|
ASSERT_NOK(FlushBlockPolicyFactory::CreateFromString( |
|
|
|
|
config_options_, "TestFlushBlockPolicyFactory", &result)); |
|
|
|
|
|
|
|
|
|
ASSERT_OK( |
|
|
|
|
FlushBlockPolicyFactory::CreateFromString(config_options_, "", &result)); |
|
|
|
|
ASSERT_NE(result, nullptr); |
|
|
|
|
ASSERT_STREQ(result->Name(), FlushBlockBySizePolicyFactory::kClassName()); |
|
|
|
|
|
|
|
|
|
ASSERT_OK(FlushBlockPolicyFactory::CreateFromString( |
|
|
|
|
config_options_, FlushBlockEveryKeyPolicyFactory::kClassName(), &result)); |
|
|
|
|
ASSERT_NE(result, nullptr); |
|
|
|
|
ASSERT_STREQ(result->Name(), FlushBlockEveryKeyPolicyFactory::kClassName()); |
|
|
|
|
|
|
|
|
|
ASSERT_OK(FlushBlockPolicyFactory::CreateFromString( |
|
|
|
|
config_options_, FlushBlockBySizePolicyFactory::kClassName(), &result)); |
|
|
|
|
ASSERT_NE(result, nullptr); |
|
|
|
|
ASSERT_STREQ(result->Name(), FlushBlockBySizePolicyFactory::kClassName()); |
|
|
|
|
#ifndef ROCKSDB_LITE |
|
|
|
|
std::string table_opts = "id=BlockBasedTable; flush_block_policy_factory="; |
|
|
|
|
ASSERT_OK(TableFactory::CreateFromString( |
|
|
|
|
config_options_, |
|
|
|
|
table_opts + FlushBlockEveryKeyPolicyFactory::kClassName(), &table)); |
|
|
|
|
auto bbto = table->GetOptions<BlockBasedTableOptions>(); |
|
|
|
|
ASSERT_NE(bbto, nullptr); |
|
|
|
|
ASSERT_NE(bbto->flush_block_policy_factory.get(), nullptr); |
|
|
|
|
ASSERT_STREQ(bbto->flush_block_policy_factory->Name(), |
|
|
|
|
FlushBlockEveryKeyPolicyFactory::kClassName()); |
|
|
|
|
if (RegisterTests("Test")) { |
|
|
|
|
ASSERT_OK(FlushBlockPolicyFactory::CreateFromString( |
|
|
|
|
config_options_, "TestFlushBlockPolicyFactory", &result)); |
|
|
|
|
ASSERT_NE(result, nullptr); |
|
|
|
|
ASSERT_STREQ(result->Name(), "TestFlushBlockPolicyFactory"); |
|
|
|
|
ASSERT_OK(TableFactory::CreateFromString( |
|
|
|
|
config_options_, table_opts + "TestFlushBlockPolicyFactory", &table)); |
|
|
|
|
bbto = table->GetOptions<BlockBasedTableOptions>(); |
|
|
|
|
ASSERT_NE(bbto, nullptr); |
|
|
|
|
ASSERT_NE(bbto->flush_block_policy_factory.get(), nullptr); |
|
|
|
|
ASSERT_STREQ(bbto->flush_block_policy_factory->Name(), |
|
|
|
|
"TestFlushBlockPolicyFactory"); |
|
|
|
|
} |
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
::testing::InitGoogleTest(&argc, argv); |
|
|
|
|