1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# Copyright (C) 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Tests for Repository.refresh_data."""
from bzrlib import (
errors,
repository,
)
from bzrlib.tests import TestSkipped
from bzrlib.tests.per_repository import TestCaseWithRepository
class TestRefreshData(TestCaseWithRepository):
def test_refresh_data_unlocked(self):
# While not interesting, it should not error.
repo = self.make_repository('.')
repo.refresh_data()
def test_refresh_data_read_locked(self):
# While not interesting, it should not error.
repo = self.make_repository('.')
repo.lock_read()
self.addCleanup(repo.unlock)
repo.refresh_data()
def test_refresh_data_write_locked(self):
# While not interesting, it should not error.
repo = self.make_repository('.')
repo.lock_write()
self.addCleanup(repo.unlock)
repo.refresh_data()
def test_refresh_data_in_write_group(self):
# refresh_data may either succeed or raise IsInWriteGroupError during a
# write group.
repo = self.make_repository('.')
repo.lock_write()
self.addCleanup(repo.unlock)
repo.start_write_group()
self.addCleanup(repo.abort_write_group)
try:
repo.refresh_data()
except repository.IsInWriteGroupError:
# This is ok.
pass
else:
# This is ok too.
pass
def fetch_new_revision_into_concurrent_instance(self, repo, token):
"""Create a new revision (revid 'new-rev') and fetch it into a
concurrent instance of repo.
"""
source = self.make_branch_and_memory_tree('source')
source.lock_write()
self.addCleanup(source.unlock)
source.add([''], ['root-id'])
revid = source.commit('foo', rev_id='new-rev')
# Force data reading on weaves/knits
repo.all_revision_ids()
repo.revisions.keys()
repo.inventories.keys()
# server repo is the instance a smart server might hold for this
# repository.
server_repo = repo.bzrdir.open_repository()
try:
server_repo.lock_write(token)
except errors.TokenLockingNotSupported:
raise TestSkipped('Cannot concurrently insert into repo format %r'
% self.repository_format)
try:
server_repo.fetch(source.branch.repository, revid)
finally:
server_repo.unlock()
def test_refresh_data_after_fetch_new_data_visible(self):
repo = self.make_repository('target')
token = repo.lock_write().repository_token
self.addCleanup(repo.unlock)
self.fetch_new_revision_into_concurrent_instance(repo, token)
repo.refresh_data()
self.assertNotEqual({}, repo.get_graph().get_parent_map(['new-rev']))
def test_refresh_data_after_fetch_new_data_visible_in_write_group(self):
tree = self.make_branch_and_memory_tree('target')
tree.lock_write()
self.addCleanup(tree.unlock)
tree.add([''], ['root-id'])
tree.commit('foo', rev_id='commit-in-target')
repo = tree.branch.repository
token = repo.lock_write().repository_token
self.addCleanup(repo.unlock)
repo.start_write_group()
self.addCleanup(repo.abort_write_group)
self.fetch_new_revision_into_concurrent_instance(repo, token)
# Call refresh_data. It either fails with IsInWriteGroupError, or it
# succeeds and the new revisions are visible.
try:
repo.refresh_data()
except repository.IsInWriteGroupError:
pass
else:
self.assertEqual(
['commit-in-target', 'new-rev'],
sorted(repo.all_revision_ids()))
|