1
# Copyright (C) 2011 Canonical Ltd
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.
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.
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
17
"""Tests for VersionedFileRepository.refresh_data."""
19
from bzrlib import repository
21
from bzrlib.tests.per_repository_vf import (
22
TestCaseWithRepository,
23
all_repository_vf_format_scenarios,
25
from bzrlib.tests.scenarios import load_tests_apply_scenarios
27
load_tests = load_tests_apply_scenarios
30
class TestRefreshData(TestCaseWithRepository):
32
scenarios = all_repository_vf_format_scenarios()
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.
38
source = self.make_branch_and_memory_tree('source')
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()
46
repo.inventories.keys()
47
# server repo is the instance a smart server might hold for this
49
server_repo = repo.bzrdir.open_repository()
51
server_repo.lock_write(token)
52
except errors.TokenLockingNotSupported:
53
raise TestSkipped('Cannot concurrently insert into repo format %r'
54
% self.repository_format)
56
server_repo.fetch(source.branch.repository, revid)
60
def test_refresh_data_after_fetch_new_data_visible_in_write_group(self):
61
tree = self.make_branch_and_memory_tree('target')
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.
76
except repository.IsInWriteGroupError:
80
['commit-in-target', 'new-rev'],
81
sorted(repo.all_revision_ids()))
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)
89
self.assertNotEqual({}, repo.get_graph().get_parent_map(['new-rev']))