コード例 #1
0
    def setUp(self):
        self.homeDirMaster = get_new_environment_path()
        self.homeDirClient = get_new_environment_path()
        self.dbenvMaster = db.DBEnv()
        self.dbenvClient = db.DBEnv()
        self.dbenvMaster.open(
            self.homeDirMaster,
            db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_LOG | db.DB_INIT_MPOOL
            | db.DB_INIT_LOCK | db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD,
            438)
        self.dbenvClient.open(
            self.homeDirClient,
            db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_LOG | db.DB_INIT_MPOOL
            | db.DB_INIT_LOCK | db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD,
            438)
        self.confirmed_master = self.client_startupdone = False

        def confirmed_master(a, b, c):
            if b == db.DB_EVENT_REP_MASTER:
                self.confirmed_master = True

        def client_startupdone(a, b, c):
            if b == db.DB_EVENT_REP_STARTUPDONE:
                self.client_startupdone = True

        self.dbenvMaster.set_event_notify(confirmed_master)
        self.dbenvClient.set_event_notify(client_startupdone)
        self.dbMaster = self.dbClient = None
        return
コード例 #2
0
ファイル: test_replication.py プロジェクト: berkeleydb/dbxml
    def setUp(self) :
        self.homeDirMaster = get_new_environment_path()
        self.homeDirClient = get_new_environment_path()

        self.dbenvMaster = db.DBEnv()
        self.dbenvClient = db.DBEnv()

        # Must use "DB_THREAD" because the Replication Manager will
        # be executed in other threads but will use the same environment.
        # http://forums.oracle.com/forums/thread.jspa?threadID=645788&tstart=0
        self.dbenvMaster.open(self.homeDirMaster, db.DB_CREATE | db.DB_INIT_TXN
                | db.DB_INIT_LOG | db.DB_INIT_MPOOL | db.DB_INIT_LOCK |
                db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD, 0666)
        self.dbenvClient.open(self.homeDirClient, db.DB_CREATE | db.DB_INIT_TXN
                | db.DB_INIT_LOG | db.DB_INIT_MPOOL | db.DB_INIT_LOCK |
                db.DB_INIT_REP | db.DB_RECOVER | db.DB_THREAD, 0666)

        self.confirmed_master=self.client_startupdone=False
        def confirmed_master(a,b,c) :
            if b==db.DB_EVENT_REP_MASTER :
                self.confirmed_master=True

        def client_startupdone(a,b,c) :
            if b==db.DB_EVENT_REP_STARTUPDONE :
                self.client_startupdone=True

        self.dbenvMaster.set_event_notify(confirmed_master)
        self.dbenvClient.set_event_notify(client_startupdone)

        #self.dbenvMaster.set_verbose(db.DB_VERB_REPLICATION, True)
        #self.dbenvMaster.set_verbose(db.DB_VERB_FILEOPS_ALL, True)
        #self.dbenvClient.set_verbose(db.DB_VERB_REPLICATION, True)
        #self.dbenvClient.set_verbose(db.DB_VERB_FILEOPS_ALL, True)

        self.dbMaster = self.dbClient = None
コード例 #3
0
 def do_open(self):
     self.env = db.DBEnv()
     self.env.open(self.homeDir,
                   self.envflags | db.DB_INIT_MPOOL | db.DB_CREATE)
     self.filename = os.path.split(self.filename)[1]
     self.d = dbshelve.DBShelf(self.env)
     self.d.open(self.filename, self.dbtype, self.dbflags)
コード例 #4
0
ファイル: test_early_close.py プロジェクト: Mshrimp/up
    def test02_close_dbenv_before_dbcursor(self):
        dbenv = db.DBEnv()
        dbenv.open(self.homeDir,
                   db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
                   0666)

        d = db.DB(dbenv)
        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)

        d.put("test","this is a test")
        d.put("test2","another test")
        d.put("test3","another one")
        self.assertEqual(d.get("test"), "this is a test", "put!=get")
        c=d.cursor()
        c.first()
        c.next()
        d.close()  # This "close" should close the child db handle also
     # db.close should close the child cursor
        self.assertRaises(db.DBError,c.next)

        d = db.DB(dbenv)
        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
        c=d.cursor()
        c.first()
        c.next()
        dbenv.close()
    # The "close" should close the child db handle also, with cursors
        self.assertRaises(db.DBError, c.next)
