def test_gc_runs_automatically(self): pop = self._pop() pop.new(pmemobj.PersistentList) pop.new(pmemobj.PersistentDict) pop.close() pop = pmemobj.open(self.fn) type_counts, gc_counts = pop.gc() self.assertEqual(type_counts['PersistentList'], 1) self.assertNotIn('PersistentDict', type_counts) self.assertEqual(gc_counts['orphans0-gced'], 0)
def test_gc_runs_automatically(self): pop = self._pop() pop.new(pmemobj.PersistentList) pop.new(pmemobj.PersistentDict) pop.close() pop = pmemobj.open(self.fn) type_counts, gc_counts = pop.gc() self.assertEqual(type_counts['PersistentList'], 1) self.assertNotIn('PersistentDict', type_counts) self.assertEqual(gc_counts['orphans0-gced'], 0)
def test_list_of_strings_as_root_obj(self): # Lists and strings are our "built in" types (handled specially by the # code because they are used by the type table), so this exercises # the absolute minimum required functionality, but doesn't fully # exercise anything, including not really testing the type table. test_list = ['a', 'b', 'c', 'd'] fn = self._test_fn() pop = pmemobj.create(fn) self.addCleanup(pop.close) pop.root = pop.new(pmemobj.PersistentList, test_list) pop.close() pop = pmemobj.open(fn) self.assertEqual(pop.root, test_list)
def test_list_of_strings_as_root_obj(self): # Lists and strings are our "built in" types (handled specially by the # code because they are used by the type table), so this exercises # the absolute minimum required functionality, but doesn't fully # exercise anything, including not really testing the type table. test_list = ['a', 'b', 'c', 'd'] fn = self._test_fn() pop = pmemobj.create(fn) self.addCleanup(pop.close) pop.root = pop.new(pmemobj.PersistentList, test_list) pop.close() pop = pmemobj.open(fn) self.assertEqual(pop.root, test_list)
def test_gc_runs_after_abort(self): pop = self._pop() pop.new(pmemobj.PersistentDict) # Fake an abort by not letting the gc run. try: old_gc = pmemobj.PersistentObjectPool.gc pmemobj.PersistentObjectPool.gc = lambda *args, **kw: None pop.close() finally: pmemobj.PersistentObjectPool.gc = old_gc pop = pmemobj.open(self.fn) type_counts, gc_counts = pop.gc() self.assertNotIn('PersistentDict', type_counts) self.assertEqual(gc_counts['orphans0-gced'], 0)
def test_gc_runs_after_abort(self): pop = self._pop() pop.new(pmemobj.PersistentDict) # Fake an abort by not letting the gc run. try: old_gc = pmemobj.PersistentObjectPool.gc pmemobj.PersistentObjectPool.gc = lambda *args, **kw: None pop.close() finally: pmemobj.PersistentObjectPool.gc = old_gc pop = pmemobj.open(self.fn) type_counts, gc_counts = pop.gc() self.assertNotIn('PersistentDict', type_counts) self.assertEqual(gc_counts['orphans0-gced'], 0)
def test_gc_does_not_run_on_startup_after_clean_shutdown(self): pop = self._pop() pop.root = pop.new(pmemobj.PersistentDict) pop.close() self.called = False def fake_gc(*args, **kw): self.called = True try: old_gc = pmemobj.PersistentObjectPool.gc pmemobj.PersistentObjectPool.gc = fake_gc pop = pmemobj.open(self.fn) finally: pmemobj.PersistentObjectPool.gc = old_gc self.assertFalse(self.called)
def test_gc_does_not_run_on_startup_after_clean_shutdown(self): pop = self._pop() pop.root = pop.new(pmemobj.PersistentDict) pop.close() self.called = False def fake_gc(*args, **kw): self.called = True try: old_gc = pmemobj.PersistentObjectPool.gc pmemobj.PersistentObjectPool.gc = fake_gc pop = pmemobj.open(self.fn) finally: pmemobj.PersistentObjectPool.gc = old_gc self.assertFalse(self.called)
def reopen_game(): if not os.path.isfile(pool_fn): raise GameError("No game in progress. Use 'start_guessing'" " to start one.") try: pool = open(pool_fn) except OSError as err: exc = GameError("Could not open game file: {}".format(err)) try: os.remove(pool_fn) except OSError as err: raise GameError("Can't remove game file") raise GameError("Could not open game file, start again" " with 'start_guessing'") if pool.root is None: pool.close() os.remove(pool_fn) raise("Looks like a game was aborted; start again with" " 'start_guessing'") return pool
def reopen_game(): if not os.path.isfile(pool_fn): raise GameError("No game in progress. Use 'start_guessing'" " to start one.") try: pool = open(pool_fn) except OSError as err: exc = GameError("Could not open game file: {}".format(err)) try: os.remove(pool_fn) except OSError as err: raise GameError("Can't remove game file") raise GameError("Could not open game file, start again" " with 'start_guessing'") if pool.root is None: pool.close() os.remove(pool_fn) raise ("Looks like a game was aborted; start again with" " 'start_guessing'") return pool
def test_create_open_close_dont_raise(self): fn = self._test_fn() pop = pmemobj.create(fn) pop.close() pop = pmemobj.open(fn) pop.close()
def _reload_root(self): self.pop.close() self.pop = pmemobj.open(self.fn, debug=True) return self.pop.root
def test_open_is_error_if_does_not_exist(self): fn = self._test_fn() with self.assertRaises(OSError): pmemobj.open(fn)
def test_implicit_close_after_open(self): fn = self._test_fn() pop = pmemobj.create(fn) pop.close() pop = pmemobj.open(fn) del pop
def test_open_is_error_if_does_not_exist(self): fn = self._test_fn() with self.assertRaises(OSError): pmemobj.open(fn)
def _reopen_pop(self): self.pop.close() pop = self.pop = pmemobj.open(self.fn) return pop
def test_create_open_close_dont_raise(self): fn = self._test_fn() pop = pmemobj.create(fn) pop.close() pop = pmemobj.open(fn) pop.close()
def _reread_tuple(self): self.pop.close() self.pop = pmemobj.open(self.fn) return self.pop.root
def _reread_list(self): self.pop.close() self.pop = pmemobj.open(self.fn) return self.pop.root
def test_implicit_close_after_open(self): fn = self._test_fn() pop = pmemobj.create(fn) pop.close() pop = pmemobj.open(fn) del pop
def _reload_root(self): self.pop.close() self.pop = pmemobj.open(self.fn, debug=True) return self.pop.root
def _reopen_pop(self): self.pop.close() pop = self.pop = pmemobj.open(self.fn) return pop