5557.1.10
by John Arbash Meinel
Add StreamSink.insert_stream_without_locking |
1 |
# Copyright (C) 2007-2011 Canonical Ltd
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
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
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
16 |
|
17 |
"""Tests for repository write groups."""
|
|
18 |
||
4343.3.2
by John Arbash Meinel
All stacking tests seem to be passing for dev6 repos |
19 |
from bzrlib import ( |
20 |
errors, |
|
21 |
)
|
|
5017.3.43
by Vincent Ladeuil
-s bt.per_repository.test_write_group passing |
22 |
from bzrlib.tests import ( |
23 |
per_repository, |
|
24 |
test_server, |
|
25 |
)
|
|
5017.3.45
by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry. |
26 |
from bzrlib.transport import memory |
5010.2.7
by Vincent Ladeuil
Fix per_repository/test_write_group.py imports. |
27 |
|
28 |
||
29 |
class TestWriteGroup(per_repository.TestCaseWithRepository): |
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
30 |
|
31 |
def test_start_write_group_unlocked_needs_write_lock(self): |
|
32 |
repo = self.make_repository('.') |
|
33 |
self.assertRaises(errors.NotWriteLocked, repo.start_write_group) |
|
34 |
||
35 |
def test_start_write_group_read_locked_needs_write_lock(self): |
|
36 |
repo = self.make_repository('.') |
|
37 |
repo.lock_read() |
|
38 |
try: |
|
39 |
self.assertRaises(errors.NotWriteLocked, repo.start_write_group) |
|
40 |
finally: |
|
41 |
repo.unlock() |
|
42 |
||
43 |
def test_start_write_group_write_locked_gets_None(self): |
|
44 |
repo = self.make_repository('.') |
|
45 |
repo.lock_write() |
|
46 |
self.assertEqual(None, repo.start_write_group()) |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
47 |
repo.commit_write_group() |
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
48 |
repo.unlock() |
49 |
||
50 |
def test_start_write_group_twice_errors(self): |
|
51 |
repo = self.make_repository('.') |
|
52 |
repo.lock_write() |
|
53 |
repo.start_write_group() |
|
54 |
try: |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
55 |
# don't need a specific exception for now - this is
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
56 |
# really to be sure it's used right, not for signalling
|
57 |
# semantic information.
|
|
58 |
self.assertRaises(errors.BzrError, repo.start_write_group) |
|
59 |
finally: |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
60 |
repo.commit_write_group() |
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
61 |
repo.unlock() |
62 |
||
4431.3.7
by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts. |
63 |
def test_commit_write_group_does_not_error(self): |
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
64 |
repo = self.make_repository('.') |
65 |
repo.lock_write() |
|
66 |
repo.start_write_group() |
|
4431.3.7
by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts. |
67 |
# commit_write_group can either return None (for repositories without
|
68 |
# isolated transactions) or a hint for pack(). So we only check it
|
|
69 |
# works in this interface test, because all repositories are exercised.
|
|
70 |
repo.commit_write_group() |
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
71 |
repo.unlock() |
72 |
||
2592.3.242
by Martin Pool
New method TestCase.call_catch_warnings |
73 |
def test_unlock_in_write_group(self): |
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
74 |
repo = self.make_repository('.') |
75 |
repo.lock_write() |
|
76 |
repo.start_write_group() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
77 |
# don't need a specific exception for now - this is
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
78 |
# really to be sure it's used right, not for signalling
|
79 |
# semantic information.
|
|
4634.85.10
by Andrew Bennetts
Change test_unlock_in_write_group to expect a log_exception_quietly rather than a raise. |
80 |
self.assertLogsError(errors.BzrError, repo.unlock) |
2592.3.244
by Martin Pool
unlock while in a write group now aborts the write group, unlocks, and errors. |
81 |
# after this error occurs, the repository is unlocked, and the write
|
82 |
# group is gone. you've had your chance, and you blew it. ;-)
|
|
83 |
self.assertFalse(repo.is_locked()) |
|
84 |
self.assertRaises(errors.BzrError, repo.commit_write_group) |
|
85 |
self.assertRaises(errors.BzrError, repo.unlock) |
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
86 |
|
87 |
def test_is_in_write_group(self): |
|
88 |
repo = self.make_repository('.') |
|
89 |
self.assertFalse(repo.is_in_write_group()) |
|
90 |
repo.lock_write() |
|
91 |
repo.start_write_group() |
|
92 |
self.assertTrue(repo.is_in_write_group()) |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
93 |
repo.commit_write_group() |
94 |
self.assertFalse(repo.is_in_write_group()) |
|
95 |
# abort also removes the in_write_group status.
|
|
96 |
repo.start_write_group() |
|
97 |
self.assertTrue(repo.is_in_write_group()) |
|
98 |
repo.abort_write_group() |
|
99 |
self.assertFalse(repo.is_in_write_group()) |
|
100 |
repo.unlock() |
|
101 |
||
102 |
def test_abort_write_group_gets_None(self): |
|
103 |
repo = self.make_repository('.') |
|
104 |
repo.lock_write() |
|
105 |
repo.start_write_group() |
|
106 |
self.assertEqual(None, repo.abort_write_group()) |
|
2617.6.1
by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group`` |
107 |
repo.unlock() |
3825.4.1
by Andrew Bennetts
Add suppress_errors to abort_write_group. |
108 |
|
109 |
def test_abort_write_group_does_not_raise_when_suppressed(self): |
|
5017.3.43
by Vincent Ladeuil
-s bt.per_repository.test_write_group passing |
110 |
if self.transport_server is test_server.LocalURLServer: |
3825.4.3
by Andrew Bennetts
Conditionally replace LocalURLServer in the test rather than changing the default_transport behaviour of per_repository tests. |
111 |
self.transport_server = None |
5017.3.45
by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry. |
112 |
self.vfs_transport_factory = memory.MemoryServer |
3825.4.1
by Andrew Bennetts
Add suppress_errors to abort_write_group. |
113 |
repo = self.make_repository('repo') |
114 |
token = repo.lock_write() |
|
115 |
self.addCleanup(repo.unlock) |
|
116 |
repo.start_write_group() |
|
117 |
# Damage the repository on the filesystem
|
|
4327.1.9
by Vincent Ladeuil
Fix 4 more lock-related test failures. |
118 |
t = self.get_transport('') |
119 |
t.rename('repo', 'foo') |
|
120 |
self.addCleanup(t.rename, 'foo', 'repo') |
|
3825.4.1
by Andrew Bennetts
Add suppress_errors to abort_write_group. |
121 |
# abort_write_group will not raise an error, because either an
|
122 |
# exception was not generated, or the exception was caught and
|
|
123 |
# suppressed. See also test_pack_repository's test of the same name.
|
|
124 |
self.assertEqual(None, repo.abort_write_group(suppress_errors=True)) |