コード例 #5
0
    def setUp(self):
        if self.useEnv:
            self.homeDir = get_new_environment_path()
            try:
                self.env = db.DBEnv()
                self.env.set_lg_max(1048576)
                self.env.set_tx_max(30)
                self._t = int(time.time())
                self.env.set_tx_timestamp(self._t)
                self.env.set_flags(self.envsetflags, 1)
                self.env.open(self.homeDir, self.envflags | db.DB_CREATE)
                self.filename = 'test'
            except:
                test_support.rmtree(self.homeDir)
                raise

        else:
            self.env = None
            self.filename = get_new_database_path()
        self.d = db.DB(self.env)
        if not self.useEnv:
            self.d.set_cachesize(*self.cachesize)
            cachesize = self.d.get_cachesize()
            self.assertEqual(cachesize[0], self.cachesize[0])
            self.assertEqual(cachesize[2], self.cachesize[2])
            self.assertEqual(125, int(100.0 * cachesize[1] / self.cachesize[1]))
        self.d.set_flags(self.dbsetflags)
        if self.dbname:
            self.d.open(self.filename, self.dbname, self.dbtype, self.dbopenflags | db.DB_CREATE, self.dbmode)
        else:
            self.d.open(self.filename, mode=self.dbmode, dbtype=self.dbtype, flags=self.dbopenflags | db.DB_CREATE)
        if not self.useEnv:
            self.assertRaises(db.DBInvalidArgError, self.d.set_cachesize, *self.cachesize)
        self.populateDB()
        return
コード例 #6
0
 def setUp(self):
     self.filename = self.__class__.__name__ + '.db'
     self.homeDir = get_new_environment_path()
     self.env = db.DBEnv()
     self.env.open(
         self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK
         | db.DB_THREAD | self.envFlags)
コード例 #7
0
ファイル: test_early_close.py プロジェクト: Mshrimp/up
    def test04_close_massive(self):
        dbenv = db.DBEnv()
        dbenv.open(self.homeDir,
                   db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
                   0666)

        dbs=[db.DB(dbenv) for i in xrange(16)]
        cursors=[]
        for i in dbs :
            i.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)

        dbs[10].put("test","this is a test")
        dbs[10].put("test2","another test")
        dbs[10].put("test3","another one")
        self.assertEqual(dbs[4].get("test"), "this is a test", "put!=get")

        for i in dbs :
            cursors.extend([i.cursor() for j in xrange(32)])

        for i in dbs[::3] :
            i.close()
        for i in cursors[::3] :
            i.close()

    # Check for missing exception in DB! (after DB close)
        self.assertRaises(db.DBError, dbs[9].get, "test")

    # Check for missing exception in DBCursor! (after DB close)
        self.assertRaises(db.DBError, cursors[101].first)

        cursors[80].first()
        cursors[80].next()
        dbenv.close()  # This "close" should close the child db handle also
    # Check for missing exception! (after DBEnv close)
        self.assertRaises(db.DBError, cursors[80].next)
コード例 #8
0
    def test04_close_massive(self):
        dbenv = db.DBEnv()
        dbenv.open(
            self.homeDir,
            db.DB_INIT_CDB | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_MPOOL,
            438)
        dbs = [db.DB(dbenv) for i in xrange(16)]
        cursors = []
        for i in dbs:
            i.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD,
                   438)

        dbs[10].put('test', 'this is a test')
        dbs[10].put('test2', 'another test')
        dbs[10].put('test3', 'another one')
        self.assertEqual(dbs[4].get('test'), 'this is a test', 'put!=get')
        for i in dbs:
            cursors.extend([i.cursor() for j in xrange(32)])

        for i in dbs[::3]:
            i.close()

        for i in cursors[::3]:
            i.close()

        self.assertRaises(db.DBError, dbs[9].get, 'test')
        self.assertRaises(db.DBError, cursors[101].first)
        cursors[80].first()
        cursors[80].next()
        dbenv.close()
        self.assertRaises(db.DBError, cursors[80].next)
