1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
55
55
from bzrlib.repofmt import groupcompress_repo, pack_repo
56
56
from bzrlib.revision import NULL_REVISION
57
from bzrlib.smart import medium
57
from bzrlib.smart import server, medium
58
58
from bzrlib.smart.client import _SmartClient
59
59
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
60
60
from bzrlib.tests import (
61
61
condition_isinstance,
62
62
split_suite_by_condition,
66
65
from bzrlib.transport import get_transport
67
66
from bzrlib.transport.memory import MemoryTransport
76
75
standard_tests, condition_isinstance(BasicRemoteObjectTests))
77
76
smart_server_version_scenarios = [
79
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
78
{'transport_server': server.SmartTCPServer_for_testing_v2_only}),
81
{'transport_server': test_server.SmartTCPServer_for_testing})]
80
{'transport_server': server.SmartTCPServer_for_testing})]
82
81
return multiply_tests(to_adapt, smart_server_version_scenarios, result)
135
134
b = BzrDir.open_from_transport(self.transport).open_branch()
136
135
self.assertStartsWith(str(b), 'RemoteBranch(')
138
def test_remote_bzrdir_repr(self):
139
b = BzrDir.open_from_transport(self.transport)
140
self.assertStartsWith(str(b), 'RemoteBzrDir(')
142
137
def test_remote_branch_format_supports_stacking(self):
143
138
t = self.transport
144
139
self.make_branch('unstackable', format='pack-0.92')
418
413
# Calling _remember_remote_is_before again with a lower value works.
419
414
client_medium._remember_remote_is_before((1, 5))
420
415
self.assertTrue(client_medium._is_remote_before((1, 5)))
421
# If you call _remember_remote_is_before with a higher value it logs a
422
# warning, and continues to remember the lower value.
423
self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
424
client_medium._remember_remote_is_before((1, 9))
425
self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
426
self.assertTrue(client_medium._is_remote_before((1, 5)))
416
# You cannot call _remember_remote_is_before with a larger value.
418
AssertionError, client_medium._remember_remote_is_before, (1, 9))
429
421
class TestBzrDirCloningMetaDir(TestRemote):
448
440
'BzrDir.cloning_metadir', ('quack/', 'False'),
449
441
'error', ('BranchReference',)),
450
442
client.add_expected_call(
451
'BzrDir.open_branchV3', ('quack/',),
443
'BzrDir.open_branchV2', ('quack/',),
452
444
'success', ('ref', self.get_url('referenced'))),
453
445
a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
531
523
self.assertIsInstance(bd, RemoteBzrDir)
532
524
self.assertFinished(client)
534
def test_backwards_compat_hpss_v2(self):
535
client, transport = self.make_fake_client_and_transport()
536
# Monkey-patch fake client to simulate real-world behaviour with v2
537
# server: upon first RPC call detect the protocol version, and because
538
# the version is 2 also do _remember_remote_is_before((1, 6)) before
539
# continuing with the RPC.
540
orig_check_call = client._check_call
541
def check_call(method, args):
542
client._medium._protocol_version = 2
543
client._medium._remember_remote_is_before((1, 6))
544
client._check_call = orig_check_call
545
client._check_call(method, args)
546
client._check_call = check_call
547
client.add_expected_call(
548
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
549
client.add_expected_call(
550
'BzrDir.open', ('quack/',), 'success', ('yes',))
551
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
552
_client=client, _force_probe=True)
553
self.assertIsInstance(bd, RemoteBzrDir)
554
self.assertFinished(client)
557
527
class TestBzrDirOpenBranch(TestRemote):
561
531
self.make_branch('.')
562
532
a_dir = BzrDir.open(self.get_url('.'))
563
533
self.reset_smart_call_log()
564
verb = 'BzrDir.open_branchV3'
534
verb = 'BzrDir.open_branchV2'
565
535
self.disable_verb(verb)
566
536
format = a_dir.open_branch()
567
537
call_count = len([call for call in self.hpss_calls if
577
547
transport = transport.clone('quack')
578
548
client = FakeClient(transport.base)
579
549
client.add_expected_call(
580
'BzrDir.open_branchV3', ('quack/',),
550
'BzrDir.open_branchV2', ('quack/',),
581
551
'success', ('branch', branch_network_name))
582
552
client.add_expected_call(
583
553
'BzrDir.find_repositoryV3', ('quack/',),
603
573
self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
604
574
self.assertEqual(
605
[('call', 'BzrDir.open_branchV3', ('quack/',))],
575
[('call', 'BzrDir.open_branchV2', ('quack/',))],
608
578
def test__get_tree_branch(self):
632
602
network_name = reference_format.network_name()
633
603
branch_network_name = self.get_branch_format().network_name()
634
604
client.add_expected_call(
635
'BzrDir.open_branchV3', ('~hello/',),
605
'BzrDir.open_branchV2', ('~hello/',),
636
606
'success', ('branch', branch_network_name))
637
607
client.add_expected_call(
638
608
'BzrDir.find_repositoryV3', ('~hello/',),
1220
1190
client = FakeClient(self.get_url())
1221
1191
branch_network_name = self.get_branch_format().network_name()
1222
1192
client.add_expected_call(
1223
'BzrDir.open_branchV3', ('stacked/',),
1193
'BzrDir.open_branchV2', ('stacked/',),
1224
1194
'success', ('branch', branch_network_name))
1225
1195
client.add_expected_call(
1226
1196
'BzrDir.find_repositoryV3', ('stacked/',),
1248
1218
len(branch.repository._real_repository._fallback_repositories))
1250
1220
def test_get_stacked_on_real_branch(self):
1251
base_branch = self.make_branch('base')
1252
stacked_branch = self.make_branch('stacked')
1221
base_branch = self.make_branch('base', format='1.6')
1222
stacked_branch = self.make_branch('stacked', format='1.6')
1253
1223
stacked_branch.set_stacked_on_url('../base')
1254
1224
reference_format = self.get_repo_format()
1255
1225
network_name = reference_format.network_name()
1256
1226
client = FakeClient(self.get_url())
1257
1227
branch_network_name = self.get_branch_format().network_name()
1258
1228
client.add_expected_call(
1259
'BzrDir.open_branchV3', ('stacked/',),
1229
'BzrDir.open_branchV2', ('stacked/',),
1260
1230
'success', ('branch', branch_network_name))
1261
1231
client.add_expected_call(
1262
1232
'BzrDir.find_repositoryV3', ('stacked/',),
1263
'success', ('ok', '', 'yes', 'no', 'yes', network_name))
1233
'success', ('ok', '', 'no', 'no', 'yes', network_name))
1264
1234
# called twice, once from constructor and then again by us
1265
1235
client.add_expected_call(
1266
1236
'Branch.get_stacked_on_url', ('stacked/',),
2034
2004
self.assertLength(1, self.hpss_calls)
2036
2006
def disableExtraResults(self):
2037
self.overrideAttr(SmartServerRepositoryGetParentMap,
2038
'no_extra_results', True)
2007
old_flag = SmartServerRepositoryGetParentMap.no_extra_results
2008
SmartServerRepositoryGetParentMap.no_extra_results = True
2010
SmartServerRepositoryGetParentMap.no_extra_results = old_flag
2011
self.addCleanup(reset_values)
2040
2013
def test_null_cached_missing_and_stop_key(self):
2041
2014
self.setup_smart_server_with_call_log()
2101
2074
def test_allows_new_revisions(self):
2102
2075
"""get_parent_map's results can be updated by commit."""
2103
smart_server = test_server.SmartTCPServer_for_testing()
2076
smart_server = server.SmartTCPServer_for_testing()
2104
2077
self.start_server(smart_server)
2105
2078
self.make_branch('branch')
2106
2079
branch = Branch.open(smart_server.get_url() + '/branch')
2217
2190
# Make a repo with a fallback repo, both using a FakeClient.
2218
2191
format = remote.response_tuple_to_repo_format(
2219
('yes', 'no', 'yes', self.get_repo_format().network_name()))
2192
('yes', 'no', 'yes', 'fake-network-name'))
2220
2193
repo, client = self.setup_fake_client_and_repository('quack')
2221
2194
repo._format = format
2222
2195
fallback_repo, ignored = self.setup_fake_client_and_repository(
2224
2197
fallback_repo._client = client
2225
fallback_repo._format = format
2226
2198
repo.add_fallback_repository(fallback_repo)
2227
2199
# First the client should ask the primary repo
2228
2200
client.add_expected_call(
2649
2621
"""RemoteRepository.copy_content_into optimizations"""
2651
2623
def test_copy_content_remote_to_local(self):
2652
self.transport_server = test_server.SmartTCPServer_for_testing
2624
self.transport_server = server.SmartTCPServer_for_testing
2653
2625
src_repo = self.make_repository('repo1')
2654
2626
src_repo = repository.Repository.open(self.get_url('repo1'))
2655
2627
# At the moment the tarball-based copy_content_into can't write back
2803
2775
expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
2804
2776
self.assertEqual(expected_error, translated_error)
2806
def test_nobranch_one_arg(self):
2807
bzrdir = self.make_bzrdir('')
2808
translated_error = self.translateTuple(
2809
('nobranch', 'extra detail'), bzrdir=bzrdir)
2810
expected_error = errors.NotBranchError(
2811
path=bzrdir.root_transport.base,
2812
detail='extra detail')
2813
self.assertEqual(expected_error, translated_error)
2815
2778
def test_LockContention(self):
2816
2779
translated_error = self.translateTuple(('LockContention',))
2817
2780
expected_error = errors.LockContention('(remote lock)')
2968
2931
stacked_branch = self.make_branch('stacked', format='1.9')
2969
2932
stacked_branch.set_stacked_on_url('../base')
2970
2933
# start a server looking at this
2971
smart_server = test_server.SmartTCPServer_for_testing()
2934
smart_server = server.SmartTCPServer_for_testing()
2972
2935
self.start_server(smart_server)
2973
2936
remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2974
2937
# can get its branch and repository
3130
3093
super(TestRemoteBranchEffort, self).setUp()
3131
3094
# Create a smart server that publishes whatever the backing VFS server
3133
self.smart_server = test_server.SmartTCPServer_for_testing()
3096
self.smart_server = server.SmartTCPServer_for_testing()
3134
3097
self.start_server(self.smart_server, self.get_server())
3135
3098
# Log all HPSS calls into self.hpss_calls.
3136
3099
_SmartClient.hooks.install_named_hook(