~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository_vf/test_refresh_data.py

(jelmer) Add stub for ControlDir.find_branch_format,
 fix some tests against foreign formats. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011 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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Tests for VersionedFileRepository.refresh_data."""
 
18
 
 
19
from bzrlib import repository
 
20
 
 
21
from bzrlib.tests.per_repository_vf import (
 
22
    TestCaseWithRepository,
 
23
    all_repository_vf_format_scenarios,
 
24
    )
 
25
from bzrlib.tests.scenarios import load_tests_apply_scenarios
 
26
 
 
27
load_tests = load_tests_apply_scenarios
 
28
 
 
29
 
 
30
class TestRefreshData(TestCaseWithRepository):
 
31
 
 
32
    scenarios = all_repository_vf_format_scenarios()
 
33
 
 
34
    def fetch_new_revision_into_concurrent_instance(self, repo, token):
 
35
        """Create a new revision (revid 'new-rev') and fetch it into a
 
36
        concurrent instance of repo.
 
37
        """
 
38
        source = self.make_branch_and_memory_tree('source')
 
39
        source.lock_write()
 
40
        self.addCleanup(source.unlock)
 
41
        source.add([''], ['root-id'])
 
42
        revid = source.commit('foo', rev_id='new-rev')
 
43
        # Force data reading on weaves/knits
 
44
        repo.all_revision_ids()
 
45
        repo.revisions.keys()
 
46
        repo.inventories.keys()
 
47
        # server repo is the instance a smart server might hold for this
 
48
        # repository.
 
49
        server_repo = repo.bzrdir.open_repository()
 
50
        try:
 
51
            server_repo.lock_write(token)
 
52
        except errors.TokenLockingNotSupported:
 
53
            raise TestSkipped('Cannot concurrently insert into repo format %r'
 
54
                % self.repository_format)
 
55
        try:
 
56
            server_repo.fetch(source.branch.repository, revid)
 
57
        finally:
 
58
            server_repo.unlock()
 
59
 
 
60
    def test_refresh_data_after_fetch_new_data_visible_in_write_group(self):
 
61
        tree = self.make_branch_and_memory_tree('target')
 
62
        tree.lock_write()
 
63
        self.addCleanup(tree.unlock)
 
64
        tree.add([''], ['root-id'])
 
65
        tree.commit('foo', rev_id='commit-in-target')
 
66
        repo = tree.branch.repository
 
67
        token = repo.lock_write().repository_token
 
68
        self.addCleanup(repo.unlock)
 
69
        repo.start_write_group()
 
70
        self.addCleanup(repo.abort_write_group)
 
71
        self.fetch_new_revision_into_concurrent_instance(repo, token)
 
72
        # Call refresh_data.  It either fails with IsInWriteGroupError, or it
 
73
        # succeeds and the new revisions are visible.
 
74
        try:
 
75
            repo.refresh_data()
 
76
        except repository.IsInWriteGroupError:
 
77
            pass
 
78
        else:
 
79
            self.assertEqual(
 
80
                ['commit-in-target', 'new-rev'],
 
81
                sorted(repo.all_revision_ids()))
 
82
 
 
83
    def test_refresh_data_after_fetch_new_data_visible(self):
 
84
        repo = self.make_repository('target')
 
85
        token = repo.lock_write().repository_token
 
86
        self.addCleanup(repo.unlock)
 
87
        self.fetch_new_revision_into_concurrent_instance(repo, token)
 
88
        repo.refresh_data()
 
89
        self.assertNotEqual({}, repo.get_graph().get_parent_map(['new-rev']))
 
90
 
 
91