@ -7,6 +7,7 @@
# include "rocksdb/utilities/object_registry.h"
# include "rocksdb/utilities/object_registry.h"
# include "rocksdb/convenience.h"
# include "rocksdb/customizable.h"
# include "rocksdb/customizable.h"
# include "test_util/testharness.h"
# include "test_util/testharness.h"
@ -117,23 +118,25 @@ TEST_F(ObjRegistryTest, LocalRegistry) {
ASSERT_NE ( env , nullptr ) ;
ASSERT_NE ( env , nullptr ) ;
}
}
TEST_F ( ObjRegistryTest , CheckShared ) {
static int RegisterTestUnguarded ( ObjectLibrary & library ,
std : : shared_ptr < Env > shared ;
const std : : string & /*arg*/ ) {
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
library . AddFactory < Env > (
std : : shared_ptr < ObjectLibrary > library =
std : : make_shared < ObjectLibrary > ( " shared " ) ;
registry - > AddLibrary ( library ) ;
library - > AddFactory < Env > (
" unguarded " ,
" unguarded " ,
[ ] ( const std : : string & /*uri*/ , std : : unique_ptr < Env > * /*guard */ ,
[ ] ( const std : : string & /*uri*/ , std : : unique_ptr < Env > * /*guard */ ,
std : : string * /* errmsg */ ) { return Env : : Default ( ) ; } ) ;
std : : string * /* errmsg */ ) { return Env : : Default ( ) ; } ) ;
library . AddFactory < Env > (
library - > AddFactory < Env > (
" guarded " , [ ] ( const std : : string & uri , std : : unique_ptr < Env > * guard ,
" guarded " , [ ] ( const std : : string & uri , std : : unique_ptr < Env > * guard ,
std : : string * /* errmsg */ ) {
std : : string * /* errmsg */ ) {
guard - > reset ( new WrappedEnv ( Env : : Default ( ) , uri ) ) ;
guard - > reset ( new WrappedEnv ( Env : : Default ( ) , uri ) ) ;
return guard - > get ( ) ;
return guard - > get ( ) ;
} ) ;
} ) ;
return 2 ;
}
TEST_F ( ObjRegistryTest , CheckShared ) {
std : : shared_ptr < Env > shared ;
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
registry - > AddLibrary ( " shared " , RegisterTestUnguarded , " " ) ;
ASSERT_OK ( registry - > NewSharedObject < Env > ( " guarded " , & shared ) ) ;
ASSERT_OK ( registry - > NewSharedObject < Env > ( " guarded " , & shared ) ) ;
ASSERT_NE ( shared , nullptr ) ;
ASSERT_NE ( shared , nullptr ) ;
@ -145,20 +148,7 @@ TEST_F(ObjRegistryTest, CheckShared) {
TEST_F ( ObjRegistryTest , CheckStatic ) {
TEST_F ( ObjRegistryTest , CheckStatic ) {
Env * env = nullptr ;
Env * env = nullptr ;
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
std : : shared_ptr < ObjectLibrary > library =
registry - > AddLibrary ( " static " , RegisterTestUnguarded , " " ) ;
std : : make_shared < ObjectLibrary > ( " static " ) ;
registry - > AddLibrary ( library ) ;
library - > AddFactory < Env > (
" unguarded " ,
[ ] ( const std : : string & /*uri*/ , std : : unique_ptr < Env > * /*guard */ ,
std : : string * /* errmsg */ ) { return Env : : Default ( ) ; } ) ;
library - > AddFactory < Env > (
" guarded " , [ ] ( const std : : string & uri , std : : unique_ptr < Env > * guard ,
std : : string * /* errmsg */ ) {
guard - > reset ( new WrappedEnv ( Env : : Default ( ) , uri ) ) ;
return guard - > get ( ) ;
} ) ;
ASSERT_NOK ( registry - > NewStaticObject < Env > ( " guarded " , & env ) ) ;
ASSERT_NOK ( registry - > NewStaticObject < Env > ( " guarded " , & env ) ) ;
ASSERT_EQ ( env , nullptr ) ;
ASSERT_EQ ( env , nullptr ) ;
@ -170,20 +160,7 @@ TEST_F(ObjRegistryTest, CheckStatic) {
TEST_F ( ObjRegistryTest , CheckUnique ) {
TEST_F ( ObjRegistryTest , CheckUnique ) {
std : : unique_ptr < Env > unique ;
std : : unique_ptr < Env > unique ;
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
std : : shared_ptr < ObjectLibrary > library =
registry - > AddLibrary ( " unique " , RegisterTestUnguarded , " " ) ;
std : : make_shared < ObjectLibrary > ( " unique " ) ;
registry - > AddLibrary ( library ) ;
library - > AddFactory < Env > (
" unguarded " ,
[ ] ( const std : : string & /*uri*/ , std : : unique_ptr < Env > * /*guard */ ,
std : : string * /* errmsg */ ) { return Env : : Default ( ) ; } ) ;
library - > AddFactory < Env > (
" guarded " , [ ] ( const std : : string & uri , std : : unique_ptr < Env > * guard ,
std : : string * /* errmsg */ ) {
guard - > reset ( new WrappedEnv ( Env : : Default ( ) , uri ) ) ;
return guard - > get ( ) ;
} ) ;
ASSERT_OK ( registry - > NewUniqueObject < Env > ( " guarded " , & unique ) ) ;
ASSERT_OK ( registry - > NewUniqueObject < Env > ( " guarded " , & unique ) ) ;
ASSERT_NE ( unique , nullptr ) ;
ASSERT_NE ( unique , nullptr ) ;
@ -268,6 +245,7 @@ TEST_F(ObjRegistryTest, TestRegistryParents) {
ASSERT_NOK ( child - > NewUniqueObject < Env > ( " cousin " , & guard ) ) ;
ASSERT_NOK ( child - > NewUniqueObject < Env > ( " cousin " , & guard ) ) ;
ASSERT_NOK ( uncle - > NewUniqueObject < Env > ( " cousin " , & guard ) ) ;
ASSERT_NOK ( uncle - > NewUniqueObject < Env > ( " cousin " , & guard ) ) ;
}
}
class MyCustomizable : public Customizable {
class MyCustomizable : public Customizable {
public :
public :
static const char * Type ( ) { return " MyCustomizable " ; }
static const char * Type ( ) { return " MyCustomizable " ; }
@ -493,6 +471,18 @@ TEST_F(ObjRegistryTest, TestGetOrCreateManagedObject) {
ASSERT_EQ ( 2 , obj . use_count ( ) ) ;
ASSERT_EQ ( 2 , obj . use_count ( ) ) ;
}
}
TEST_F ( ObjRegistryTest , RegisterPlugin ) {
std : : shared_ptr < ObjectRegistry > registry = ObjectRegistry : : NewInstance ( ) ;
std : : unique_ptr < Env > guard ;
Env * env = nullptr ;
ASSERT_NOK ( registry - > NewObject < Env > ( " unguarded " , & env , & guard ) ) ;
ASSERT_EQ ( registry - > RegisterPlugin ( " Missing " , nullptr ) , - 1 ) ;
ASSERT_EQ ( registry - > RegisterPlugin ( " " , RegisterTestUnguarded ) , - 1 ) ;
ASSERT_GT ( registry - > RegisterPlugin ( " Valid " , RegisterTestUnguarded ) , 0 ) ;
ASSERT_OK ( registry - > NewObject < Env > ( " unguarded " , & env , & guard ) ) ;
ASSERT_NE ( env , nullptr ) ;
}
class PatternEntryTest : public testing : : Test { } ;
class PatternEntryTest : public testing : : Test { } ;
TEST_F ( PatternEntryTest , TestSimpleEntry ) {
TEST_F ( PatternEntryTest , TestSimpleEntry ) {