/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3735.2.1 by Robert Collins
Add the concept of CHK lookups to Repository.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
3735.36.3 by John Arbash Meinel
Add the new address for FSF to the new files.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3735.2.1 by Robert Collins
Add the concept of CHK lookups to Repository.
16
17
"""Tests for repositories that support CHK indices."""
18
3735.2.77 by John Arbash Meinel
Fix 'test_pack_preserves_chk_bytes_store'.
19
from bzrlib import osutils
3735.2.1 by Robert Collins
Add the concept of CHK lookups to Repository.
20
from bzrlib.versionedfile import VersionedFiles
3735.2.4 by Robert Collins
Test RemoteRepository with and with-out chk index backing formats.
21
from bzrlib.tests.per_repository_chk import TestCaseWithRepositoryCHK
22
23
24
class TestCHKSupport(TestCaseWithRepositoryCHK):
3735.2.1 by Robert Collins
Add the concept of CHK lookups to Repository.
25
26
    def test_chk_bytes_attribute_is_VersionedFiles(self):
27
        repo = self.make_repository('.')
28
        self.assertIsInstance(repo.chk_bytes, VersionedFiles)
3735.2.6 by Robert Collins
Basic add-and-pack of CHK content from within a repository.
29
30
    def test_add_bytes_to_chk_bytes_store(self):
31
        repo = self.make_repository('.')
32
        repo.lock_write()
33
        try:
34
            repo.start_write_group()
35
            try:
36
                sha1, len, _ = repo.chk_bytes.add_lines((None,),
37
                    None, ["foo\n", "bar\n"], random_id=True)
38
                self.assertEqual('4e48e2c9a3d2ca8a708cb0cc545700544efb5021',
39
                    sha1)
40
                self.assertEqual(
41
                    set([('sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)]),
42
                    repo.chk_bytes.keys())
43
            except:
44
                repo.abort_write_group()
45
                raise
46
            else:
47
                repo.commit_write_group()
48
        finally:
49
            repo.unlock()
50
        # And after an unlock/lock pair
51
        repo.lock_read()
52
        try:
53
            self.assertEqual(
54
                set([('sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)]),
55
                repo.chk_bytes.keys())
56
        finally:
57
            repo.unlock()
58
        # and reopening
59
        repo = repo.bzrdir.open_repository()
60
        repo.lock_read()
61
        try:
62
            self.assertEqual(
63
                set([('sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021',)]),
64
                repo.chk_bytes.keys())
65
        finally:
66
            repo.unlock()
67
68
    def test_pack_preserves_chk_bytes_store(self):
3735.2.77 by John Arbash Meinel
Fix 'test_pack_preserves_chk_bytes_store'.
69
        leaf_lines = ["chkleaf:\n", "0\n", "1\n", "0\n", "\n"]
70
        leaf_sha1 = osutils.sha_strings(leaf_lines)
71
        node_lines = ["chknode:\n", "0\n", "1\n", "1\n", "foo\n",
72
                      "\x00sha1:%s\n" % (leaf_sha1,)]
73
        node_sha1 = osutils.sha_strings(node_lines)
74
        expected_set = set([('sha1:' + leaf_sha1,), ('sha1:' + node_sha1,)])
3735.2.6 by Robert Collins
Basic add-and-pack of CHK content from within a repository.
75
        repo = self.make_repository('.')
76
        repo.lock_write()
77
        try:
78
            repo.start_write_group()
79
            try:
3735.2.26 by Robert Collins
CHKInventory migrated to new CHKMap code.
80
                # Internal node pointing at a leaf.
3735.2.77 by John Arbash Meinel
Fix 'test_pack_preserves_chk_bytes_store'.
81
                repo.chk_bytes.add_lines((None,), None, node_lines, random_id=True)
3735.2.6 by Robert Collins
Basic add-and-pack of CHK content from within a repository.
82
            except:
83
                repo.abort_write_group()
84
                raise
85
            else:
86
                repo.commit_write_group()
87
            repo.start_write_group()
88
            try:
3735.2.26 by Robert Collins
CHKInventory migrated to new CHKMap code.
89
                # Leaf in a separate pack.
3735.2.77 by John Arbash Meinel
Fix 'test_pack_preserves_chk_bytes_store'.
90
                repo.chk_bytes.add_lines((None,), None, leaf_lines, random_id=True)
3735.2.6 by Robert Collins
Basic add-and-pack of CHK content from within a repository.
91
            except:
92
                repo.abort_write_group()
93
                raise
94
            else:
95
                repo.commit_write_group()
96
            repo.pack()
3735.2.18 by Robert Collins
Partial multi-layer chk dictionary trees.
97
            self.assertEqual(expected_set, repo.chk_bytes.keys())
3735.2.6 by Robert Collins
Basic add-and-pack of CHK content from within a repository.
98
        finally:
99
            repo.unlock()
100
        # and reopening
101
        repo = repo.bzrdir.open_repository()
102
        repo.lock_read()
103
        try:
3735.2.18 by Robert Collins
Partial multi-layer chk dictionary trees.
104
            self.assertEqual(expected_set, repo.chk_bytes.keys())
3735.2.6 by Robert Collins
Basic add-and-pack of CHK content from within a repository.
105
        finally:
106
            repo.unlock()