コード例 #9
0
    def test06_close_txn_before_dup_cursor(self):
        dbenv = db.DBEnv()
        dbenv.open(
            self.homeDir,
            db.DB_INIT_TXN | db.DB_INIT_MPOOL | db.DB_INIT_LOG | db.DB_CREATE)
        d = db.DB(dbenv)
        txn = dbenv.txn_begin()
        d.open(self.filename, dbtype=db.DB_HASH, flags=db.DB_CREATE, txn=txn)
        d.put('XXX', 'yyy', txn=txn)
        txn.commit()
        txn = dbenv.txn_begin()
        c1 = d.cursor(txn)
        c2 = c1.dup()
        self.assertEqual(('XXX', 'yyy'), c1.first())
        import warnings
        if sys.version_info < (2, 6):
            warnings.simplefilter('ignore')
            txn.commit()
            warnings.resetwarnings()
        else:
            w = warnings.catch_warnings()
            w.__enter__()
            try:
                warnings.simplefilter('ignore')
                txn.commit()
            finally:
                w.__exit__()

        self.assertRaises(db.DBCursorClosedError, c2.first)
コード例 #10
0
    def test_fileid_reset(self):
        # create DB 1
        self.db1 = db.DB()
        self.db1.open(self.db_path_1,
                      dbtype=db.DB_HASH,
                      flags=(db.DB_CREATE | db.DB_EXCL))
        self.db1.put('spam', 'eggs')
        self.db1.close()

        shutil.copy(self.db_path_1, self.db_path_2)

        self.db2 = db.DB()
        self.db2.open(self.db_path_2, dbtype=db.DB_HASH)
        self.db2.put('spam', 'spam')
        self.db2.close()

        self.db_env = db.DBEnv()
        self.db_env.open(self.db_env_path, db.DB_CREATE | db.DB_INIT_MPOOL)

        # use fileid_reset() here
        self.db_env.fileid_reset(self.db_path_2)

        self.db1 = db.DB(self.db_env)
        self.db1.open(self.db_path_1, dbtype=db.DB_HASH, flags=db.DB_RDONLY)
        self.assertEqual(self.db1.get('spam'), 'eggs')

        self.db2 = db.DB(self.db_env)
        self.db2.open(self.db_path_2, dbtype=db.DB_HASH, flags=db.DB_RDONLY)
        self.assertEqual(self.db2.get('spam'), 'spam')

        self.db1.close()
        self.db2.close()

        self.db_env.close()
コード例 #11
0
 def test06_close_txn_before_dup_cursor(self):
     dbenv = db.DBEnv()
     dbenv.open(
         self.homeDir,
         db.DB_INIT_TXN | db.DB_INIT_MPOOL | db.DB_INIT_LOG | db.DB_CREATE)
     d = db.DB(dbenv)
     txn = dbenv.txn_begin()
     if db.version() < (4, 1):
         d.open(self.filename, dbtype=db.DB_HASH, flags=db.DB_CREATE)
     else:
         d.open(self.filename,
                dbtype=db.DB_HASH,
                flags=db.DB_CREATE,
                txn=txn)
     d.put("XXX", "yyy", txn=txn)
     txn.commit()
     txn = dbenv.txn_begin()
     c1 = d.cursor(txn)
     c2 = c1.dup()
     self.assertEquals(("XXX", "yyy"), c1.first())
     import warnings
     # Not interested in warnings about implicit close.
     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
         txn.commit()
     self.assertRaises(db.DBCursorClosedError, c2.first)
コード例 #12
0
 def _create_env(self, must_open_db):
     self.dbenv = db.DBEnv()
     self.dbenv.set_tx_max(self.num_txns)
     self.dbenv.set_lk_max_lockers(self.num_txns * 2)
     self.dbenv.set_lk_max_locks(self.num_txns * 2)
     self.dbenv.set_lk_max_objects(self.num_txns * 2)
     if self.nosync:
         self.dbenv.set_flags(db.DB_TXN_NOSYNC, True)
     self.dbenv.open(
         self.homeDir,
         db.DB_CREATE | db.DB_THREAD | db.DB_RECOVER | db.DB_INIT_TXN
         | db.DB_INIT_LOG | db.DB_INIT_MPOOL | db.DB_INIT_LOCK, 0666)
     self.db = db.DB(self.dbenv)
     self.db.set_re_len(db.DB_XIDDATASIZE)
     if must_open_db:
         if db.version() > (4, 1):
             txn = self.dbenv.txn_begin()
             self.db.open(self.filename,
                          db.DB_QUEUE,
                          db.DB_CREATE | db.DB_THREAD,
                          0666,
                          txn=txn)
             txn.commit()
         else:
             self.db.open(self.filename, db.DB_QUEUE,
                          db.DB_CREATE | db.DB_THREAD, 0666)
