53
60
RemoteRepositoryFormat,
55
from bzrlib.repofmt import groupcompress_repo, pack_repo
56
from bzrlib.revision import NULL_REVISION
57
from bzrlib.smart import medium
62
from bzrlib.repofmt import groupcompress_repo, knitpack_repo
63
from bzrlib.revision import (
67
from bzrlib.smart import medium, request
58
68
from bzrlib.smart.client import _SmartClient
59
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
69
from bzrlib.smart.repository import (
70
SmartServerRepositoryGetParentMap,
71
SmartServerRepositoryGetStream_1_19,
72
_stream_to_byte_stream,
74
from bzrlib.symbol_versioning import deprecated_in
60
75
from bzrlib.tests import (
62
split_suite_by_condition,
66
from bzrlib.transport import get_transport
78
from bzrlib.tests.scenarios import load_tests_apply_scenarios
67
79
from bzrlib.transport.memory import MemoryTransport
68
80
from bzrlib.transport.remote import (
70
82
RemoteSSHTransport,
71
83
RemoteTCPTransport,
74
def load_tests(standard_tests, module, loader):
75
to_adapt, result = split_suite_by_condition(
76
standard_tests, condition_isinstance(BasicRemoteObjectTests))
77
smart_server_version_scenarios = [
87
load_tests = load_tests_apply_scenarios
90
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
79
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
94
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
81
{'transport_server': test_server.SmartTCPServer_for_testing})]
82
return multiply_tests(to_adapt, smart_server_version_scenarios, result)
85
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
96
{'transport_server': test_server.SmartTCPServer_for_testing})]
88
100
super(BasicRemoteObjectTests, self).setUp()
89
101
self.transport = self.get_transport()
90
102
# make a branch that can be opened over the smart transport
91
103
self.local_wt = BzrDir.create_standalone_workingtree('.')
94
self.transport.disconnect()
95
tests.TestCaseWithTransport.tearDown(self)
104
self.addCleanup(self.transport.disconnect)
97
106
def test_create_remote_bzrdir(self):
98
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
107
b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
99
108
self.assertIsInstance(b, BzrDir)
101
110
def test_open_remote_branch(self):
102
111
# open a standalone branch in the working directory
103
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
112
b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
104
113
branch = b.open_branch()
105
114
self.assertIsInstance(branch, Branch)
480
491
self.assertEqual(None, result._branch_format)
481
492
self.assertFinished(client)
494
def test_unknown(self):
495
transport = self.get_transport('quack')
496
referenced = self.make_branch('referenced')
497
expected = referenced.bzrdir.cloning_metadir()
498
client = FakeClient(transport.base)
499
client.add_expected_call(
500
'BzrDir.cloning_metadir', ('quack/', 'False'),
501
'success', ('unknown', 'unknown', ('branch', ''))),
502
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
504
self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
507
class TestBzrDirCheckoutMetaDir(TestRemote):
509
def test__get_checkout_format(self):
510
transport = MemoryTransport()
511
client = FakeClient(transport.base)
512
reference_bzrdir_format = bzrdir.format_registry.get('default')()
513
control_name = reference_bzrdir_format.network_name()
514
client.add_expected_call(
515
'BzrDir.checkout_metadir', ('quack/', ),
516
'success', (control_name, '', ''))
517
transport.mkdir('quack')
518
transport = transport.clone('quack')
519
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
521
result = a_bzrdir.checkout_metadir()
522
# We should have got a reference control dir with default branch and
523
# repository formats.
524
self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
525
self.assertEqual(None, result._repository_format)
526
self.assertEqual(None, result._branch_format)
527
self.assertFinished(client)
529
def test_unknown_format(self):
530
transport = MemoryTransport()
531
client = FakeClient(transport.base)
532
client.add_expected_call(
533
'BzrDir.checkout_metadir', ('quack/',),
534
'success', ('dontknow', '', ''))
535
transport.mkdir('quack')
536
transport = transport.clone('quack')
537
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
539
self.assertRaises(errors.UnknownFormatError,
540
a_bzrdir.checkout_metadir)
541
self.assertFinished(client)
544
class TestBzrDirGetBranches(TestRemote):
546
def test_get_branches(self):
547
transport = MemoryTransport()
548
client = FakeClient(transport.base)
549
reference_bzrdir_format = bzrdir.format_registry.get('default')()
550
branch_name = reference_bzrdir_format.get_branch_format().network_name()
551
client.add_success_response_with_body(
553
"foo": ("branch", branch_name),
554
"": ("branch", branch_name)}), "success")
555
client.add_success_response(
556
'ok', '', 'no', 'no', 'no',
557
reference_bzrdir_format.repository_format.network_name())
558
client.add_error_response('NotStacked')
559
client.add_success_response(
560
'ok', '', 'no', 'no', 'no',
561
reference_bzrdir_format.repository_format.network_name())
562
client.add_error_response('NotStacked')
563
transport.mkdir('quack')
564
transport = transport.clone('quack')
565
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
567
result = a_bzrdir.get_branches()
568
self.assertEquals(set(["", "foo"]), set(result.keys()))
570
[('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
571
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
572
('call', 'Branch.get_stacked_on_url', ('quack/', )),
573
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
574
('call', 'Branch.get_stacked_on_url', ('quack/', ))],
578
class TestBzrDirDestroyBranch(TestRemote):
580
def test_destroy_default(self):
581
transport = self.get_transport('quack')
582
referenced = self.make_branch('referenced')
583
client = FakeClient(transport.base)
584
client.add_expected_call(
585
'BzrDir.destroy_branch', ('quack/', ),
587
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
589
a_bzrdir.destroy_branch()
590
self.assertFinished(client)
593
class TestBzrDirHasWorkingTree(TestRemote):
595
def test_has_workingtree(self):
596
transport = self.get_transport('quack')
597
client = FakeClient(transport.base)
598
client.add_expected_call(
599
'BzrDir.has_workingtree', ('quack/',),
600
'success', ('yes',)),
601
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
603
self.assertTrue(a_bzrdir.has_workingtree())
604
self.assertFinished(client)
606
def test_no_workingtree(self):
607
transport = self.get_transport('quack')
608
client = FakeClient(transport.base)
609
client.add_expected_call(
610
'BzrDir.has_workingtree', ('quack/',),
612
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
614
self.assertFalse(a_bzrdir.has_workingtree())
615
self.assertFinished(client)
618
class TestBzrDirDestroyRepository(TestRemote):
620
def test_destroy_repository(self):
621
transport = self.get_transport('quack')
622
client = FakeClient(transport.base)
623
client.add_expected_call(
624
'BzrDir.destroy_repository', ('quack/',),
626
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
628
a_bzrdir.destroy_repository()
629
self.assertFinished(client)
484
632
class TestBzrDirOpen(TestRemote):
967
1147
return RemoteBranch(bzrdir, repo, _client=client, format=format)
1150
class TestBranchBreakLock(RemoteBranchTestCase):
1152
def test_break_lock(self):
1153
transport_path = 'quack'
1154
transport = MemoryTransport()
1155
client = FakeClient(transport.base)
1156
client.add_expected_call(
1157
'Branch.get_stacked_on_url', ('quack/',),
1158
'error', ('NotStacked',))
1159
client.add_expected_call(
1160
'Branch.break_lock', ('quack/',),
1162
transport.mkdir('quack')
1163
transport = transport.clone('quack')
1164
branch = self.make_remote_branch(transport, client)
1166
self.assertFinished(client)
1169
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1171
def test_get_physical_lock_status_yes(self):
1172
transport = MemoryTransport()
1173
client = FakeClient(transport.base)
1174
client.add_expected_call(
1175
'Branch.get_stacked_on_url', ('quack/',),
1176
'error', ('NotStacked',))
1177
client.add_expected_call(
1178
'Branch.get_physical_lock_status', ('quack/',),
1179
'success', ('yes',))
1180
transport.mkdir('quack')
1181
transport = transport.clone('quack')
1182
branch = self.make_remote_branch(transport, client)
1183
result = branch.get_physical_lock_status()
1184
self.assertFinished(client)
1185
self.assertEqual(True, result)
1187
def test_get_physical_lock_status_no(self):
1188
transport = MemoryTransport()
1189
client = FakeClient(transport.base)
1190
client.add_expected_call(
1191
'Branch.get_stacked_on_url', ('quack/',),
1192
'error', ('NotStacked',))
1193
client.add_expected_call(
1194
'Branch.get_physical_lock_status', ('quack/',),
1196
transport.mkdir('quack')
1197
transport = transport.clone('quack')
1198
branch = self.make_remote_branch(transport, client)
1199
result = branch.get_physical_lock_status()
1200
self.assertFinished(client)
1201
self.assertEqual(False, result)
970
1204
class TestBranchGetParent(RemoteBranchTestCase):
972
1206
def test_no_parent(self):
1143
1377
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1380
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1382
def test_uses_last_revision_info_and_tags_by_default(self):
1383
transport = MemoryTransport()
1384
client = FakeClient(transport.base)
1385
client.add_expected_call(
1386
'Branch.get_stacked_on_url', ('quack/',),
1387
'error', ('NotStacked',))
1388
client.add_expected_call(
1389
'Branch.last_revision_info', ('quack/',),
1390
'success', ('ok', '1', 'rev-tip'))
1391
client.add_expected_call(
1392
'Branch.get_config_file', ('quack/',),
1393
'success', ('ok',), '')
1394
transport.mkdir('quack')
1395
transport = transport.clone('quack')
1396
branch = self.make_remote_branch(transport, client)
1397
result = branch.heads_to_fetch()
1398
self.assertFinished(client)
1399
self.assertEqual((set(['rev-tip']), set()), result)
1401
def test_uses_last_revision_info_and_tags_when_set(self):
1402
transport = MemoryTransport()
1403
client = FakeClient(transport.base)
1404
client.add_expected_call(
1405
'Branch.get_stacked_on_url', ('quack/',),
1406
'error', ('NotStacked',))
1407
client.add_expected_call(
1408
'Branch.last_revision_info', ('quack/',),
1409
'success', ('ok', '1', 'rev-tip'))
1410
client.add_expected_call(
1411
'Branch.get_config_file', ('quack/',),
1412
'success', ('ok',), 'branch.fetch_tags = True')
1413
# XXX: this will break if the default format's serialization of tags
1414
# changes, or if the RPC for fetching tags changes from get_tags_bytes.
1415
client.add_expected_call(
1416
'Branch.get_tags_bytes', ('quack/',),
1417
'success', ('d5:tag-17:rev-foo5:tag-27:rev-bare',))
1418
transport.mkdir('quack')
1419
transport = transport.clone('quack')
1420
branch = self.make_remote_branch(transport, client)
1421
result = branch.heads_to_fetch()
1422
self.assertFinished(client)
1424
(set(['rev-tip']), set(['rev-foo', 'rev-bar'])), result)
1426
def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1427
transport = MemoryTransport()
1428
client = FakeClient(transport.base)
1429
client.add_expected_call(
1430
'Branch.get_stacked_on_url', ('quack/',),
1431
'error', ('NotStacked',))
1432
client.add_expected_call(
1433
'Branch.heads_to_fetch', ('quack/',),
1434
'success', (['tip'], ['tagged-1', 'tagged-2']))
1435
transport.mkdir('quack')
1436
transport = transport.clone('quack')
1437
branch = self.make_remote_branch(transport, client)
1438
branch._format._use_default_local_heads_to_fetch = lambda: False
1439
result = branch.heads_to_fetch()
1440
self.assertFinished(client)
1441
self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1443
def make_branch_with_tags(self):
1444
self.setup_smart_server_with_call_log()
1445
# Make a branch with a single revision.
1446
builder = self.make_branch_builder('foo')
1447
builder.start_series()
1448
builder.build_snapshot('tip', None, [
1449
('add', ('', 'root-id', 'directory', ''))])
1450
builder.finish_series()
1451
branch = builder.get_branch()
1452
# Add two tags to that branch
1453
branch.tags.set_tag('tag-1', 'rev-1')
1454
branch.tags.set_tag('tag-2', 'rev-2')
1457
def test_backwards_compatible(self):
1458
branch = self.make_branch_with_tags()
1459
c = branch.get_config_stack()
1460
c.set('branch.fetch_tags', True)
1461
self.addCleanup(branch.lock_read().unlock)
1462
# Disable the heads_to_fetch verb
1463
verb = 'Branch.heads_to_fetch'
1464
self.disable_verb(verb)
1465
self.reset_smart_call_log()
1466
result = branch.heads_to_fetch()
1467
self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1469
['Branch.last_revision_info', 'Branch.get_config_file',
1470
'Branch.get_tags_bytes'],
1471
[call.call.method for call in self.hpss_calls])
1473
def test_backwards_compatible_no_tags(self):
1474
branch = self.make_branch_with_tags()
1475
c = branch.get_config_stack()
1476
c.set('branch.fetch_tags', False)
1477
self.addCleanup(branch.lock_read().unlock)
1478
# Disable the heads_to_fetch verb
1479
verb = 'Branch.heads_to_fetch'
1480
self.disable_verb(verb)
1481
self.reset_smart_call_log()
1482
result = branch.heads_to_fetch()
1483
self.assertEqual((set(['tip']), set()), result)
1485
['Branch.last_revision_info', 'Branch.get_config_file'],
1486
[call.call.method for call in self.hpss_calls])
1146
1489
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1148
1491
def test_empty_branch(self):
1661
2024
self.addCleanup(branch.unlock)
1662
2025
self.reset_smart_call_log()
1663
2026
branch._get_config().set_option('value', 'name')
1664
self.assertLength(10, self.hpss_calls)
2027
self.assertLength(11, self.hpss_calls)
1665
2028
self.assertEqual('value', branch._get_config().get_option('name'))
2030
def test_backwards_compat_set_option_with_dict(self):
2031
self.setup_smart_server_with_call_log()
2032
branch = self.make_branch('.')
2033
verb = 'Branch.set_config_option_dict'
2034
self.disable_verb(verb)
2036
self.addCleanup(branch.unlock)
2037
self.reset_smart_call_log()
2038
config = branch._get_config()
2039
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
2040
config.set_option(value_dict, 'name')
2041
self.assertLength(11, self.hpss_calls)
2042
self.assertEqual(value_dict, branch._get_config().get_option('name'))
2045
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
2047
def test_get_branch_conf(self):
2048
# in an empty branch we decode the response properly
2049
client = FakeClient()
2050
client.add_expected_call(
2051
'Branch.get_stacked_on_url', ('memory:///',),
2052
'error', ('NotStacked',),)
2053
client.add_success_response_with_body('# config file body', 'ok')
2054
transport = MemoryTransport()
2055
branch = self.make_remote_branch(transport, client)
2056
config = branch.get_config_stack()
2058
config.get("log_format")
2060
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2061
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
2064
def test_set_branch_conf(self):
2065
client = FakeClient()
2066
client.add_expected_call(
2067
'Branch.get_stacked_on_url', ('memory:///',),
2068
'error', ('NotStacked',),)
2069
client.add_expected_call(
2070
'Branch.lock_write', ('memory:///', '', ''),
2071
'success', ('ok', 'branch token', 'repo token'))
2072
client.add_expected_call(
2073
'Branch.get_config_file', ('memory:///', ),
2074
'success', ('ok', ), "# line 1\n")
2075
client.add_expected_call(
2076
'Branch.put_config_file', ('memory:///', 'branch token',
2079
client.add_expected_call(
2080
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2082
transport = MemoryTransport()
2083
branch = self.make_remote_branch(transport, client)
2085
config = branch.get_config_stack()
2086
config.set('email', 'The Dude <lebowski@example.com>')
2088
self.assertFinished(client)
2090
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2091
('call', 'Branch.lock_write', ('memory:///', '', '')),
2092
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2093
('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2094
('memory:///', 'branch token', 'repo token'),
2095
'# line 1\nemail = The Dude <lebowski@example.com>\n'),
2096
('call', 'Branch.unlock', ('memory:///', 'branch token', 'repo token'))],
1668
2100
class TestBranchLockWrite(RemoteBranchTestCase):
1683
2115
self.assertFinished(client)
2118
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2120
def test_simple(self):
2121
transport = MemoryTransport()
2122
client = FakeClient(transport.base)
2123
client.add_expected_call(
2124
'Branch.get_stacked_on_url', ('quack/',),
2125
'error', ('NotStacked',),)
2126
client.add_expected_call(
2127
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2128
'success', ('ok', '0',),)
2129
client.add_expected_call(
2130
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2131
'error', ('NoSuchRevision', 'unknown',),)
2132
transport.mkdir('quack')
2133
transport = transport.clone('quack')
2134
branch = self.make_remote_branch(transport, client)
2135
self.assertEquals(0, branch.revision_id_to_revno('null:'))
2136
self.assertRaises(errors.NoSuchRevision,
2137
branch.revision_id_to_revno, 'unknown')
2138
self.assertFinished(client)
2140
def test_dotted(self):
2141
transport = MemoryTransport()
2142
client = FakeClient(transport.base)
2143
client.add_expected_call(
2144
'Branch.get_stacked_on_url', ('quack/',),
2145
'error', ('NotStacked',),)
2146
client.add_expected_call(
2147
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2148
'success', ('ok', '0',),)
2149
client.add_expected_call(
2150
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2151
'error', ('NoSuchRevision', 'unknown',),)
2152
transport.mkdir('quack')
2153
transport = transport.clone('quack')
2154
branch = self.make_remote_branch(transport, client)
2155
self.assertEquals((0, ), branch.revision_id_to_dotted_revno('null:'))
2156
self.assertRaises(errors.NoSuchRevision,
2157
branch.revision_id_to_dotted_revno, 'unknown')
2158
self.assertFinished(client)
2160
def test_dotted_no_smart_verb(self):
2161
self.setup_smart_server_with_call_log()
2162
branch = self.make_branch('.')
2163
self.disable_verb('Branch.revision_id_to_revno')
2164
self.reset_smart_call_log()
2165
self.assertEquals((0, ),
2166
branch.revision_id_to_dotted_revno('null:'))
2167
self.assertLength(8, self.hpss_calls)
1686
2170
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1688
2172
def test__get_config(self):
2415
class TestRepositoryBreakLock(TestRemoteRepository):
2417
def test_break_lock(self):
2418
transport_path = 'quack'
2419
repo, client = self.setup_fake_client_and_repository(transport_path)
2420
client.add_success_response('ok')
2423
[('call', 'Repository.break_lock', ('quack/',))],
2427
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2429
def test_get_serializer_format(self):
2430
transport_path = 'hill'
2431
repo, client = self.setup_fake_client_and_repository(transport_path)
2432
client.add_success_response('ok', '7')
2433
self.assertEquals('7', repo.get_serializer_format())
2435
[('call', 'VersionedFileRepository.get_serializer_format',
2440
class TestRepositoryReconcile(TestRemoteRepository):
2442
def test_reconcile(self):
2443
transport_path = 'hill'
2444
repo, client = self.setup_fake_client_and_repository(transport_path)
2445
body = ("garbage_inventories: 2\n"
2446
"inconsistent_parents: 3\n")
2447
client.add_expected_call(
2448
'Repository.lock_write', ('hill/', ''),
2449
'success', ('ok', 'a token'))
2450
client.add_success_response_with_body(body, 'ok')
2451
reconciler = repo.reconcile()
2453
[('call', 'Repository.lock_write', ('hill/', '')),
2454
('call_expecting_body', 'Repository.reconcile',
2455
('hill/', 'a token'))],
2457
self.assertEquals(2, reconciler.garbage_inventories)
2458
self.assertEquals(3, reconciler.inconsistent_parents)
2461
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2463
def test_text(self):
2464
# ('ok',), body with signature text
2465
transport_path = 'quack'
2466
repo, client = self.setup_fake_client_and_repository(transport_path)
2467
client.add_success_response_with_body(
2469
self.assertEquals("THETEXT", repo.get_signature_text("revid"))
2471
[('call_expecting_body', 'Repository.get_revision_signature_text',
2472
('quack/', 'revid'))],
2475
def test_no_signature(self):
2476
transport_path = 'quick'
2477
repo, client = self.setup_fake_client_and_repository(transport_path)
2478
client.add_error_response('nosuchrevision', 'unknown')
2479
self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2482
[('call_expecting_body', 'Repository.get_revision_signature_text',
2483
('quick/', 'unknown'))],
1906
2487
class TestRepositoryGetGraph(TestRemoteRepository):
1908
2489
def test_get_graph(self):
3078
class TestRepositoryWriteGroups(TestRemoteRepository):
3080
def test_start_write_group(self):
3081
transport_path = 'quack'
3082
repo, client = self.setup_fake_client_and_repository(transport_path)
3083
client.add_expected_call(
3084
'Repository.lock_write', ('quack/', ''),
3085
'success', ('ok', 'a token'))
3086
client.add_expected_call(
3087
'Repository.start_write_group', ('quack/', 'a token'),
3088
'success', ('ok', ('token1', )))
3090
repo.start_write_group()
3092
def test_start_write_group_unsuspendable(self):
3093
# Some repositories do not support suspending write
3094
# groups. For those, fall back to the "real" repository.
3095
transport_path = 'quack'
3096
repo, client = self.setup_fake_client_and_repository(transport_path)
3097
def stub_ensure_real():
3098
client._calls.append(('_ensure_real',))
3099
repo._real_repository = _StubRealPackRepository(client._calls)
3100
repo._ensure_real = stub_ensure_real
3101
client.add_expected_call(
3102
'Repository.lock_write', ('quack/', ''),
3103
'success', ('ok', 'a token'))
3104
client.add_expected_call(
3105
'Repository.start_write_group', ('quack/', 'a token'),
3106
'error', ('UnsuspendableWriteGroup',))
3108
repo.start_write_group()
3109
self.assertEquals(client._calls[-2:], [
3111
('start_write_group',)])
3113
def test_commit_write_group(self):
3114
transport_path = 'quack'
3115
repo, client = self.setup_fake_client_and_repository(transport_path)
3116
client.add_expected_call(
3117
'Repository.lock_write', ('quack/', ''),
3118
'success', ('ok', 'a token'))
3119
client.add_expected_call(
3120
'Repository.start_write_group', ('quack/', 'a token'),
3121
'success', ('ok', ['token1']))
3122
client.add_expected_call(
3123
'Repository.commit_write_group', ('quack/', 'a token', ['token1']),
3126
repo.start_write_group()
3127
repo.commit_write_group()
3129
def test_abort_write_group(self):
3130
transport_path = 'quack'
3131
repo, client = self.setup_fake_client_and_repository(transport_path)
3132
client.add_expected_call(
3133
'Repository.lock_write', ('quack/', ''),
3134
'success', ('ok', 'a token'))
3135
client.add_expected_call(
3136
'Repository.start_write_group', ('quack/', 'a token'),
3137
'success', ('ok', ['token1']))
3138
client.add_expected_call(
3139
'Repository.abort_write_group', ('quack/', 'a token', ['token1']),
3142
repo.start_write_group()
3143
repo.abort_write_group(False)
3145
def test_suspend_write_group(self):
3146
transport_path = 'quack'
3147
repo, client = self.setup_fake_client_and_repository(transport_path)
3148
self.assertEquals([], repo.suspend_write_group())
3150
def test_resume_write_group(self):
3151
transport_path = 'quack'
3152
repo, client = self.setup_fake_client_and_repository(transport_path)
3153
client.add_expected_call(
3154
'Repository.lock_write', ('quack/', ''),
3155
'success', ('ok', 'a token'))
3156
client.add_expected_call(
3157
'Repository.check_write_group', ('quack/', 'a token', ['token1']),
3160
repo.resume_write_group(['token1'])
2329
3163
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
2331
3165
def test_backwards_compat(self):
2895
3783
expected_error = errors.PermissionDenied(path, extra)
2896
3784
self.assertEqual(expected_error, translated_error)
3786
# GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3788
def test_NoSuchFile_context_path(self):
3789
local_path = "local path"
3790
translated_error = self.translateTuple(('ReadError', "remote path"),
3792
expected_error = errors.ReadError(local_path)
3793
self.assertEqual(expected_error, translated_error)
3795
def test_NoSuchFile_without_context(self):
3796
remote_path = "remote path"
3797
translated_error = self.translateTuple(('ReadError', remote_path))
3798
expected_error = errors.ReadError(remote_path)
3799
self.assertEqual(expected_error, translated_error)
3801
def test_ReadOnlyError(self):
3802
translated_error = self.translateTuple(('ReadOnlyError',))
3803
expected_error = errors.TransportNotPossible("readonly transport")
3804
self.assertEqual(expected_error, translated_error)
3806
def test_MemoryError(self):
3807
translated_error = self.translateTuple(('MemoryError',))
3808
self.assertStartsWith(str(translated_error),
3809
"remote server out of memory")
3811
def test_generic_IndexError_no_classname(self):
3812
err = errors.ErrorFromSmartServer(('error', "list index out of range"))
3813
translated_error = self.translateErrorFromSmartServer(err)
3814
expected_error = errors.UnknownErrorFromSmartServer(err)
3815
self.assertEqual(expected_error, translated_error)
3817
# GZ 2011-03-02: TODO test generic non-ascii error string
3819
def test_generic_KeyError(self):
3820
err = errors.ErrorFromSmartServer(('error', 'KeyError', "1"))
3821
translated_error = self.translateErrorFromSmartServer(err)
3822
expected_error = errors.UnknownErrorFromSmartServer(err)
3823
self.assertEqual(expected_error, translated_error)
2899
3826
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2900
3827
"""Unit tests for bzrlib.remote._translate_error's robustness.
3143
4072
def test_copy_content_into_avoids_revision_history(self):
3144
4073
local = self.make_branch('local')
3145
remote_backing_tree = self.make_branch_and_tree('remote')
3146
remote_backing_tree.commit("Commit.")
4074
builder = self.make_branch_builder('remote')
4075
builder.build_commit(message="Commit.")
3147
4076
remote_branch_url = self.smart_server.get_url() + 'remote'
3148
4077
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3149
4078
local.repository.fetch(remote_branch.repository)
3150
4079
self.hpss_calls = []
3151
4080
remote_branch.copy_content_into(local)
3152
4081
self.assertFalse('Branch.revision_history' in self.hpss_calls)
4083
def test_fetch_everything_needs_just_one_call(self):
4084
local = self.make_branch('local')
4085
builder = self.make_branch_builder('remote')
4086
builder.build_commit(message="Commit.")
4087
remote_branch_url = self.smart_server.get_url() + 'remote'
4088
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4089
self.hpss_calls = []
4090
local.repository.fetch(
4091
remote_branch.repository,
4092
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4093
self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
4095
def override_verb(self, verb_name, verb):
4096
request_handlers = request.request_handlers
4097
orig_verb = request_handlers.get(verb_name)
4098
orig_info = request_handlers.get_info(verb_name)
4099
request_handlers.register(verb_name, verb, override_existing=True)
4100
self.addCleanup(request_handlers.register, verb_name, orig_verb,
4101
override_existing=True, info=orig_info)
4103
def test_fetch_everything_backwards_compat(self):
4104
"""Can fetch with EverythingResult even with pre 2.4 servers.
4106
Pre-2.4 do not support 'everything' searches with the
4107
Repository.get_stream_1.19 verb.
4110
class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
4111
"""A version of the Repository.get_stream_1.19 verb patched to
4112
reject 'everything' searches the way 2.3 and earlier do.
4114
def recreate_search(self, repository, search_bytes,
4115
discard_excess=False):
4116
verb_log.append(search_bytes.split('\n', 1)[0])
4117
if search_bytes == 'everything':
4119
request.FailedSmartServerResponse(('BadSearch',)))
4120
return super(OldGetStreamVerb,
4121
self).recreate_search(repository, search_bytes,
4122
discard_excess=discard_excess)
4123
self.override_verb('Repository.get_stream_1.19', OldGetStreamVerb)
4124
local = self.make_branch('local')
4125
builder = self.make_branch_builder('remote')
4126
builder.build_commit(message="Commit.")
4127
remote_branch_url = self.smart_server.get_url() + 'remote'
4128
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4129
self.hpss_calls = []
4130
local.repository.fetch(
4131
remote_branch.repository,
4132
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4133
# make sure the overridden verb was used
4134
self.assertLength(1, verb_log)
4135
# more than one HPSS call is needed, but because it's a VFS callback
4136
# its hard to predict exactly how many.
4137
self.assertTrue(len(self.hpss_calls) > 1)
4140
class TestUpdateBoundBranchWithModifiedBoundLocation(
4141
tests.TestCaseWithTransport):
4142
"""Ensure correct handling of bound_location modifications.
4144
This is tested against a smart server as http://pad.lv/786980 was about a
4145
ReadOnlyError (write attempt during a read-only transaction) which can only
4146
happen in this context.
4150
super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
4151
self.transport_server = test_server.SmartTCPServer_for_testing
4153
def make_master_and_checkout(self, master_name, checkout_name):
4154
# Create the master branch and its associated checkout
4155
self.master = self.make_branch_and_tree(master_name)
4156
self.checkout = self.master.branch.create_checkout(checkout_name)
4157
# Modify the master branch so there is something to update
4158
self.master.commit('add stuff')
4159
self.last_revid = self.master.commit('even more stuff')
4160
self.bound_location = self.checkout.branch.get_bound_location()
4162
def assertUpdateSucceeds(self, new_location):
4163
self.checkout.branch.set_bound_location(new_location)
4164
self.checkout.update()
4165
self.assertEquals(self.last_revid, self.checkout.last_revision())
4167
def test_without_final_slash(self):
4168
self.make_master_and_checkout('master', 'checkout')
4169
# For unclear reasons some users have a bound_location without a final
4170
# '/', simulate that by forcing such a value
4171
self.assertEndsWith(self.bound_location, '/')
4172
self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
4174
def test_plus_sign(self):
4175
self.make_master_and_checkout('+master', 'checkout')
4176
self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
4178
def test_tilda(self):
4179
# Embed ~ in the middle of the path just to avoid any $HOME
4181
self.make_master_and_checkout('mas~ter', 'checkout')
4182
self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4185
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4187
def test_no_context(self):
4188
class OutOfCoffee(errors.BzrError):
4189
"""A dummy exception for testing."""
4191
def __init__(self, urgency):
4192
self.urgency = urgency
4193
remote.no_context_error_translators.register("OutOfCoffee",
4194
lambda err: OutOfCoffee(err.error_args[0]))
4195
transport = MemoryTransport()
4196
client = FakeClient(transport.base)
4197
client.add_expected_call(
4198
'Branch.get_stacked_on_url', ('quack/',),
4199
'error', ('NotStacked',))
4200
client.add_expected_call(
4201
'Branch.last_revision_info',
4203
'error', ('OutOfCoffee', 'low'))
4204
transport.mkdir('quack')
4205
transport = transport.clone('quack')
4206
branch = self.make_remote_branch(transport, client)
4207
self.assertRaises(OutOfCoffee, branch.last_revision_info)
4208
self.assertFinished(client)
4210
def test_with_context(self):
4211
class OutOfTea(errors.BzrError):
4212
def __init__(self, branch, urgency):
4213
self.branch = branch
4214
self.urgency = urgency
4215
remote.error_translators.register("OutOfTea",
4216
lambda err, find, path: OutOfTea(err.error_args[0],
4218
transport = MemoryTransport()
4219
client = FakeClient(transport.base)
4220
client.add_expected_call(
4221
'Branch.get_stacked_on_url', ('quack/',),
4222
'error', ('NotStacked',))
4223
client.add_expected_call(
4224
'Branch.last_revision_info',
4226
'error', ('OutOfTea', 'low'))
4227
transport.mkdir('quack')
4228
transport = transport.clone('quack')
4229
branch = self.make_remote_branch(transport, client)
4230
self.assertRaises(OutOfTea, branch.last_revision_info)
4231
self.assertFinished(client)
4234
class TestRepositoryPack(TestRemoteRepository):
4236
def test_pack(self):
4237
transport_path = 'quack'
4238
repo, client = self.setup_fake_client_and_repository(transport_path)
4239
client.add_expected_call(
4240
'Repository.lock_write', ('quack/', ''),
4241
'success', ('ok', 'token'))
4242
client.add_expected_call(
4243
'Repository.pack', ('quack/', 'token', 'False'),
4244
'success', ('ok',), )
4245
client.add_expected_call(
4246
'Repository.unlock', ('quack/', 'token'),
4247
'success', ('ok', ))
4250
def test_pack_with_hint(self):
4251
transport_path = 'quack'
4252
repo, client = self.setup_fake_client_and_repository(transport_path)
4253
client.add_expected_call(
4254
'Repository.lock_write', ('quack/', ''),
4255
'success', ('ok', 'token'))
4256
client.add_expected_call(
4257
'Repository.pack', ('quack/', 'token', 'False'),
4258
'success', ('ok',), )
4259
client.add_expected_call(
4260
'Repository.unlock', ('quack/', 'token', 'False'),
4261
'success', ('ok', ))
4262
repo.pack(['hinta', 'hintb'])
4265
class TestRepositoryIterInventories(TestRemoteRepository):
4266
"""Test Repository.iter_inventories."""
4268
def _serialize_inv_delta(self, old_name, new_name, delta):
4269
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4270
return "".join(serializer.delta_to_lines(old_name, new_name, delta))
4272
def test_single_empty(self):
4273
transport_path = 'quack'
4274
repo, client = self.setup_fake_client_and_repository(transport_path)
4275
fmt = bzrdir.format_registry.get('2a')().repository_format
4277
stream = [('inventory-deltas', [
4278
versionedfile.FulltextContentFactory('somerevid', None, None,
4279
self._serialize_inv_delta('null:', 'somerevid', []))])]
4280
client.add_expected_call(
4281
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4282
'success', ('ok', ),
4283
_stream_to_byte_stream(stream, fmt))
4284
ret = list(repo.iter_inventories(["somerevid"]))
4285
self.assertLength(1, ret)
4287
self.assertEquals("somerevid", inv.revision_id)
4289
def test_empty(self):
4290
transport_path = 'quack'
4291
repo, client = self.setup_fake_client_and_repository(transport_path)
4292
ret = list(repo.iter_inventories([]))
4293
self.assertEquals(ret, [])
4295
def test_missing(self):
4296
transport_path = 'quack'
4297
repo, client = self.setup_fake_client_and_repository(transport_path)
4298
client.add_expected_call(
4299
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4300
'success', ('ok', ), iter([]))
4301
self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(