@ -13,8 +13,11 @@
# include <cinttypes>
# include <cinttypes>
# include <cstring>
# include <cstring>
# include <unordered_map>
# include <unordered_map>
# include <unordered_set>
# include "db/db_test_util.h"
# include "db/db_test_util.h"
# include "memory/jemalloc_nodump_allocator.h"
# include "memory/memkind_kmem_allocator.h"
# include "options/options_helper.h"
# include "options/options_helper.h"
# include "options/options_parser.h"
# include "options/options_parser.h"
# include "port/stack_trace.h"
# include "port/stack_trace.h"
@ -1655,6 +1658,190 @@ class LoadCustomizableTest : public testing::Test {
# endif // !ROCKSDB_LITE
# endif // !ROCKSDB_LITE
}
}
template < typename T , typename U >
Status TestCreateStatic ( const std : : string & name , U * * result ,
bool delete_result = false ) {
Status s = T : : CreateFromString ( config_options_ , name , result ) ;
if ( s . ok ( ) ) {
EXPECT_NE ( * result , nullptr ) ;
EXPECT_TRUE ( * result ! = nullptr & & ( * result ) - > IsInstanceOf ( name ) ) ;
}
if ( delete_result ) {
delete * result ;
* result = nullptr ;
}
return s ;
}
template < typename T , typename U >
std : : shared_ptr < U > ExpectCreateShared ( const std : : string & name ,
std : : shared_ptr < U > * object ) {
EXPECT_OK ( T : : CreateFromString ( config_options_ , name , object ) ) ;
EXPECT_NE ( object - > get ( ) , nullptr ) ;
EXPECT_TRUE ( object - > get ( ) - > IsInstanceOf ( name ) ) ;
return * object ;
}
template < typename T >
std : : shared_ptr < T > ExpectCreateShared ( const std : : string & name ) {
std : : shared_ptr < T > result ;
return ExpectCreateShared < T > ( name , & result ) ;
}
template < typename T , typename U >
Status TestExpectedBuiltins (
const std : : string & mock , const std : : unordered_set < std : : string > & expected ,
std : : shared_ptr < U > * object , std : : vector < std : : string > * failed ,
const std : : function < std : : vector < std : : string > ( const std : : string & ) > & alt =
nullptr ) {
std : : unordered_set < std : : string > factories = expected ;
Status s = T : : CreateFromString ( config_options_ , mock , object ) ;
EXPECT_NOK ( s ) ;
# ifndef ROCKSDB_LITE
std : : vector < std : : string > builtins ;
ObjectLibrary : : Default ( ) - > GetFactoryNames ( T : : Type ( ) , & builtins ) ;
factories . insert ( builtins . begin ( ) , builtins . end ( ) ) ;
# endif // ROCKSDB_LITE
Status result ;
int created = 0 ;
for ( const auto & name : factories ) {
created + + ;
s = T : : CreateFromString ( config_options_ , name , object ) ;
if ( ! s . ok ( ) & & alt ! = nullptr ) {
for ( const auto & alt_name : alt ( name ) ) {
s = T : : CreateFromString ( config_options_ , alt_name , object ) ;
if ( s . ok ( ) ) {
break ;
}
}
}
if ( ! s . ok ( ) ) {
result = s ;
failed - > push_back ( name ) ;
} else {
EXPECT_NE ( object - > get ( ) , nullptr ) ;
EXPECT_TRUE ( object - > get ( ) - > IsInstanceOf ( name ) ) ;
}
}
# ifndef ROCKSDB_LITE
std : : vector < std : : string > plugins ;
ObjectRegistry : : Default ( ) - > GetFactoryNames ( T : : Type ( ) , & plugins ) ;
if ( plugins . size ( ) > builtins . size ( ) ) {
for ( const auto & name : plugins ) {
if ( factories . find ( name ) = = factories . end ( ) ) {
created + + ;
s = T : : CreateFromString ( config_options_ , name , object ) ;
if ( ! s . ok ( ) & & alt ! = nullptr ) {
for ( const auto & alt_name : alt ( name ) ) {
s = T : : CreateFromString ( config_options_ , alt_name , object ) ;
if ( s . ok ( ) ) {
break ;
}
}
}
if ( ! s . ok ( ) ) {
failed - > push_back ( name ) ;
if ( result . ok ( ) ) {
result = s ;
}
printf ( " %s: Failed creating plugin[%s]: %s \n " , T : : Type ( ) ,
name . c_str ( ) , s . ToString ( ) . c_str ( ) ) ;
} else if ( object - > get ( ) = = nullptr | |
! object - > get ( ) - > IsInstanceOf ( name ) ) {
failed - > push_back ( name ) ;
printf ( " %s: Invalid plugin[%s] \n " , T : : Type ( ) , name . c_str ( ) ) ;
}
}
}
}
printf ( " %s: Created %d (expected+builtins+plugins %d+%d+%d) %d Failed \n " ,
T : : Type ( ) , created , ( int ) expected . size ( ) ,
( int ) ( factories . size ( ) - expected . size ( ) ) ,
( int ) ( plugins . size ( ) - builtins . size ( ) ) , ( int ) failed - > size ( ) ) ;
# else
printf ( " %s: Created %d (expected %d) %d Failed \n " , T : : Type ( ) , created ,
( int ) expected . size ( ) , ( int ) failed - > size ( ) ) ;
# endif // ROCKSDB_LITE
return result ;
}
template < typename T >
Status TestSharedBuiltins ( const std : : string & mock ,
const std : : string & expected ,
std : : vector < std : : string > * failed = nullptr ) {
std : : unordered_set < std : : string > values ;
if ( ! expected . empty ( ) ) {
values . insert ( expected ) ;
}
std : : shared_ptr < T > object ;
if ( failed ! = nullptr ) {
return TestExpectedBuiltins < T > ( mock , values , & object , failed ) ;
} else {
std : : vector < std : : string > failures ;
Status s = TestExpectedBuiltins < T > ( mock , values , & object , & failures ) ;
EXPECT_EQ ( 0U , failures . size ( ) ) ;
return s ;
}
}
template < typename T , typename U >
Status TestStaticBuiltins ( const std : : string & mock , U * * object ,
const std : : unordered_set < std : : string > & expected ,
std : : vector < std : : string > * failed ,
bool delete_objects = false ) {
std : : unordered_set < std : : string > factories = expected ;
Status s = TestCreateStatic < T > ( mock , object , delete_objects ) ;
EXPECT_NOK ( s ) ;
# ifndef ROCKSDB_LITE
std : : vector < std : : string > builtins ;
ObjectLibrary : : Default ( ) - > GetFactoryNames ( T : : Type ( ) , & builtins ) ;
factories . insert ( builtins . begin ( ) , builtins . end ( ) ) ;
# endif // ROCKSDB_LITE
int created = 0 ;
Status result ;
for ( const auto & name : factories ) {
created + + ;
s = TestCreateStatic < T > ( name , object , delete_objects ) ;
if ( ! s . ok ( ) ) {
result = s ;
failed - > push_back ( name ) ;
}
}
# ifndef ROCKSDB_LITE
std : : vector < std : : string > plugins ;
ObjectRegistry : : Default ( ) - > GetFactoryNames ( T : : Type ( ) , & plugins ) ;
if ( plugins . size ( ) > builtins . size ( ) ) {
for ( const auto & name : plugins ) {
if ( factories . find ( name ) = = factories . end ( ) ) {
created + + ;
s = T : : CreateFromString ( config_options_ , name , object ) ;
if ( ! s . ok ( ) | | * object = = nullptr | |
! ( ( * object ) - > IsInstanceOf ( name ) ) ) {
failed - > push_back ( name ) ;
if ( result . ok ( ) & & ! s . ok ( ) ) {
result = s ;
}
printf ( " %s: Failed creating plugin[%s]: %s \n " , T : : Type ( ) ,
name . c_str ( ) , s . ToString ( ) . c_str ( ) ) ;
}
if ( delete_objects ) {
delete * object ;
* object = nullptr ;
}
}
}
}
printf ( " %s: Created %d (expected+builtins+plugins %d+%d+%d) %d Failed \n " ,
T : : Type ( ) , created , ( int ) expected . size ( ) ,
( int ) ( factories . size ( ) - expected . size ( ) ) ,
( int ) ( plugins . size ( ) - builtins . size ( ) ) , ( int ) failed - > size ( ) ) ;
# else
printf ( " %s: Created %d (expected %d) %d Failed \n " , T : : Type ( ) , created ,
( int ) expected . size ( ) , ( int ) failed - > size ( ) ) ;
# endif // ROCKSDB_LITE
return result ;
}
protected :
protected :
DBOptions db_opts_ ;
DBOptions db_opts_ ;
ColumnFamilyOptions cf_opts_ ;
ColumnFamilyOptions cf_opts_ ;
@ -1662,13 +1849,9 @@ class LoadCustomizableTest : public testing::Test {
} ;
} ;
TEST_F ( LoadCustomizableTest , LoadTableFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadTableFactoryTest ) {
std : : shared_ptr < TableFactory > factory ;
ASSERT_OK (
ASSERT_NOK ( TableFactory : : CreateFromString (
TestSharedBuiltins < TableFactory > ( mock : : MockTableFactory : : kClassName ( ) ,
config_options_ , mock : : MockTableFactory : : kClassName ( ) , & factory ) ) ;
TableFactory : : kBlockBasedTableName ( ) ) ) ;
ASSERT_OK ( TableFactory : : CreateFromString (
config_options_ , TableFactory : : kBlockBasedTableName ( ) , & factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) , TableFactory : : kBlockBasedTableName ( ) ) ;
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
std : : string opts_str = " table_factory= " ;
std : : string opts_str = " table_factory= " ;
ASSERT_OK ( GetColumnFamilyOptionsFromString (
ASSERT_OK ( GetColumnFamilyOptionsFromString (
@ -1679,10 +1862,7 @@ TEST_F(LoadCustomizableTest, LoadTableFactoryTest) {
TableFactory : : kBlockBasedTableName ( ) ) ;
TableFactory : : kBlockBasedTableName ( ) ) ;
# endif // ROCKSDB_LITE
# endif // ROCKSDB_LITE
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( TableFactory : : CreateFromString (
ExpectCreateShared < TableFactory > ( mock : : MockTableFactory : : kClassName ( ) ) ;
config_options_ , mock : : MockTableFactory : : kClassName ( ) , & factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) , mock : : MockTableFactory : : kClassName ( ) ) ;
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
ASSERT_OK ( GetColumnFamilyOptionsFromString (
ASSERT_OK ( GetColumnFamilyOptionsFromString (
config_options_ , cf_opts_ ,
config_options_ , cf_opts_ ,
@ -1695,151 +1875,97 @@ TEST_F(LoadCustomizableTest, LoadTableFactoryTest) {
}
}
TEST_F ( LoadCustomizableTest , LoadFileSystemTest ) {
TEST_F ( LoadCustomizableTest , LoadFileSystemTest ) {
ColumnFamilyOptions cf_opts ;
ASSERT_OK ( TestSharedBuiltins < FileSystem > ( DummyFileSystem : : kClassName ( ) ,
std : : shared_ptr < FileSystem > result ;
FileSystem : : kDefaultName ( ) ) ) ;
ASSERT_NOK ( FileSystem : : CreateFromString (
config_options_ , DummyFileSystem : : kClassName ( ) , & result ) ) ;
ASSERT_OK ( FileSystem : : CreateFromString ( config_options_ ,
FileSystem : : kDefaultName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( FileSystem : : kDefaultName ( ) ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( FileSystem : : CreateFromString (
auto fs = ExpectCreateShared < FileSystem > ( DummyFileSystem : : kClassName ( ) ) ;
config_options_ , DummyFileSystem : : kClassName ( ) , & result ) ) ;
ASSERT_FALSE ( fs - > IsInstanceOf ( FileSystem : : kDefaultName ( ) ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , DummyFileSystem : : kClassName ( ) ) ;
ASSERT_FALSE ( result - > IsInstanceOf ( FileSystem : : kDefaultName ( ) ) ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadSecondaryCacheTest ) {
TEST_F ( LoadCustomizableTest , LoadSecondaryCacheTest ) {
std : : shared_ptr < SecondaryCache > result ;
ASSERT_OK (
ASSERT_NOK ( SecondaryCache : : CreateFromString (
TestSharedBuiltins < SecondaryCache > ( TestSecondaryCache : : kClassName ( ) , " " ) ) ;
config_options_ , TestSecondaryCache : : kClassName ( ) , & result ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( SecondaryCache : : CreateFromString (
ExpectCreateShared < SecondaryCache > ( TestSecondaryCache : : kClassName ( ) ) ;
config_options_ , TestSecondaryCache : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , TestSecondaryCache : : kClassName ( ) ) ;
}
}
}
}
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
TEST_F ( LoadCustomizableTest , LoadSstPartitionerFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadSstPartitionerFactoryTest ) {
std : : shared_ptr < SstPartitionerFactory > factory ;
ASSERT_OK ( TestSharedBuiltins < SstPartitionerFactory > (
ASSERT_NOK ( SstPartitionerFactory : : CreateFromString ( config_options_ , " Mock " ,
" Mock " , SstPartitionerFixedPrefixFactory : : kClassName ( ) ) ) ;
& factory ) ) ;
ASSERT_OK ( SstPartitionerFactory : : CreateFromString (
config_options_ , SstPartitionerFixedPrefixFactory : : kClassName ( ) ,
& factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) , SstPartitionerFixedPrefixFactory : : kClassName ( ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( SstPartitionerFactory : : CreateFromString ( config_options_ , " Mock " ,
ExpectCreateShared < SstPartitionerFactory > ( " Mock " ) ;
& factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) , " Mock " ) ;
}
}
}
}
# endif // ROCKSDB_LITE
# endif // ROCKSDB_LITE
TEST_F ( LoadCustomizableTest , LoadChecksumGenFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadChecksumGenFactoryTest ) {
std : : shared_ptr < FileChecksumGenFactory > factory ;
ASSERT_OK ( TestSharedBuiltins < FileChecksumGenFactory > ( " Mock " , " " ) ) ;
ASSERT_NOK ( FileChecksumGenFactory : : CreateFromString ( config_options_ , " Mock " ,
& factory ) ) ;
ASSERT_OK ( FileChecksumGenFactory : : CreateFromString (
config_options_ , FileChecksumGenCrc32cFactory : : kClassName ( ) , & factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) , FileChecksumGenCrc32cFactory : : kClassName ( ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( FileChecksumGenFactory : : CreateFromString ( config_options_ , " Mock " ,
ExpectCreateShared < FileChecksumGenFactory > ( " Mock " ) ;
& factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) , " Mock " ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadTablePropertiesCollectorFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadTablePropertiesCollectorFactoryTest ) {
std : : shared_ptr < TablePropertiesCollectorFactory > factory ;
ASSERT_OK ( TestSharedBuiltins < TablePropertiesCollectorFactory > (
ASSERT_NOK ( TablePropertiesCollectorFactory : : CreateFromString (
MockTablePropertiesCollectorFactory : : kClassName ( ) , " " ) ) ;
config_options_ , MockTablePropertiesCollectorFactory : : kClassName ( ) ,
& factory ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( TablePropertiesCollectorFactory : : CreateFromString (
ExpectCreateShared < TablePropertiesCollectorFactory > (
config_options_ , MockTablePropertiesCollectorFactory : : kClassName ( ) ,
MockTablePropertiesCollectorFactory : : kClassName ( ) ) ;
& factory ) ) ;
ASSERT_NE ( factory , nullptr ) ;
ASSERT_STREQ ( factory - > Name ( ) ,
MockTablePropertiesCollectorFactory : : kClassName ( ) ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadComparatorTest ) {
TEST_F ( LoadCustomizableTest , LoadComparatorTest ) {
const Comparator * bytewise = BytewiseComparator ( ) ;
const Comparator * bytewise = BytewiseComparator ( ) ;
const Comparator * reverse = ReverseBytewiseComparator ( ) ;
const Comparator * reverse = ReverseBytewiseComparator ( ) ;
const Comparator * result = nullptr ;
const Comparator * result = nullptr ;
ASSERT_NOK ( Comparator : : CreateFromString (
std : : unordered_set < std : : string > expected = { bytewise - > Name ( ) ,
config_options_ , test : : SimpleSuffixReverseComparator : : kClassName ( ) ,
reverse - > Name ( ) } ;
& result ) ) ;
std : : vector < std : : string > failures ;
ASSERT_OK (
ASSERT_OK ( TestStaticBuiltins < Comparator > (
Comparator : : CreateFromString ( config_options_ , bytewise - > Name ( ) , & result ) ) ;
test : : SimpleSuffixReverseComparator : : kClassName ( ) , & result , expected ,
ASSERT_EQ ( result , bytewise ) ;
& failures ) ) ;
ASSERT_OK (
Comparator : : CreateFromString ( config_options_ , reverse - > Name ( ) , & result ) ) ;
ASSERT_EQ ( result , reverse ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( Comparator : : CreateFromString (
ASSERT_OK ( TestCreateStatic < Comparator > (
config_options_ , test : : SimpleSuffixReverseComparator : : kClassName ( ) ,
test : : SimpleSuffixReverseComparator : : kClassName ( ) , & result ) ) ;
& result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) ,
test : : SimpleSuffixReverseComparator : : kClassName ( ) ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadSliceTransformFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadSliceTransformFactoryTest ) {
std : : shared_ptr < const SliceTransform > result ;
std : : shared_ptr < const SliceTransform > result ;
ASSERT_NOK (
std : : vector < std : : string > failures ;
SliceTransform : : CreateFromString ( config_options_ , " Mock " , & result ) ) ;
std : : unordered_set < std : : string > expected = { " rocksdb.Noop " , " fixed " ,
ASSERT_OK (
" rocksdb.FixedPrefix " , " capped " ,
SliceTransform : : CreateFromString ( config_options_ , " fixed:16 " , & result ) ) ;
" rocksdb.CappedPrefix " } ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_OK ( TestExpectedBuiltins < SliceTransform > (
ASSERT_TRUE ( result - > IsInstanceOf ( " fixed " ) ) ;
" Mock " , expected , & result , & failures , [ ] ( const std : : string & name ) {
std : : vector < std : : string > names = { name + " :22 " , name + " .22 " } ;
return names ;
} ) ) ;
ASSERT_OK ( SliceTransform : : CreateFromString (
ASSERT_OK ( SliceTransform : : CreateFromString (
config_options_ , " rocksdb.FixedPrefix.22 " , & result ) ) ;
config_options_ , " rocksdb.FixedPrefix.22 " , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( " fixed " ) ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( " fixed " ) ) ;
ASSERT_OK (
SliceTransform : : CreateFromString ( config_options_ , " capped:16 " , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( " capped " ) ) ;
ASSERT_OK ( SliceTransform : : CreateFromString (
ASSERT_OK ( SliceTransform : : CreateFromString (
config_options_ , " rocksdb.CappedPrefix.11 " , & result ) ) ;
config_options_ , " rocksdb.CappedPrefix.22 " , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( " capped " ) ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( " capped " ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK (
ExpectCreateShared < SliceTransform > ( " Mock " , & result ) ;
SliceTransform : : CreateFromString ( config_options_ , " Mock " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " Mock " ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadStatisticsTest ) {
TEST_F ( LoadCustomizableTest , LoadStatisticsTest ) {
std : : shared_ptr < Statistics > stats ;
ASSERT_OK ( TestSharedBuiltins < Statistics > ( TestStatistics : : kClassName ( ) ,
ASSERT_NOK ( Statistics : : CreateFromString (
" BasicStatistics " ) ) ;
config_options_ , TestStatistics : : kClassName ( ) , & stats ) ) ;
// Empty will create a default BasicStatistics
ASSERT_OK (
ASSERT_OK (
Statistics : : CreateFromString ( config_options_ , " BasicStatistics " , & stats ) ) ;
Statistics : : CreateFromString ( config_options_ , " " , & db_opts_ . statistics ) ) ;
ASSERT_NE ( stats , nullptr ) ;
ASSERT_NE ( db_opts_ . statistics , nullptr ) ;
ASSERT_EQ ( stats - > Name ( ) , std : : string ( " BasicStatistics " ) ) ;
ASSERT_STREQ ( db_opts_ . statistics - > Name ( ) , " BasicStatistics " ) ;
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
ASSERT_NOK ( GetDBOptionsFromString ( config_options_ , db_opts_ ,
ASSERT_NOK ( GetDBOptionsFromString ( config_options_ , db_opts_ ,
" statistics=Test " , & db_opts_ ) ) ;
" statistics=Test " , & db_opts_ ) ) ;
@ -1849,10 +1975,7 @@ TEST_F(LoadCustomizableTest, LoadStatisticsTest) {
ASSERT_STREQ ( db_opts_ . statistics - > Name ( ) , " BasicStatistics " ) ;
ASSERT_STREQ ( db_opts_ . statistics - > Name ( ) , " BasicStatistics " ) ;
if ( RegisterTests ( " test " ) ) {
if ( RegisterTests ( " test " ) ) {
ASSERT_OK ( Statistics : : CreateFromString (
auto stats = ExpectCreateShared < Statistics > ( TestStatistics : : kClassName ( ) ) ;
config_options_ , TestStatistics : : kClassName ( ) , & stats ) ) ;
ASSERT_NE ( stats , nullptr ) ;
ASSERT_STREQ ( stats - > Name ( ) , TestStatistics : : kClassName ( ) ) ;
ASSERT_OK ( GetDBOptionsFromString ( config_options_ , db_opts_ ,
ASSERT_OK ( GetDBOptionsFromString ( config_options_ , db_opts_ ,
" statistics=Test " , & db_opts_ ) ) ;
" statistics=Test " , & db_opts_ ) ) ;
@ -1883,167 +2006,90 @@ TEST_F(LoadCustomizableTest, LoadStatisticsTest) {
}
}
TEST_F ( LoadCustomizableTest , LoadMemTableRepFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadMemTableRepFactoryTest ) {
std : : unique_ptr < MemTableRepFactory > result ;
std : : unordered_set < std : : string > expected = {
ASSERT_NOK ( MemTableRepFactory : : CreateFromString (
SkipListFactory : : kClassName ( ) ,
config_options_ , " SpecialSkipListFactory " , & result ) ) ;
SkipListFactory : : kNickName ( ) ,
ASSERT_OK ( MemTableRepFactory : : CreateFromString (
} ;
config_options_ , SkipListFactory : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( SkipListFactory : : kClassName ( ) ) ) ;
std : : vector < std : : string > failures ;
std : : shared_ptr < MemTableRepFactory > factory ;
Status s = TestExpectedBuiltins < MemTableRepFactory > (
" SpecialSkipListFactory " , expected , & factory , & failures ) ;
// There is a "cuckoo" factory registered that we expect to fail. Ignore the
// error if this is the one
if ( s . ok ( ) | | failures . size ( ) > 1 | | failures [ 0 ] ! = " cuckoo " ) {
ASSERT_OK ( s ) ;
}
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( MemTableRepFactory : : CreateFromString (
ExpectCreateShared < MemTableRepFactory > ( " SpecialSkipListFactory " ) ;
config_options_ , " SpecialSkipListFactory " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " SpecialSkipListFactory " ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadMergeOperatorTest ) {
TEST_F ( LoadCustomizableTest , LoadMergeOperatorTest ) {
std : : shared_ptr < MergeOperator > result ;
std : : shared_ptr < MergeOperator > result ;
std : : vector < std : : string > failed ;
ASSERT_NOK (
std : : unordered_set < std : : string > expected = {
MergeOperator : : CreateFromString ( config_options_ , " Changling " , & result ) ) ;
" put " , " put_v1 " , " PutOperator " , " uint64add " , " UInt64AddOperator " ,
//**TODO: MJR: Use the constants when these names are in public classes
" max " , " MaxOperator " ,
ASSERT_OK ( MergeOperator : : CreateFromString ( config_options_ , " put " , & result ) ) ;
} ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " PutOperator " ) ;
ASSERT_OK (
MergeOperator : : CreateFromString ( config_options_ , " PutOperator " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " PutOperator " ) ;
ASSERT_OK (
MergeOperator : : CreateFromString ( config_options_ , " put_v1 " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " PutOperator " ) ;
ASSERT_OK (
MergeOperator : : CreateFromString ( config_options_ , " uint64add " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " UInt64AddOperator " ) ;
ASSERT_OK ( MergeOperator : : CreateFromString ( config_options_ ,
" UInt64AddOperator " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " UInt64AddOperator " ) ;
ASSERT_OK ( MergeOperator : : CreateFromString ( config_options_ , " max " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " MaxOperator " ) ;
ASSERT_OK (
MergeOperator : : CreateFromString ( config_options_ , " MaxOperator " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " MaxOperator " ) ;
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
ASSERT_OK ( MergeOperator : : CreateFromString (
expected . insert ( {
config_options_ , StringAppendOperator : : kNickName ( ) , & result ) ) ;
StringAppendOperator : : kClassName ( ) ,
ASSERT_NE ( result , nullptr ) ;
StringAppendOperator : : kNickName ( ) ,
ASSERT_STREQ ( result - > Name ( ) , StringAppendOperator : : kClassName ( ) ) ;
StringAppendTESTOperator : : kClassName ( ) ,
ASSERT_OK ( MergeOperator : : CreateFromString (
StringAppendTESTOperator : : kNickName ( ) ,
config_options_ , StringAppendOperator : : kClassName ( ) , & result ) ) ;
SortList : : kClassName ( ) ,
ASSERT_NE ( result , nullptr ) ;
SortList : : kNickName ( ) ,
ASSERT_STREQ ( result - > Name ( ) , StringAppendOperator : : kClassName ( ) ) ;
BytesXOROperator : : kClassName ( ) ,
BytesXOROperator : : kNickName ( ) ,
ASSERT_OK ( MergeOperator : : CreateFromString (
} ) ;
config_options_ , StringAppendTESTOperator : : kNickName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , StringAppendTESTOperator : : kClassName ( ) ) ;
ASSERT_OK ( MergeOperator : : CreateFromString (
config_options_ , StringAppendTESTOperator : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , StringAppendTESTOperator : : kClassName ( ) ) ;
ASSERT_OK ( MergeOperator : : CreateFromString ( config_options_ ,
SortList : : kNickName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , SortList : : kClassName ( ) ) ;
ASSERT_OK ( MergeOperator : : CreateFromString ( config_options_ ,
SortList : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , SortList : : kClassName ( ) ) ;
ASSERT_OK ( MergeOperator : : CreateFromString (
config_options_ , BytesXOROperator : : kNickName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , BytesXOROperator : : kClassName ( ) ) ;
ASSERT_OK ( MergeOperator : : CreateFromString (
config_options_ , BytesXOROperator : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , BytesXOROperator : : kClassName ( ) ) ;
# endif // ROCKSDB_LITE
# endif // ROCKSDB_LITE
ASSERT_NOK (
MergeOperator : : CreateFromString ( config_options_ , " Changling " , & result ) ) ;
ASSERT_OK ( TestExpectedBuiltins < MergeOperator > ( " Changling " , expected , & result ,
& failed ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK (
ExpectCreateShared < MergeOperator > ( " Changling " ) ;
MergeOperator : : CreateFromString ( config_options_ , " Changling " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " ChanglingMergeOperator " ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadCompactionFilterFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadCompactionFilterFactoryTest ) {
std : : shared_ptr < CompactionFilterFactory > result ;
ASSERT_OK ( TestSharedBuiltins < CompactionFilterFactory > ( " Changling " , " " ) ) ;
ASSERT_NOK ( CompactionFilterFactory : : CreateFromString ( config_options_ ,
" Changling " , & result ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( CompactionFilterFactory : : CreateFromString ( config_options_ ,
ExpectCreateShared < CompactionFilterFactory > ( " Changling " ) ;
" Changling " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " ChanglingCompactionFilterFactory " ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadCompactionFilterTest ) {
TEST_F ( LoadCustomizableTest , LoadCompactionFilterTest ) {
const CompactionFilter * result = nullptr ;
const CompactionFilter * result = nullptr ;
std : : vector < std : : string > failures ;
ASSERT_NOK ( CompactionFilter : : CreateFromString ( config_options_ , " Changling " ,
ASSERT_OK ( TestStaticBuiltins < CompactionFilter > ( " Changling " , & result , { } ,
& result ) ) ;
& failures , true ) ) ;
# ifndef ROCKSDB_LITE
ASSERT_OK ( CompactionFilter : : CreateFromString (
config_options_ , RemoveEmptyValueCompactionFilter : : kClassName ( ) ,
& result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , RemoveEmptyValueCompactionFilter : : kClassName ( ) ) ;
delete result ;
result = nullptr ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( CompactionFilter : : CreateFromString ( config_options_ , " Changling " ,
ASSERT_OK ( TestCreateStatic < CompactionFilter > ( " Changling " , & result , true ) ) ;
& result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " ChanglingCompactionFilter " ) ;
delete result ;
}
}
# endif // ROCKSDB_LITE
}
}
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
TEST_F ( LoadCustomizableTest , LoadEventListenerTest ) {
TEST_F ( LoadCustomizableTest , LoadEventListenerTest ) {
std : : shared_ptr < EventListener > result ;
ASSERT_OK ( TestSharedBuiltins < EventListener > (
OnFileDeletionListener : : kClassName ( ) , " " ) ) ;
ASSERT_NOK ( EventListener : : CreateFromString (
config_options_ , OnFileDeletionListener : : kClassName ( ) , & result ) ) ;
ASSERT_NOK ( EventListener : : CreateFromString (
config_options_ , FlushCounterListener : : kClassName ( ) , & result ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( EventListener : : CreateFromString (
ExpectCreateShared < EventListener > ( OnFileDeletionListener : : kClassName ( ) ) ;
config_options_ , OnFileDeletionListener : : kClassName ( ) , & result ) ) ;
ExpectCreateShared < EventListener > ( FlushCounterListener : : kClassName ( ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , OnFileDeletionListener : : kClassName ( ) ) ;
ASSERT_OK ( EventListener : : CreateFromString (
config_options_ , FlushCounterListener : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , FlushCounterListener : : kClassName ( ) ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadEncryptionProviderTest ) {
TEST_F ( LoadCustomizableTest , LoadEncryptionProviderTest ) {
std : : vector < std : : string > failures ;
std : : shared_ptr < EncryptionProvider > result ;
std : : shared_ptr < EncryptionProvider > result ;
ASSERT_NOK (
EncryptionProvider : : CreateFromString ( config_options_ , " Mock " , & result ) ) ;
ASSERT_OK (
ASSERT_OK (
EncryptionProvider : : CreateFromString ( config_options_ , " CTR " , & result ) ) ;
TestExpectedBuiltins < EncryptionProvider > ( " Mock " , { } , & result , & failures ) ) ;
ASSERT_NE ( result , nullptr ) ;
if ( ! failures . empty ( ) ) {
ASSERT_STREQ ( result - > Name ( ) , " CTR " ) ;
ASSERT_EQ ( failures [ 0 ] , " 1://test " ) ;
ASSERT_EQ ( failures . size ( ) , 1U ) ;
}
result = ExpectCreateShared < EncryptionProvider > ( " CTR " ) ;
ASSERT_NOK ( result - > ValidateOptions ( db_opts_ , cf_opts_ ) ) ;
ASSERT_NOK ( result - > ValidateOptions ( db_opts_ , cf_opts_ ) ) ;
ASSERT_OK ( EncryptionProvider : : CreateFromString ( config_options_ , " CTR://test " ,
ASSERT_OK ( EncryptionProvider : : CreateFromString ( config_options_ , " CTR://test " ,
& result ) ) ;
& result ) ) ;
@ -2052,10 +2098,7 @@ TEST_F(LoadCustomizableTest, LoadEncryptionProviderTest) {
ASSERT_OK ( result - > ValidateOptions ( db_opts_ , cf_opts_ ) ) ;
ASSERT_OK ( result - > ValidateOptions ( db_opts_ , cf_opts_ ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK (
ExpectCreateShared < EncryptionProvider > ( " Mock " ) ;
EncryptionProvider : : CreateFromString ( config_options_ , " Mock " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " Mock " ) ;
ASSERT_OK ( EncryptionProvider : : CreateFromString ( config_options_ ,
ASSERT_OK ( EncryptionProvider : : CreateFromString ( config_options_ ,
" Mock://test " , & result ) ) ;
" Mock://test " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_NE ( result , nullptr ) ;
@ -2065,72 +2108,69 @@ TEST_F(LoadCustomizableTest, LoadEncryptionProviderTest) {
}
}
TEST_F ( LoadCustomizableTest , LoadEncryptionCipherTest ) {
TEST_F ( LoadCustomizableTest , LoadEncryptionCipherTest ) {
std : : shared_ptr < BlockCipher > result ;
ASSERT_OK ( TestSharedBuiltins < BlockCipher > ( " Mock " , " ROT13 " ) ) ;
ASSERT_NOK ( BlockCipher : : CreateFromString ( config_options_ , " Mock " , & result ) ) ;
ASSERT_OK ( BlockCipher : : CreateFromString ( config_options_ , " ROT13 " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " ROT13 " ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( BlockCipher : : CreateFromString ( config_options_ , " Mock " , & result ) ) ;
ExpectCreateShared < BlockCipher > ( " Mock " ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , " Mock " ) ;
}
}
}
}
# endif // !ROCKSDB_LITE
# endif // !ROCKSDB_LITE
TEST_F ( LoadCustomizableTest , LoadSystemClockTest ) {
TEST_F ( LoadCustomizableTest , LoadSystemClockTest ) {
std : : shared_ptr < SystemClock > result ;
ASSERT_OK ( TestSharedBuiltins < SystemClock > ( MockSystemClock : : kClassName ( ) ,
ASSERT_NOK ( SystemClock : : CreateFromString (
SystemClock : : kDefaultName ( ) ) ) ;
config_options_ , MockSystemClock : : kClassName ( ) , & result ) ) ;
ASSERT_OK ( SystemClock : : CreateFromString (
config_options_ , SystemClock : : kDefaultName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( SystemClock : : kDefaultName ( ) ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( SystemClock : : CreateFromString (
auto result =
config_options_ , MockSystemClock : : kClassName ( ) , & result ) ) ;
ExpectCreateShared < SystemClock > ( MockSystemClock : : kClassName ( ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_FALSE ( result - > IsInstanceOf ( SystemClock : : kDefaultName ( ) ) ) ;
ASSERT_STREQ ( result - > Name ( ) , MockSystemClock : : kClassName ( ) ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadMemoryAllocatorTest ) {
TEST_F ( LoadCustomizableTest , LoadMemoryAllocatorTest ) {
std : : shared_ptr < MemoryAllocator > result ;
std : : vector < std : : string > failures ;
ASSERT_NOK ( MemoryAllocator : : CreateFromString (
Status s = TestSharedBuiltins < MemoryAllocator > (
config_options_ , MockMemoryAllocator : : kClassName ( ) , & result ) ) ;
MockMemoryAllocator : : kClassName ( ) , DefaultMemoryAllocator : : kClassName ( ) ,
ASSERT_OK ( MemoryAllocator : : CreateFromString (
& failures ) ;
config_options_ , DefaultMemoryAllocator : : kClassName ( ) , & result ) ) ;
if ( failures . empty ( ) ) {
ASSERT_NE ( result , nullptr ) ;
ASSERT_OK ( s ) ;
ASSERT_STREQ ( result - > Name ( ) , DefaultMemoryAllocator : : kClassName ( ) ) ;
} else {
ASSERT_NOK ( s ) ;
for ( const auto & failure : failures ) {
if ( failure = = JemallocNodumpAllocator : : kClassName ( ) ) {
ASSERT_FALSE ( JemallocNodumpAllocator : : IsSupported ( ) ) ;
} else if ( failure = = MemkindKmemAllocator : : kClassName ( ) ) {
ASSERT_FALSE ( MemkindKmemAllocator : : IsSupported ( ) ) ;
} else {
printf ( " BYPASSED: %s -- %s \n " , failure . c_str ( ) , s . ToString ( ) . c_str ( ) ) ;
}
}
}
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( MemoryAllocator : : CreateFromString (
ExpectCreateShared < MemoryAllocator > ( MockMemoryAllocator : : kClassName ( ) ) ;
config_options_ , MockMemoryAllocator : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , MockMemoryAllocator : : kClassName ( ) ) ;
}
}
}
}
TEST_F ( LoadCustomizableTest , LoadRateLimiterTest ) {
TEST_F ( LoadCustomizableTest , LoadRateLimiterTest ) {
# ifndef ROCKSDB_LITE
ASSERT_OK ( TestSharedBuiltins < RateLimiter > ( MockRateLimiter : : kClassName ( ) ,
GenericRateLimiter : : kClassName ( ) ) ) ;
# else
ASSERT_OK ( TestSharedBuiltins < RateLimiter > ( MockRateLimiter : : kClassName ( ) , " " ) ) ;
# endif // ROCKSDB_LITE
std : : shared_ptr < RateLimiter > result ;
std : : shared_ptr < RateLimiter > result ;
ASSERT_NOK ( RateLimiter : : CreateFromString (
config_options_ , MockRateLimiter : : kClassName ( ) , & result ) ) ;
ASSERT_OK ( RateLimiter : : CreateFromString (
ASSERT_OK ( RateLimiter : : CreateFromString (
config_options_ , std : : string ( GenericRateLimiter : : kClassName ( ) ) + " :1234 " ,
config_options_ , std : : string ( GenericRateLimiter : : kClassName ( ) ) + " :1234 " ,
& result ) ) ;
& result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( GenericRateLimiter : : kClassName ( ) ) ) ;
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
ASSERT_OK ( RateLimiter : : CreateFromString (
config_options_ , GenericRateLimiter : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_OK ( GetDBOptionsFromString (
ASSERT_OK ( GetDBOptionsFromString (
config_options_ , db_opts_ ,
config_options_ , db_opts_ ,
std : : string ( " rate_limiter= " ) + GenericRateLimiter : : kClassName ( ) ,
std : : string ( " rate_limiter= " ) + GenericRateLimiter : : kClassName ( ) ,
& db_opts_ ) ) ;
& db_opts_ ) ) ;
ASSERT_NE ( db_opts_ . rate_limiter , nullptr ) ;
ASSERT_NE ( db_opts_ . rate_limiter , nullptr ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( RateLimiter : : CreateFromString (
ExpectCreateShared < RateLimiter > ( MockRateLimiter : : kClassName ( ) ) ;
config_options_ , MockRateLimiter : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_OK ( GetDBOptionsFromString (
ASSERT_OK ( GetDBOptionsFromString (
config_options_ , db_opts_ ,
config_options_ , db_opts_ ,
std : : string ( " rate_limiter= " ) + MockRateLimiter : : kClassName ( ) ,
std : : string ( " rate_limiter= " ) + MockRateLimiter : : kClassName ( ) ,
@ -2141,17 +2181,52 @@ TEST_F(LoadCustomizableTest, LoadRateLimiterTest) {
}
}
TEST_F ( LoadCustomizableTest , LoadFilterPolicyTest ) {
TEST_F ( LoadCustomizableTest , LoadFilterPolicyTest ) {
std : : shared_ptr < TableFactory > table ;
const std : : string kAutoBloom = BloomFilterPolicy : : kClassName ( ) ;
const std : : string kAutoRibbon = RibbonFilterPolicy : : kClassName ( ) ;
std : : shared_ptr < const FilterPolicy > result ;
std : : shared_ptr < const FilterPolicy > result ;
ASSERT_NOK ( FilterPolicy : : CreateFromString (
std : : vector < std : : string > failures ;
config_options_ , MockFilterPolicy : : kClassName ( ) , & result ) ) ;
std : : unordered_set < std : : string > expected = {
ReadOnlyBuiltinFilterPolicy : : kClassName ( ) ,
} ;
ASSERT_OK ( FilterPolicy : : CreateFromString ( config_options_ , " " , & result ) ) ;
# ifndef ROCKSDB_LITE
ASSERT_EQ ( result , nullptr ) ;
expected . insert ( {
kAutoBloom ,
BloomFilterPolicy : : kNickName ( ) ,
kAutoRibbon ,
RibbonFilterPolicy : : kNickName ( ) ,
} ) ;
# endif // ROCKSDB_LITE
ASSERT_OK ( TestExpectedBuiltins < const FilterPolicy > (
" Mock " , expected , & result , & failures , [ ] ( const std : : string & name ) {
std : : vector < std : : string > names = { name + " :1.234 " } ;
return names ;
} ) ) ;
# ifndef ROCKSDB_LITE
ASSERT_OK ( FilterPolicy : : CreateFromString (
ASSERT_OK ( FilterPolicy : : CreateFromString (
config_options_ , ReadOnlyBuiltinFilterPolicy : : kClassName ( ) , & result ) ) ;
config_options_ , kAutoBloom + " :1.234:false " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , ReadOnlyBuiltinFilterPolicy : : kClassName ( ) ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( kAutoBloom ) ) ;
ASSERT_OK ( FilterPolicy : : CreateFromString (
config_options_ , kAutoBloom + " :1.234:false " , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( kAutoBloom ) ) ;
ASSERT_OK ( FilterPolicy : : CreateFromString ( config_options_ ,
kAutoRibbon + " :1.234:-1 " , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( kAutoRibbon ) ) ;
ASSERT_OK ( FilterPolicy : : CreateFromString ( config_options_ ,
kAutoRibbon + " :1.234:56 " , & result ) ) ;
ASSERT_NE ( result . get ( ) , nullptr ) ;
ASSERT_TRUE ( result - > IsInstanceOf ( kAutoRibbon ) ) ;
# endif // ROCKSDB_LITE
if ( RegisterTests ( " Test " ) ) {
ExpectCreateShared < FilterPolicy > ( MockFilterPolicy : : kClassName ( ) , & result ) ;
}
std : : shared_ptr < TableFactory > table ;
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
std : : string table_opts = " id=BlockBasedTable; filter_policy= " ;
std : : string table_opts = " id=BlockBasedTable; filter_policy= " ;
@ -2173,42 +2248,30 @@ TEST_F(LoadCustomizableTest, LoadFilterPolicyTest) {
config_options_ , table_opts + MockFilterPolicy : : kClassName ( ) , & table ) ) ;
config_options_ , table_opts + MockFilterPolicy : : kClassName ( ) , & table ) ) ;
bbto = table - > GetOptions < BlockBasedTableOptions > ( ) ;
bbto = table - > GetOptions < BlockBasedTableOptions > ( ) ;
ASSERT_NE ( bbto , nullptr ) ;
ASSERT_NE ( bbto , nullptr ) ;
ASSERT_EQ ( bbto - > filter_policy . get ( ) , nullptr ) ;
ASSERT_NE ( bbto - > filter_policy . get ( ) , nullptr ) ;
if ( RegisterTests ( " Test " ) ) {
ASSERT_TRUE (
ASSERT_OK ( FilterPolicy : : CreateFromString (
bbto - > filter_policy - > IsInstanceOf ( MockFilterPolicy : : kClassName ( ) ) ) ;
config_options_ , MockFilterPolicy : : kClassName ( ) , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , MockFilterPolicy : : kClassName ( ) ) ;
ASSERT_OK ( TableFactory : : CreateFromString (
config_options_ , table_opts + MockFilterPolicy : : kClassName ( ) , & table ) ) ;
bbto = table - > GetOptions < BlockBasedTableOptions > ( ) ;
ASSERT_NE ( bbto , nullptr ) ;
ASSERT_NE ( bbto - > filter_policy . get ( ) , nullptr ) ;
ASSERT_STREQ ( bbto - > filter_policy - > Name ( ) , MockFilterPolicy : : kClassName ( ) ) ;
}
# endif // ROCKSDB_LITE
# endif // ROCKSDB_LITE
}
}
TEST_F ( LoadCustomizableTest , LoadFlushBlockPolicyFactoryTest ) {
TEST_F ( LoadCustomizableTest , LoadFlushBlockPolicyFactoryTest ) {
std : : shared_ptr < TableFactory > table ;
std : : shared_ptr < FlushBlockPolicyFactory > result ;
std : : shared_ptr < FlushBlockPolicyFactory > result ;
ASSERT_NOK ( FlushBlockPolicyFactory : : CreateFromString (
std : : shared_ptr < TableFactory > table ;
config_options_ , TestFlushBlockPolicyFactory : : kClassName ( ) , & result ) ) ;
std : : vector < std : : string > failed ;
std : : unordered_set < std : : string > expected = {
FlushBlockBySizePolicyFactory : : kClassName ( ) ,
FlushBlockEveryKeyPolicyFactory : : kClassName ( ) ,
} ;
ASSERT_OK ( TestExpectedBuiltins < FlushBlockPolicyFactory > (
TestFlushBlockPolicyFactory : : kClassName ( ) , expected , & result , & failed ) ) ;
// An empty policy name creates a BySize policy
ASSERT_OK (
ASSERT_OK (
FlushBlockPolicyFactory : : CreateFromString ( config_options_ , " " , & result ) ) ;
FlushBlockPolicyFactory : : CreateFromString ( config_options_ , " " , & result ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , FlushBlockBySizePolicyFactory : : kClassName ( ) ) ;
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
# ifndef ROCKSDB_LITE
std : : string table_opts = " id=BlockBasedTable; flush_block_policy_factory= " ;
std : : string table_opts = " id=BlockBasedTable; flush_block_policy_factory= " ;
ASSERT_OK ( TableFactory : : CreateFromString (
ASSERT_OK ( TableFactory : : CreateFromString (
@ -2220,10 +2283,8 @@ TEST_F(LoadCustomizableTest, LoadFlushBlockPolicyFactoryTest) {
ASSERT_STREQ ( bbto - > flush_block_policy_factory - > Name ( ) ,
ASSERT_STREQ ( bbto - > flush_block_policy_factory - > Name ( ) ,
FlushBlockEveryKeyPolicyFactory : : kClassName ( ) ) ;
FlushBlockEveryKeyPolicyFactory : : kClassName ( ) ) ;
if ( RegisterTests ( " Test " ) ) {
if ( RegisterTests ( " Test " ) ) {
ASSERT_OK ( FlushBlockPolicyFactory : : CreateFromString (
ExpectCreateShared < FlushBlockPolicyFactory > (
config_options_ , TestFlushBlockPolicyFactory : : kClassName ( ) , & result ) ) ;
TestFlushBlockPolicyFactory : : kClassName ( ) ) ;
ASSERT_NE ( result , nullptr ) ;
ASSERT_STREQ ( result - > Name ( ) , TestFlushBlockPolicyFactory : : kClassName ( ) ) ;
ASSERT_OK ( TableFactory : : CreateFromString (
ASSERT_OK ( TableFactory : : CreateFromString (
config_options_ , table_opts + TestFlushBlockPolicyFactory : : kClassName ( ) ,
config_options_ , table_opts + TestFlushBlockPolicyFactory : : kClassName ( ) ,
& table ) ) ;
& table ) ) ;