Rev 1744: parents cache tests. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Sun Aug 31 23:10:17 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1744
revision-id: jelmer at samba.org-20080831221015-d8sebc42cp0lmy4v
parent: jelmer at samba.org-20080831200501-fn85tu9v7ng075k5
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2008-09-01 00:10:15 +0200
message:
parents cache tests.
added:
tests/test_parents.py test_parents.py-20080831221012-2yc11sx1tyk2tj2c-1
modified:
TODO todo-20060729211917-2kpobww0zyvvo0j2-1
parents.py parents.py-20080505192113-5rcif033d6wcam9w-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
=== modified file 'TODO'
--- a/TODO 2008-08-31 17:34:49 +0000
+++ b/TODO 2008-08-31 22:10:15 +0000
@@ -18,9 +18,7 @@
.svn working trees:
- implement apply_inventory_delta()
-
- Needs more tests
- - parents cache
- Run all tests against repository with revprop changing allowed and without
- Needs upgrade command that can use legacy file properties and set revprops
- Support disabling legacy file property support somehow
=== modified file 'parents.py'
--- a/parents.py 2008-08-23 14:55:24 +0000
+++ b/parents.py 2008-08-31 22:10:15 +0000
@@ -20,6 +20,8 @@
from bzrlib.versionedfile import ConstantMapper
class DiskCachingParentsProvider(object):
+ """Parents provider that caches parents in a SQLite database."""
+
def __init__(self, actual, cachetransport):
self._cache = ParentsCache(cachetransport)
self.actual = actual
@@ -33,7 +35,7 @@
todo.add(k)
else:
ret[k] = parents
- if len(todo):
+ if len(todo) > 0:
newfound = self.actual.get_parent_map(todo)
for revid, parents in newfound.items():
if revid == NULL_REVISION:
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-08-31 15:31:04 +0000
+++ b/tests/__init__.py 2008-08-31 22:10:15 +0000
@@ -326,6 +326,7 @@
'test_log',
'test_logwalker',
'test_mapping',
+ 'test_parents',
'test_properties',
'test_push',
'test_ra',
=== added file 'tests/test_parents.py'
--- a/tests/test_parents.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_parents.py 2008-08-31 22:10:15 +0000
@@ -0,0 +1,89 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from bzrlib import graph as _mod_graph
+from bzrlib.tests import TestCaseWithMemoryTransport
+from bzrlib.tests.test_graph import InstrumentedParentsProvider
+
+from bzrlib.plugins.svn.parents import ParentsCache, DiskCachingParentsProvider
+
+class ParentsCacheTests(TestCaseWithMemoryTransport):
+
+ def setUp(self):
+ super(ParentsCacheTests, self).setUp()
+ self.cache = ParentsCache(self.get_transport())
+
+ def test_noparents(self):
+ self.cache.insert_parents("myrevid", ())
+ self.assertEquals((), self.cache.lookup_parents("myrevid"))
+
+ def test_single(self):
+ self.cache.insert_parents("myrevid", ("single",))
+ self.assertEquals(("single",), self.cache.lookup_parents("myrevid"))
+
+ def test_multiple(self):
+ self.cache.insert_parents("myrevid", ("one", "two"))
+ self.assertEquals(("one", "two"), self.cache.lookup_parents("myrevid"))
+
+ def test_nonexistant(self):
+ self.assertEquals(None, self.cache.lookup_parents("myrevid"))
+
+ def test_insert_twice(self):
+ self.cache.insert_parents("myrevid", ("single",))
+ self.cache.insert_parents("myrevid", ("second",))
+ self.assertEquals(("second",), self.cache.lookup_parents("myrevid"))
+
+
+class TestCachingParentsProvider(TestCaseWithMemoryTransport):
+
+ def setUp(self):
+ super(TestCachingParentsProvider, self).setUp()
+ dict_pp = _mod_graph.DictParentsProvider({'a':('b',)})
+ self.inst_pp = InstrumentedParentsProvider(dict_pp)
+ self.caching_pp = DiskCachingParentsProvider(self.inst_pp, self.get_transport())
+
+ def test_get_parent_map(self):
+ """Requesting the same revision should be returned from cache"""
+ self.assertEqual({'a':('b',)}, self.caching_pp.get_parent_map(['a']))
+ self.assertEqual(['a'], self.inst_pp.calls)
+ self.assertEqual({'a':('b',)}, self.caching_pp.get_parent_map(['a']))
+ # No new call, as it should have been returned from the cache
+ self.assertEqual(['a'], self.inst_pp.calls)
+
+ def test_get_parent_map_not_present(self):
+ """The cache should also track when a revision doesn't exist"""
+ self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
+ self.assertEqual(['b'], self.inst_pp.calls)
+ self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
+ # No new calls
+ self.assertEqual(['b', 'b'], self.inst_pp.calls)
+
+ def test_get_parent_map_mixed(self):
+ """Anything that can be returned from cache, should be"""
+ self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
+ self.assertEqual(['b'], self.inst_pp.calls)
+ self.assertEqual({'a':('b',)},
+ self.caching_pp.get_parent_map(['a', 'b']))
+ self.assertEqual(['b', 'a', 'b'], self.inst_pp.calls)
+
+ def test_get_parent_map_repeated(self):
+ """Asking for the same parent 2x will only forward 1 request."""
+ self.assertEqual({'a':('b',)},
+ self.caching_pp.get_parent_map(['b', 'a', 'b']))
+ # Use sorted because we don't care about the order, just that each is
+ # only present 1 time.
+ self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls))
+
+
More information about the bazaar-commits
mailing list