コード例 #13
0
 def setUp(self):
     self.homeDir = get_new_environment_path()
     self.env = db.DBEnv()
     self.env.open(
         self.homeDir,
         db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOG | db.DB_INIT_TXN)
     self.db = db.DB(self.env)
コード例 #14
0
ファイル: test_basics.py プロジェクト: redb/MNPP
    def setUp(self):
        if self.useEnv:
            self.homeDir = get_new_environment_path()
            try:
                self.env = db.DBEnv()
                self.env.set_lg_max(1024 * 1024)
                self.env.set_tx_max(30)
                self.env.set_tx_timestamp(int(time.time()))
                self.env.set_flags(self.envsetflags, 1)
                self.env.open(self.homeDir, self.envflags | db.DB_CREATE)
                self.filename = "test"
            # Yes, a bare except is intended, since we're re-raising the exc.
            except:
                test_support.rmtree(self.homeDir)
                raise
        else:
            self.env = None
            self.filename = get_new_database_path()

        # create and open the DB
        self.d = db.DB(self.env)
        self.d.set_flags(self.dbsetflags)
        if self.dbname:
            self.d.open(self.filename, self.dbname, self.dbtype,
                        self.dbopenflags | db.DB_CREATE, self.dbmode)
        else:
            self.d.open(
                self.filename,  # try out keyword args
                mode=self.dbmode,
                dbtype=self.dbtype,
                flags=self.dbopenflags | db.DB_CREATE)

        self.populateDB()
コード例 #15
0
 def setUp(self):
     self.int_32_max = 4294967296L
     self.homeDir = get_new_environment_path()
     self.filename = 'test'
     self.dbenv = db.DBEnv()
     self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 438)
     self.d = db.DB(self.dbenv)
     self.d.open(self.filename, db.DB_BTREE, db.DB_CREATE, 438)
コード例 #16
0
ファイル: test_misc.py プロジェクト: altrevi2/Cpp
 def test02_db_home(self):
     env = db.DBEnv()
     # check for crash fixed when db_home is used before open()
     self.assertTrue(env.db_home is None)
     env.open(self.homeDir, db.DB_CREATE)
     if sys.version_info[0] < 3:
         self.assertEqual(self.homeDir, env.db_home)
     else:
         self.assertEqual(bytes(self.homeDir, "ascii"), env.db_home)
コード例 #17
0
    def setUp(self):
        self.int_32_max = 0x100000000
        self.homeDir = get_new_environment_path()
        self.filename = "test"

        self.dbenv = db.DBEnv()
        self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 0666)
        self.d = db.DB(self.dbenv)
        self.d.open(self.filename, db.DB_BTREE, db.DB_CREATE, 0666)
コード例 #18
0
 def test02_db_home(self):
     env = db.DBEnv()
     self.assertTrue(env.db_home is None)
     env.open(self.homeDir, db.DB_CREATE)
     if sys.version_info[0] < 3:
         self.assertEqual(self.homeDir, env.db_home)
     else:
         self.assertEqual(bytes(self.homeDir, 'ascii'), env.db_home)
     return
コード例 #19
0
 def test01_close_dbenv_before_db(self):
     dbenv = db.DBEnv()
     dbenv.open(self.homeDir, db.DB_INIT_CDB | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_MPOOL, 438)
     d = db.DB(dbenv)
     d2 = db.DB(dbenv)
     d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 438)
     self.assertRaises(db.DBNoSuchFileError, d2.open, self.filename + '2', db.DB_BTREE, db.DB_THREAD, 438)
     d.put('test', 'this is a test')
     self.assertEqual(d.get('test'), 'this is a test', 'put!=get')
     dbenv.close()
     self.assertRaises(db.DBError, d.get, 'test')
