@ -45,7 +45,8 @@ void VerifyTableProperties(DB* db, uint64_t expected_entries_size) {
}
} // namespace
class DBTablePropertiesTest : public DBTestBase {
class DBTablePropertiesTest : public DBTestBase ,
public testing : : WithParamInterface < std : : string > {
public :
DBTablePropertiesTest ( ) : DBTestBase ( " /db_table_properties_test " ) { }
TablePropertiesCollection TestGetPropertiesOfTablesInRange (
@ -251,7 +252,20 @@ TEST_F(DBTablePropertiesTest, GetColumnFamilyNameProperty) {
}
}
TEST_F ( DBTablePropertiesTest , DeletionTriggeredCompactionMarking ) {
class DeletionTriggeredCompactionTestListener : public EventListener {
public :
void OnCompactionBegin ( DB * , const CompactionJobInfo & ci ) override {
ASSERT_EQ ( ci . compaction_reason ,
CompactionReason : : kFilesMarkedForCompaction ) ;
}
void OnCompactionCompleted ( DB * , const CompactionJobInfo & ci ) override {
ASSERT_EQ ( ci . compaction_reason ,
CompactionReason : : kFilesMarkedForCompaction ) ;
}
} ;
TEST_P ( DBTablePropertiesTest , DeletionTriggeredCompactionMarking ) {
int kNumKeys = 1000 ;
int kWindowSize = 100 ;
int kNumDelsTrigger = 90 ;
@ -260,6 +274,10 @@ TEST_F(DBTablePropertiesTest, DeletionTriggeredCompactionMarking) {
Options opts = CurrentOptions ( ) ;
opts . table_properties_collector_factories . emplace_back ( compact_on_del ) ;
if ( GetParam ( ) = = " kCompactionStyleUniversal " ) {
opts . compaction_style = kCompactionStyleUniversal ;
}
Reopen ( opts ) ;
// add an L1 file to prevent tombstones from dropping due to obsolescence
@ -268,6 +286,11 @@ TEST_F(DBTablePropertiesTest, DeletionTriggeredCompactionMarking) {
Flush ( ) ;
MoveFilesToLevel ( 1 ) ;
DeletionTriggeredCompactionTestListener * listener =
new DeletionTriggeredCompactionTestListener ( ) ;
opts . listeners . emplace_back ( listener ) ;
Reopen ( opts ) ;
for ( int i = 0 ; i < kNumKeys ; + + i ) {
if ( i > = kNumKeys - kWindowSize & &
i < kNumKeys - kWindowSize + kNumDelsTrigger ) {
@ -280,7 +303,6 @@ TEST_F(DBTablePropertiesTest, DeletionTriggeredCompactionMarking) {
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_GT ( NumTableFilesAtLevel ( 1 ) , 0 ) ;
// Change the window size and deletion trigger and ensure new values take
// effect
@ -302,7 +324,6 @@ TEST_F(DBTablePropertiesTest, DeletionTriggeredCompactionMarking) {
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_GT ( NumTableFilesAtLevel ( 1 ) , 0 ) ;
// Change the window size to disable delete triggered compaction
kWindowSize = 0 ;
@ -322,9 +343,16 @@ TEST_F(DBTablePropertiesTest, DeletionTriggeredCompactionMarking) {
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( 0 ) ) ;
}
INSTANTIATE_TEST_CASE_P (
DBTablePropertiesTest ,
DBTablePropertiesTest ,
: : testing : : Values (
" kCompactionStyleLevel " ,
" kCompactionStyleUniversal "
) ) ;
} // namespace ROCKSDB_NAMESPACE
# endif // ROCKSDB_LITE