/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4145.1.2 by Robert Collins
Add a refresh_data method on Repository allowing cleaner handling of insertions into RemoteRepository objects with _real_repository instances.
1
# Copyright (C) 2009 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4145.1.2 by Robert Collins
Add a refresh_data method on Repository allowing cleaner handling of insertions into RemoteRepository objects with _real_repository instances.
16
17
"""Tests for Repository.refresh_data."""
18
19
from bzrlib import (
20
    errors,
21
    remote,
22
    )
23
from bzrlib.tests import TestSkipped
24
from bzrlib.tests.per_repository import TestCaseWithRepository
25
26
27
class TestRefreshData(TestCaseWithRepository):
28
29
    def test_refresh_data_unlocked(self):
30
        # While not interesting, it should not error.
31
        repo = self.make_repository('.')
32
        repo.refresh_data()
33
34
    def test_refresh_data_read_locked(self):
35
        # While not interesting, it should not error.
36
        repo = self.make_repository('.')
37
        repo.lock_read()
38
        self.addCleanup(repo.unlock)
39
        repo.refresh_data()
40
41
    def test_refresh_data_write_locked(self):
42
        # While not interesting, it should not error.
43
        repo = self.make_repository('.')
44
        repo.lock_write()
45
        self.addCleanup(repo.unlock)
46
        repo.refresh_data()
47
48
    def test_refresh_data_in_write_group_errors(self):
49
        repo = self.make_repository('.')
50
        repo.lock_write()
51
        self.addCleanup(repo.unlock)
52
        repo.start_write_group()
53
        self.addCleanup(repo.abort_write_group)
54
        # No flow control anticipated, BzrError is enough
55
        self.assertRaises(errors.BzrError, repo.refresh_data)
56
57
    def test_refresh_data_after_fetch_new_data_visible(self):
58
        source = self.make_branch_and_tree('source')
59
        revid = source.commit('foo')
60
        repo = self.make_repository('target')
61
        token = repo.lock_write()
62
        self.addCleanup(repo.unlock)
63
        # Force data reading on weaves/knits
64
        repo.revisions.keys()
65
        repo.inventories.keys()
66
        # server repo is the instance a smart server might hold for this
67
        # repository.
68
        server_repo = repo.bzrdir.open_repository()
69
        try:
70
            server_repo.lock_write(token)
71
        except errors.TokenLockingNotSupported:
72
            raise TestSkipped('Cannot concurrently insert into repo format %r'
73
                % self.repository_format)
74
        try:
75
            server_repo.fetch(source.branch.repository, revid)
76
        finally:
77
            server_repo.unlock()
78
        repo.refresh_data()
79
        self.assertNotEqual({}, repo.get_graph().get_parent_map([revid]))