コード例 #20
0
 def setUp(self):
     if verbose:
         dbutils._deadlock_VerboseFile = sys.stdout
     self.homeDir = get_new_environment_path()
     self.env = db.DBEnv()
     self.setEnvOpts()
     self.env.open(self.homeDir, self.envflags | db.DB_CREATE)
     self.filename = self.__class__.__name__ + '.db'
     self.d = db.DB(self.env)
     if self.dbsetflags:
         self.d.set_flags(self.dbsetflags)
     self.d.open(self.filename, self.dbtype, self.dbopenflags | db.DB_CREATE)
コード例 #21
0
 def setUp(self):
     self.homeDir = get_new_environment_path()
     self.env = db.DBEnv()
     self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
     self.primary_db = db.DB(self.env)
     self.primary_db.open(self.db_name, 'primary', db.DB_BTREE, db.DB_CREATE)
     self.secondary_db = db.DB(self.env)
     self.secondary_db.set_flags(db.DB_DUP)
     self.secondary_db.open(self.db_name, 'secondary', db.DB_BTREE, db.DB_CREATE)
     self.primary_db.associate(self.secondary_db, lambda key, data: data)
     self.primary_db.put('salad', 'eggs')
     self.primary_db.put('spam', 'ham')
     self.primary_db.put('omelet', 'eggs')
コード例 #22
0
    def test05_close_dbenv_delete_db_success(self):
        dbenv = db.DBEnv()
        dbenv.open(self.homeDir, db.DB_INIT_CDB | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_MPOOL, 438)
        d = db.DB(dbenv)
        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 438)
        dbenv.close()
        del d
        try:
            import gc
        except ImportError:
            gc = None

        if gc:
            gc.collect()
        return
コード例 #23
0
ファイル: test_pickle.py プロジェクト: underrun/pybsddb
 def _base_test_pickle_DBError(self, pickle):
     self.env = db.DBEnv()
     self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
     self.db = db.DB(self.env)
     self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE)
     self.db.put('spam', 'eggs')
     self.assertEqual(self.db['spam'], 'eggs')
     try:
         self.db.put('spam', 'ham', flags=db.DB_NOOVERWRITE)
     except db.DBError, egg:
         pickledEgg = pickle.dumps(egg)
         #print repr(pickledEgg)
         rottenEgg = pickle.loads(pickledEgg)
         if rottenEgg.args != egg.args or type(rottenEgg) != type(egg):
             raise Exception, (rottenEgg, '!=', egg)
コード例 #24
0
    def setUp(self):
        if self.useEnv:
            self.homeDir = get_new_environment_path()
            try:
                self.env = db.DBEnv()
                self.env.set_lg_max(1024 * 1024)
                self.env.set_tx_max(30)
                self._t = int(time.time())
                self.env.set_tx_timestamp(self._t)
                self.env.set_flags(self.envsetflags, 1)
                self.env.open(self.homeDir, self.envflags | db.DB_CREATE)
                self.filename = "test"
            # Yes, a bare except is intended, since we're re-raising the exc.
            except:
                test_support.rmtree(self.homeDir)
                raise
        else:
            self.env = None
            self.filename = get_new_database_path()

        # create and open the DB
        self.d = db.DB(self.env)
        if not self.useEnv:
            if db.version() >= (4, 2):
                self.d.set_cachesize(*self.cachesize)
                cachesize = self.d.get_cachesize()
                self.assertEqual(cachesize[0], self.cachesize[0])
                self.assertEqual(cachesize[2], self.cachesize[2])
                # Berkeley DB expands the cache 25% accounting overhead,
                # if the cache is small.
                self.assertEqual(125,
                                 int(100.0 * cachesize[1] / self.cachesize[1]))
        self.d.set_flags(self.dbsetflags)
        if self.dbname:
            self.d.open(self.filename, self.dbname, self.dbtype,
                        self.dbopenflags | db.DB_CREATE, self.dbmode)
        else:
            self.d.open(
                self.filename,  # try out keyword args
                mode=self.dbmode,
                dbtype=self.dbtype,
                flags=self.dbopenflags | db.DB_CREATE)

        if not self.useEnv:
            self.assertRaises(db.DBInvalidArgError, self.d.set_cachesize,
                              *self.cachesize)

        self.populateDB()
