@ -1832,25 +1832,47 @@ TEST_F(BackupableDBTest, KeepLogFiles) {
AssertBackupConsistency ( 0 , 0 , 500 , 600 , true ) ;
}
TEST_F ( BackupableDBTest , RateLimiting ) {
size_t const kMicrosPerSec = 1000 * 1000LL ;
uint64_t const MB = 1024 * 1024 ;
class BackupableDBRateLimitingTestWithParam
: public BackupableDBTest ,
public testing : : WithParamInterface <
std : : tuple < bool /* make throttle */ ,
int /* 0 = single threaded, 1 = multi threaded*/ ,
std : : pair < uint64_t , uint64_t > /* limits */ > > {
public :
BackupableDBRateLimitingTestWithParam ( ) { }
} ;
const std : : vector < std : : pair < uint64_t , uint64_t > > limits (
{ { 1 * MB , 5 * MB } , { 2 * MB , 3 * MB } } ) ;
uint64_t const MB = 1024 * 1024 ;
INSTANTIATE_TEST_CASE_P (
RateLimiting , BackupableDBRateLimitingTestWithParam ,
: : testing : : Values ( std : : make_tuple ( false , 0 , std : : make_pair ( 1 * MB , 5 * MB ) ) ,
std : : make_tuple ( false , 0 , std : : make_pair ( 2 * MB , 3 * MB ) ) ,
std : : make_tuple ( false , 1 , std : : make_pair ( 1 * MB , 5 * MB ) ) ,
std : : make_tuple ( false , 1 , std : : make_pair ( 2 * MB , 3 * MB ) ) ,
std : : make_tuple ( true , 0 , std : : make_pair ( 1 * MB , 5 * MB ) ) ,
std : : make_tuple ( true , 0 , std : : make_pair ( 2 * MB , 3 * MB ) ) ,
std : : make_tuple ( true , 1 , std : : make_pair ( 1 * MB , 5 * MB ) ) ,
std : : make_tuple ( true , 1 ,
std : : make_pair ( 2 * MB , 3 * MB ) ) ) ) ;
TEST_P ( BackupableDBRateLimitingTestWithParam , RateLimiting ) {
size_t const kMicrosPerSec = 1000 * 1000LL ;
std : : shared_ptr < RateLimiter > backupThrottler ( NewGenericRateLimiter ( 1 ) ) ;
std : : shared_ptr < RateLimiter > restoreThrottler ( NewGenericRateLimiter ( 1 ) ) ;
for ( bool makeThrottler : { false , true } ) {
bool makeThrottler = std : : get < 0 > ( GetParam ( ) ) ;
if ( makeThrottler ) {
backupable_options_ - > backup_rate_limiter = backupThrottler ;
backupable_options_ - > restore_rate_limiter = restoreThrottler ;
}
// iter 0 -- single threaded
// iter 1 -- multi threaded
for ( int iter = 0 ; iter < 2 ; + + iter ) {
for ( const auto & limit : limits ) {
int iter = std : : get < 1 > ( GetParam ( ) ) ;
const std : : pair < uint64_t , uint64_t > limit = std : : get < 2 > ( GetParam ( ) ) ;
// destroy old data
DestroyDB ( dbname_ , Options ( ) ) ;
if ( makeThrottler ) {
@ -1868,8 +1890,7 @@ TEST_F(BackupableDBTest, RateLimiting) {
auto start_backup = db_chroot_env_ - > NowMicros ( ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) , false ) ) ;
auto backup_time = db_chroot_env_ - > NowMicros ( ) - start_backup ;
auto rate_limited_backup_time =
( bytes_written * kMicrosPerSec ) / limit . first ;
auto rate_limited_backup_time = ( bytes_written * kMicrosPerSec ) / limit . first ;
ASSERT_GT ( backup_time , 0.8 * rate_limited_backup_time ) ;
CloseDBAndBackupEngine ( ) ;
@ -1884,9 +1905,6 @@ TEST_F(BackupableDBTest, RateLimiting) {
ASSERT_GT ( restore_time , 0.8 * rate_limited_restore_time ) ;
AssertBackupConsistency ( 0 , 0 , 100000 , 100010 ) ;
}
}
}
}
TEST_F ( BackupableDBTest , ReadOnlyBackupEngine ) {