comparison tests/test_revmap_migrate.py @ 1473:623af04c6e06

tests: new test about revmap two-way migrations The test makes sure the bi-directional migration happens transparently, and without data loss.
author Jun Wu <quark@fb.com>
date Wed, 15 Jun 2016 18:25:39 +0100
parents
children 8937f19586fe
comparison
equal deleted inserted replaced
1472:cf79525f507c 1473:623af04c6e06
1 import test_util
2
3 from mercurial import util as hgutil
4 from hgsubversion import svnmeta, maps
5 from mercurial.node import hex
6
7 class TestRevMapMigrate(test_util.TestBase):
8
9 def _test_revmap_migrate(self, fromclass, toclass):
10 # revmap interfaces to test
11 getters = [
12 lambda x: x.branchedits('the_branch', 3),
13 lambda x: x.branchedits('the_branch', 4),
14 lambda x: x.branchedits('the_branch', 5),
15 lambda x: x.branchedits('the_branch', 6),
16 lambda x: x.branchedits(None, 5),
17 lambda x: x.branchedits('non_existed', 10),
18 lambda x: x.branchmaxrevnum('the_branch', 3),
19 lambda x: x.branchmaxrevnum('the_branch', 4),
20 lambda x: x.branchmaxrevnum('the_branch', 5),
21 lambda x: x.branchmaxrevnum('the_branch', 6),
22 lambda x: x.branchmaxrevnum(None, 5),
23 lambda x: x.branchmaxrevnum('non_existed', 10),
24 lambda x: list(x.revhashes(3)),
25 lambda x: list(x.revhashes(4)),
26 lambda x: list(x.revhashes(42)),
27 lambda x: list(x.revhashes(105)),
28 lambda x: x.firstpulled,
29 lambda x: x.lastpulled,
30 lambda x: x.lasthash,
31 ]
32
33 svnmeta.SVNMeta._defaultrevmapclass = fromclass
34 repo = self._load_fixture_and_fetch('two_heads.svndump')
35 meta = svnmeta.SVNMeta(repo)
36 self.assertEqual(meta.revmap.__class__, fromclass)
37 origrevmap = meta.revmap
38
39 # insert fake special (duplicated, with '\0') data
40 origrevmap[103, None] = b'\0' * 20
41 origrevmap[104, None] = b'\0' * 18 + b'cd'
42 origrevmap[105, None] = b'ab\0cdefghijklmnopqrs'
43 origrevmap[104, None] = b'\0' * 18 + b'\xff\0'
44 origrevmap[105, 'ab'] = origrevmap[105, None]
45
46 origvalues = [f(meta.revmap) for f in getters]
47
48 # migrate to another format (transparently)
49 svnmeta.SVNMeta._defaultrevmapclass = toclass
50 meta = svnmeta.SVNMeta(repo)
51 self.assertEqual(meta.revmap.__class__, toclass)
52
53 # enable iteration otherwise we cannot use iteritems
54 origrevmap._allowiter = True
55 for k, v in origrevmap.iteritems():
56 newv = meta.revmap[k]
57 self.assertEqual(newv, v)
58 self.assertEqual(len(newv), 20)
59 self.assertEqual(meta.revmap[meta.revmap.hashes()[v]], v)
60
61 newvalues = [f(meta.revmap) for f in getters]
62 self.assertEqual(origvalues, newvalues)
63
64 def test_revmap_migrate_up(self):
65 self._test_revmap_migrate(maps.RevMap, maps.SqliteRevMap)
66
67 def test_revmap_migrate_down(self):
68 self._test_revmap_migrate(maps.SqliteRevMap, maps.RevMap)