コード例 #25
0
def test_suite():
    suite = unittest.TestSuite()
    if db.version() >= (4, 6):
        dbenv = db.DBEnv()
        try:
            dbenv.repmgr_get_ack_policy()
            ReplicationManager_available = True
        except:
            ReplicationManager_available = False

        dbenv.close()
        del dbenv
        if ReplicationManager_available:
            suite.addTest(unittest.makeSuite(DBReplicationManager))
        if have_threads:
            suite.addTest(unittest.makeSuite(DBBaseReplication))
    return suite
コード例 #26
0
ファイル: test_early_close.py プロジェクト: Mshrimp/up
    def test01_close_dbenv_before_db(self):
        dbenv = db.DBEnv()
        dbenv.open(self.homeDir,
                   db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
                   0666)

        d = db.DB(dbenv)
        d2 = db.DB(dbenv)
        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)

        self.assertRaises(db.DBNoSuchFileError, d2.open,
                self.filename+"2", db.DB_BTREE, db.DB_THREAD, 0666)

        d.put("test","this is a test")
        self.assertEqual(d.get("test"), "this is a test", "put!=get")
        dbenv.close()  # This "close" should close the child db handle also
        self.assertRaises(db.DBError, d.get, "test")
コード例 #27
0
ファイル: test_early_close.py プロジェクト: Mshrimp/up
    def test06_close_txn_before_dup_cursor(self) :
        dbenv = db.DBEnv()
        dbenv.open(self.homeDir,db.DB_INIT_TXN | db.DB_INIT_MPOOL |
                db.DB_INIT_LOG | db.DB_CREATE)
        d = db.DB(dbenv)
        txn = dbenv.txn_begin()
        d.open(self.filename, dbtype = db.DB_HASH, flags = db.DB_CREATE,
                txn=txn)
        d.put("XXX", "yyy", txn=txn)
        txn.commit()
        txn = dbenv.txn_begin()
        c1 = d.cursor(txn)
        c2 = c1.dup()
        self.assertEqual(("XXX", "yyy"), c1.first())

        # Not interested in warnings about implicit close.
        import warnings
        if sys.version_info < (2, 6) :
            # Completely resetting the warning state is
            # problematic with python >=2.6 with -3 (py3k warning),
            # because some stdlib modules selectively ignores warnings.
            warnings.simplefilter("ignore")
            txn.commit()
            warnings.resetwarnings()
        else :
            # When we drop support for python 2.3 and 2.4
            # we could use: (in 2.5 we need a __future__ statement)
            #
            #    with warnings.catch_warnings():
            #        warnings.simplefilter("ignore")
            #        txn.commit()
            #
            # We can not use "with" as is, because it would be invalid syntax
            # in python 2.3, 2.4 and (with no __future__) 2.5.
            # Here we simulate "with" following PEP 343 :
            w = warnings.catch_warnings()
            w.__enter__()
            try :
                warnings.simplefilter("ignore")
                txn.commit()
            finally :
                w.__exit__()

        self.assertRaises(db.DBCursorClosedError, c2.first)
コード例 #28
0
ファイル: test_early_close.py プロジェクト: Mshrimp/up
    def test05_close_dbenv_delete_db_success(self):
        dbenv = db.DBEnv()
        dbenv.open(self.homeDir,
                   db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
                   0666)

        d = db.DB(dbenv)
        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)

        dbenv.close()  # This "close" should close the child db handle also

        del d
        try:
            import gc
        except ImportError:
            gc = None
        if gc:
            # force d.__del__ [DB_dealloc] to be called
            gc.collect()
コード例 #29
0
 def test02_close_dbenv_before_dbcursor(self):
     dbenv = db.DBEnv()
     dbenv.open(self.homeDir, db.DB_INIT_CDB | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_MPOOL, 438)
     d = db.DB(dbenv)
     d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 438)
     d.put('test', 'this is a test')
     d.put('test2', 'another test')
     d.put('test3', 'another one')
     self.assertEqual(d.get('test'), 'this is a test', 'put!=get')
     c = d.cursor()
     c.first()
     c.next()
     d.close()
     self.assertRaises(db.DBError, c.next)
     d = db.DB(dbenv)
     d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 438)
     c = d.cursor()
     c.first()
     c.next()
     dbenv.close()
     self.assertRaises(db.DBError, c.next)
コード例 #30
0
 def setUp(self):
     self.homeDir = get_new_environment_path()
     self.env = db.DBEnv()
     self.env.open(self.homeDir, db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_CREATE)