Example #1
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)
Example #2
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)
Example #3
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)
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
0
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
Example #10
0
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
Example #11
0
 def test_create_open_close_dont_raise(self):
     fn = self._test_fn()
     pop = pmemobj.create(fn)
     pop.close()
     pop = pmemobj.open(fn)
     pop.close()
Example #12
0
 def _reload_root(self):
     self.pop.close()
     self.pop = pmemobj.open(self.fn, debug=True)
     return self.pop.root
Example #13
0
 def test_open_is_error_if_does_not_exist(self):
     fn = self._test_fn()
     with self.assertRaises(OSError):
         pmemobj.open(fn)
Example #14
0
 def test_implicit_close_after_open(self):
     fn = self._test_fn()
     pop = pmemobj.create(fn)
     pop.close()
     pop = pmemobj.open(fn)
     del pop
Example #15
0
 def test_open_is_error_if_does_not_exist(self):
     fn = self._test_fn()
     with self.assertRaises(OSError):
         pmemobj.open(fn)
Example #16
0
 def _reopen_pop(self):
     self.pop.close()
     pop = self.pop = pmemobj.open(self.fn)
     return pop
Example #17
0
 def test_create_open_close_dont_raise(self):
     fn = self._test_fn()
     pop = pmemobj.create(fn)
     pop.close()
     pop = pmemobj.open(fn)
     pop.close()
Example #18
0
 def _reread_tuple(self):
     self.pop.close()
     self.pop = pmemobj.open(self.fn)
     return self.pop.root
Example #19
0
 def _reread_list(self):
     self.pop.close()
     self.pop = pmemobj.open(self.fn)
     return self.pop.root
Example #20
0
 def test_implicit_close_after_open(self):
     fn = self._test_fn()
     pop = pmemobj.create(fn)
     pop.close()
     pop = pmemobj.open(fn)
     del pop
Example #21
0
 def _reload_root(self):
     self.pop.close()
     self.pop = pmemobj.open(self.fn, debug=True)
     return self.pop.root
Example #22
0
 def _reopen_pop(self):
     self.pop.close()
     pop = self.pop = pmemobj.open(self.fn)
     return pop