int TestBackupSimpleEnvWithConfig(CuTest *ct) { DB_ENV *dbenv; DB *dbp; DBTYPE dtype; struct handlers *info; char **names; int cnt, has_callback; time_t end_time, secs1, secs2, start_time; u_int32_t flag, value; dtype = DB_BTREE; info = ct->context; has_callback = 0; flag = DB_EXCL; end_time = secs1 = secs2 = start_time = 0; /* Step 1: set up directories. */ CuAssert(ct, "setup_dir", setup_dir(0, NULL) == 0); /* Step 2: open db handle. */ CuAssert(ct, "open_dbp", open_dbp(&dbenv, &dbp, dtype, 0, NULL, NULL, NULL, 0, NULL) == 0); info->dbenvp = dbenv; info->dbp = dbp; /* * Step 3: store records into db so that there is more than * 1 data page in the db. */ CuAssert(ct, "store_records", store_records(dbp, 10) == 0); CuAssert(ct, "DB->sync", dbp->sync(dbp, 0) == 0); /* * Step 4: verify the backup handle is NULL, * since we never configure the backup. */ CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, &value) == EINVAL); /* * Step 5: backup without any backup configs. * 5a: backup only the db file without callbacks and record the time. */ start_time = time(NULL); CuAssert(ct, "backup_db", backup_db(ct, dbenv, BACKUP_DB, flag, has_callback) == 0); end_time = time(NULL); secs1 = end_time - start_time; /* 5b: verify db file is in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 0, NULL, NULL) == 0); /* 5c: verify that no other files are in BACKUP_DIR. */ CuAssert(ct, "__os_dirlist", __os_dirlist(NULL, BACKUP_DIR, 0, &names, &cnt) == 0); CuAssert(ct, "too many files in backupdir", cnt == 1); /* Clean up the backup directory. */ setup_envdir(BACKUP_DIR, 1); /* * Step 6: backup with backup configs. * 6a: configure the backup handle: use direct I/O to write pages to * the disk, the backup buffer size is 256 bytes (which is smaller * than the db page size), the number of pages * to read before pausing is 1, and the number of seconds to sleep * between batches of reads is 1. */ CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, 1) == 0); CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_SIZE, 256) == 0); CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_READ_COUNT, 1) == 0); CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_READ_SLEEP, US_PER_SEC / 2) == 0); /* * 6b: backup only the db file without callbacks and * record the time. */ start_time = time(NULL); CuAssert(ct, "backup_db", backup_db(ct, dbenv, BACKUP_DB, flag, has_callback) == 0); end_time = time(NULL); secs2 = end_time - start_time; /* 6c: verify db file is in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 0, NULL, NULL) == 0); /* 6d: no other files are in BACKUP_DIR. */ CuAssert(ct, "__os_dirlist", __os_dirlist(NULL, BACKUP_DIR, 0, &names, &cnt) == 0); CuAssert(ct, "too many files in backupdir", cnt == 1); /* 6e: verify the backup config. */ CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_READ_SLEEP, &value) == 0); CuAssertTrue(ct, value == US_PER_SEC / 2); /* * Verify the backup config DB_BACKUP_READ_SLEEP works. That is with * the configuration, backup pauses for a number of microseconds * between batches of reads. So for the same backup content, the backup * time with the configuration should be longer than that without it. */ CuAssertTrue(ct, secs2 > secs1); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_READ_COUNT, &value) == 0); CuAssertTrue(ct, value == 1); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_SIZE, &value) == 0); CuAssertTrue(ct, value == 256); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, &value) == 0); CuAssertTrue(ct, value == 1); /* * Step 7: re-configure the backup write direct config and * verify the new config value. */ CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, 0) == 0); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, &value) == 0); CuAssertTrue(ct, value == 0); return (0); }