10a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport os, glob 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test_all import db, test_support, get_new_environment_path, \ 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao get_new_database_path 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao#---------------------------------------------------------------------- 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DBEnv(unittest.TestCase): 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.homeDir = get_new_environment_path() 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env = db.DBEnv() 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def tearDown(self): 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.close() 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao del self.env 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_support.rmtree(self.homeDir) 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DBEnv_general(DBEnv) : 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_get_open_flags(self) : 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao flags = db.DB_CREATE | db.DB_INIT_MPOOL 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, flags) 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(flags, self.env.get_open_flags()) 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_get_open_flags2(self) : 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao flags = db.DB_CREATE | db.DB_INIT_MPOOL | \ 270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao db.DB_INIT_LOCK | db.DB_THREAD 280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, flags) 290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(flags, self.env.get_open_flags()) 300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 7) : 320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lk_partitions(self) : 330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [10, 20, 40] : 340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lk_partitions(i) 350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lk_partitions()) 360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_getset_intermediate_dir_mode(self) : 380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(None, self.env.get_intermediate_dir_mode()) 390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for mode in ["rwx------", "rw-rw-rw-", "rw-r--r--"] : 400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_intermediate_dir_mode(mode) 410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(mode, self.env.get_intermediate_dir_mode()) 420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_intermediate_dir_mode, "abcde") 440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 6) : 460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_thread(self) : 470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [16, 100, 1000] : 480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_thread_count(i) 490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_thread_count()) 500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_cache_max(self) : 520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for size in [64, 128] : 530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao size = size*1024*1024 # Megabytes 540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_cache_max(0, size) 550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao size2 = self.env.get_cache_max() 560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(0, size2[0]) 570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(size <= size2[1]) 580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(2*size > size2[1]) 590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 4) : 610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mutex_stat(self) : 620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | 630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao db.DB_INIT_LOCK) 640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao stat = self.env.mutex_stat() 650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue("mutex_inuse_max" in stat) 660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lg_filemode(self) : 680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [0600, 0660, 0666] : 690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lg_filemode(i) 700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lg_filemode()) 710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mp_max_openfd(self) : 730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [17, 31, 42] : 740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_mp_max_openfd(i) 750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_mp_max_openfd()) 760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mp_max_write(self) : 780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [100, 200, 300] : 790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for j in [1, 2, 3] : 800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao j *= 1000000 810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_mp_max_write(i, j) 820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v=self.env.get_mp_max_write() 830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual((i, j), v) 840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_invalid_txn(self) : 860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # This environment doesn't support transactions 870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, self.env.txn_begin) 880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mp_mmapsize(self) : 900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [16, 32, 64] : 910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao i *= 1024*1024 920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_mp_mmapsize(i) 930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_mp_mmapsize()) 940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_tmp_dir(self) : 960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in ["a", "bb", "ccc"] : 970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_tmp_dir(i) 980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_tmp_dir()) 990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_flags(self) : 1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_flags(db.DB_AUTO_COMMIT, 1) 1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(db.DB_AUTO_COMMIT, self.env.get_flags()) 1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_flags(db.DB_TXN_NOSYNC, 1) 1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(db.DB_AUTO_COMMIT | db.DB_TXN_NOSYNC, 1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.get_flags()) 1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_flags(db.DB_AUTO_COMMIT, 0) 1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(db.DB_TXN_NOSYNC, self.env.get_flags()) 1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_flags(db.DB_TXN_NOSYNC, 0) 1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(0, self.env.get_flags()) 1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lk_max_objects(self) : 1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [1000, 2000, 3000] : 1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lk_max_objects(i) 1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lk_max_objects()) 1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lk_max_locks(self) : 1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [1000, 2000, 3000] : 1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lk_max_locks(i) 1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lk_max_locks()) 1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lk_max_lockers(self) : 1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [1000, 2000, 3000] : 1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lk_max_lockers(i) 1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lk_max_lockers()) 1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lg_regionmax(self) : 1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in [128, 256, 1000] : 1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao i = i*1024*1024 1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lg_regionmax(i) 1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao j = self.env.get_lg_regionmax() 1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(i <= j) 1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(2*i > j) 1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lk_detect(self) : 1350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao flags= [db.DB_LOCK_DEFAULT, db.DB_LOCK_EXPIRE, db.DB_LOCK_MAXLOCKS, 1360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao db.DB_LOCK_MINLOCKS, db.DB_LOCK_MINWRITE, 1370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao db.DB_LOCK_OLDEST, db.DB_LOCK_RANDOM, db.DB_LOCK_YOUNGEST] 1380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao flags.append(db.DB_LOCK_MAXWRITE) 1400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in flags : 1420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lk_detect(i) 1430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lk_detect()) 1440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lg_dir(self) : 1460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in ["a", "bb", "ccc", "dddd"] : 1470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lg_dir(i) 1480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(i, self.env.get_lg_dir()) 1490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_lg_bsize(self) : 1510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao log_size = 70*1024 1520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lg_bsize(log_size) 1530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.get_lg_bsize() >= log_size) 1540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.get_lg_bsize() < 4*log_size) 1550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_lg_bsize(4*log_size) 1560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.get_lg_bsize() >= 4*log_size) 1570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_setget_data_dirs(self) : 1590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao dirs = ("a", "b", "c", "d") 1600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in dirs : 1610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_data_dir(i) 1620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(dirs, self.env.get_data_dirs()) 1630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_setget_cachesize(self) : 1650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cachesize = (0, 512*1024*1024, 3) 1660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_cachesize(*cachesize) 1670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(cachesize, self.env.get_cachesize()) 1680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cachesize = (0, 1*1024*1024, 5) 1700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_cachesize(*cachesize) 1710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cachesize2 = self.env.get_cachesize() 1720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(cachesize[0], cachesize2[0]) 1730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(cachesize[2], cachesize2[2]) 1740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Berkeley DB expands the cache 25% accounting overhead, 1750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # if the cache is small. 1760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(125, int(100.0*cachesize2[1]/cachesize[1])) 1770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # You can not change configuration after opening 1790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # the environment. 1800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) 1810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cachesize = (0, 2*1024*1024, 1) 1820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 1830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_cachesize, *cachesize) 1840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao cachesize3 = self.env.get_cachesize() 1850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(cachesize2[0], cachesize3[0]) 1860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(cachesize2[2], cachesize3[2]) 1870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # In Berkeley DB 5.1, the cachesize can change when opening the Env 1880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(cachesize2[1] <= cachesize3[1]) 1890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_set_cachesize_dbenv_db(self) : 1910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # You can not configure the cachesize using 1920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # the database handle, if you are using an environment. 1930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao d = db.DB(self.env) 1940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 1950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao d.set_cachesize, 0, 1024*1024, 1) 1960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_setget_shm_key(self) : 1980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao shm_key=137 1990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_shm_key(shm_key) 2000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(shm_key, self.env.get_shm_key()) 2010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_shm_key(shm_key+1) 2020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(shm_key+1, self.env.get_shm_key()) 2030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # You can not change configuration after opening 2050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # the environment. 2060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) 2070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # If we try to reconfigure cache after opening the 2080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # environment, core dump. 2090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 2100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.set_shm_key, shm_key) 2110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(shm_key+1, self.env.get_shm_key()) 2120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 4) : 2140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mutex_setget_max(self) : 2150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = self.env.mutex_get_max() 2160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = v*2+1 2170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_max(v2) 2190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v2, self.env.mutex_get_max()) 2200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_max(v) 2220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v, self.env.mutex_get_max()) 2230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # You can not change configuration after opening 2250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # the environment. 2260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE) 2270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 2280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_max, v2) 2290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mutex_setget_increment(self) : 2310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = self.env.mutex_get_increment() 2320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = 127 2330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_increment(v2) 2350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v2, self.env.mutex_get_increment()) 2360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_increment(v) 2380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v, self.env.mutex_get_increment()) 2390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # You can not change configuration after opening 2410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # the environment. 2420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE) 2430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 2440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_increment, v2) 2450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mutex_setget_tas_spins(self) : 2470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_tas_spins(0) # Default = BDB decides 2480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = self.env.mutex_get_tas_spins() 2490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = v*2+1 2500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_tas_spins(v2) 2520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v2, self.env.mutex_get_tas_spins()) 2530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_tas_spins(v) 2550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v, self.env.mutex_get_tas_spins()) 2560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # In this case, you can change configuration 2580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # after opening the environment. 2590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE) 2600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_tas_spins(v2) 2610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_mutex_setget_align(self) : 2630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = self.env.mutex_get_align() 2640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = 64 2650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if v == 64 : 2660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = 128 2670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_align(v2) 2690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v2, self.env.mutex_get_align()) 2700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Requires a nonzero power of two 2720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 2730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_align, 0) 2740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 2750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_align, 17) 2760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_align(2*v2) 2780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(2*v2, self.env.mutex_get_align()) 2790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # You can not change configuration after opening 2810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # the environment. 2820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE) 2830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBInvalidArgError, 2840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.mutex_set_align, v2) 2850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2870a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DBEnv_log(DBEnv) : 2880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 2890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DBEnv.setUp(self) 2900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOG) 2910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_log_file(self) : 2930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao log_file = self.env.log_file((1, 1)) 2940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual("log.0000000001", log_file[-14:]) 2950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 4) : 2970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # The version with transactions is checked in other test object 2980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_log_printf(self) : 2990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao msg = "This is a test..." 3000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.log_printf(msg) 3010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 3020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(msg in (logc.last()[1])) 3030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 7) : 3050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_log_config(self) : 3060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.log_set_config(db.DB_LOG_DSYNC | db.DB_LOG_ZERO, 1) 3070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.log_get_config(db.DB_LOG_DSYNC)) 3080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.log_get_config(db.DB_LOG_ZERO)) 3090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.log_set_config(db.DB_LOG_ZERO, 0) 3100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.log_get_config(db.DB_LOG_DSYNC)) 3110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertFalse(self.env.log_get_config(db.DB_LOG_ZERO)) 3120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3140a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DBEnv_log_txn(DBEnv) : 3150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 3160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DBEnv.setUp(self) 3170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | 3180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao db.DB_INIT_LOG | db.DB_INIT_TXN) 3190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if (db.version() >= (4, 5)) and (db.version() < (5, 2)) : 3210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_tx_max(self) : 3220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txns=[] 3230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def tx() : 3240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in xrange(self.env.get_tx_max()) : 3250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txns.append(self.env.txn_begin()) 3260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao tx() 3280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(MemoryError, tx) 3290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Abort the transactions before garbage collection, 3310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # to avoid "warnings". 3320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in txns : 3330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao i.abort() 3340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if db.version() >= (4, 4) : 3360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # The version without transactions is checked in other test object 3370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_log_printf(self) : 3380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao msg = "This is a test..." 3390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn = self.env.txn_begin() 3400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.log_printf(msg, txn=txn) 3410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn.commit() 3420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 3430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc.last() # Skip the commit 3440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(msg in (logc.prev()[1])) 3450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao msg = "This is another test..." 3470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn = self.env.txn_begin() 3480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.log_printf(msg, txn=txn) 3490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn.abort() # Do not store the new message 3500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc.last() # Skip the abort 3510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(msg not in (logc.prev()[1])) 3520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao msg = "This is a third test..." 3540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn = self.env.txn_begin() 3550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.log_printf(msg, txn=txn) 3560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn.commit() # Do not store the new message 3570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc.last() # Skip the commit 3580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(msg in (logc.prev()[1])) 3590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3610a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DBEnv_memp(DBEnv): 3620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 3630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DBEnv.setUp(self) 3640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOG) 3650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db = db.DB(self.env) 3660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.open("test", db.DB_HASH, db.DB_CREATE, 0660) 3670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def tearDown(self): 3690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.close() 3700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao del self.db 3710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DBEnv.tearDown(self) 3720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_memp_1_trickle(self) : 3740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.put("hi", "bye") 3750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.memp_trickle(100) > 0) 3760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Preserve the order, do "memp_trickle" test first 3780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_memp_2_sync(self) : 3790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.put("hi", "bye") 3800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.memp_sync() # Full flush 3810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Nothing to do... 3820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.memp_trickle(100) == 0) 3830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.put("hi", "bye2") 3850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.memp_sync((1, 0)) # NOP, probably 3860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Something to do... or not 3870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.memp_trickle(100) >= 0) 3880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.put("hi", "bye3") 3900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.memp_sync((123, 99)) # Full flush 3910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Nothing to do... 3920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(self.env.memp_trickle(100) == 0) 3930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 3940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_memp_stat_1(self) : 3950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao stats = self.env.memp_stat() # No param 3960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(len(stats)==2) 3970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue("cache_miss" in stats[0]) 3980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao stats = self.env.memp_stat(db.DB_STAT_CLEAR) # Positional param 3990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue("cache_miss" in stats[0]) 4000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao stats = self.env.memp_stat(flags=0) # Keyword param 4010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue("cache_miss" in stats[0]) 4020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_memp_stat_2(self) : 4040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao stats=self.env.memp_stat()[1] 4050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(len(stats))==1 4060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue("test" in stats) 4070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue("page_in" in stats["test"]) 4080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4090a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DBEnv_logcursor(DBEnv): 4100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def setUp(self): 4110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DBEnv.setUp(self) 4120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | 4130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao db.DB_INIT_LOG | db.DB_INIT_TXN) 4140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn = self.env.txn_begin() 4150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db = db.DB(self.env) 4160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.open("test", db.DB_HASH, db.DB_CREATE, 0660, txn=txn) 4170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn.commit() 4180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in ["2", "8", "20"] : 4190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn = self.env.txn_begin() 4200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.put(key = i, data = i*int(i), txn=txn) 4210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao txn.commit() 4220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def tearDown(self): 4240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.db.close() 4250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao del self.db 4260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao DBEnv.tearDown(self) 4270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def _check_return(self, value) : 4290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(isinstance(value, tuple)) 4300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(len(value), 2) 4310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(isinstance(value[0], tuple)) 4320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(len(value[0]), 2) 4330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(isinstance(value[0][0], int)) 4340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(isinstance(value[0][1], int)) 4350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(isinstance(value[1], str)) 4360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Preserve test order 4380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_1_first(self) : 4390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 4400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = logc.first() 4410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self._check_return(v) 4420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue((1, 1) < v[0]) 4430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(len(v[1])>0) 4440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_2_last(self) : 4460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 4470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lsn_first = logc.first()[0] 4480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = logc.last() 4490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self._check_return(v) 4500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_first < v[0]) 4510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_3_next(self) : 4530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 4540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lsn_last = logc.last()[0] 4550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(logc.next(), None) 4560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lsn_first = logc.first()[0] 4570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = logc.next() 4580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self._check_return(v) 4590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_first < v[0]) 4600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_last > v[0]) 4610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = logc.next() 4630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(v2[0] > v[0]) 4640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_last > v2[0]) 4650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v3 = logc.next() 4670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(v3[0] > v2[0]) 4680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_last > v3[0]) 4690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_4_prev(self) : 4710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 4720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lsn_first = logc.first()[0] 4730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(logc.prev(), None) 4740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao lsn_last = logc.last()[0] 4750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = logc.prev() 4760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self._check_return(v) 4770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_first < v[0]) 4780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_last > v[0]) 4790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v2 = logc.prev() 4810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(v2[0] < v[0]) 4820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_first < v2[0]) 4830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v3 = logc.prev() 4850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(v3[0] < v2[0]) 4860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertTrue(lsn_first < v3[0]) 4870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_5_current(self) : 4890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 4900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc.first() 4910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = logc.next() 4920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v, logc.current()) 4930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 4940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_6_set(self) : 4950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 4960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc.first() 4970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao v = logc.next() 4980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertNotEqual(v, logc.next()) 4990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertNotEqual(v, logc.next()) 5000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertEqual(v, logc.set(v[0])) 5010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 5020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_explicit_close(self) : 5030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = self.env.log_cursor() 5040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc.close() 5050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBCursorClosedError, logc.next) 5060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 5070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_implicit_close(self) : 5080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao logc = [self.env.log_cursor() for i in xrange(10)] 5090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.env.close() # This close should close too all its tree 5100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for i in logc : 5110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(db.DBCursorClosedError, i.next) 5120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 5130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_suite(): 5140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao suite = unittest.TestSuite() 5150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 5160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao suite.addTest(unittest.makeSuite(DBEnv_general)) 5170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao suite.addTest(unittest.makeSuite(DBEnv_memp)) 5180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao suite.addTest(unittest.makeSuite(DBEnv_logcursor)) 5190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao suite.addTest(unittest.makeSuite(DBEnv_log)) 5200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao suite.addTest(unittest.makeSuite(DBEnv_log_txn)) 5210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 5220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return suite 5230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 5240a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == '__main__': 5250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao unittest.main(defaultTest='test_suite') 526