45
45
from bzrlib.branch import Branch
46
from bzrlib.bzrdir import (
46
from bzrlib.bzrdir import BzrDir, BzrDirFormat
51
47
from bzrlib.remote import (
53
49
RemoteBranchFormat,
56
53
RemoteRepositoryFormat,
58
55
from bzrlib.repofmt import groupcompress_repo, pack_repo
59
56
from bzrlib.revision import NULL_REVISION
60
from bzrlib.smart import medium
57
from bzrlib.smart import server, medium
61
58
from bzrlib.smart.client import _SmartClient
62
59
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
63
60
from bzrlib.tests import (
64
61
condition_isinstance,
65
62
split_suite_by_condition,
65
from bzrlib.transport import get_transport
69
66
from bzrlib.transport.memory import MemoryTransport
70
67
from bzrlib.transport.remote import (
78
75
standard_tests, condition_isinstance(BasicRemoteObjectTests))
79
76
smart_server_version_scenarios = [
81
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
78
{'transport_server': server.SmartTCPServer_for_testing_v2_only}),
83
{'transport_server': test_server.SmartTCPServer_for_testing})]
80
{'transport_server': server.SmartTCPServer_for_testing})]
84
81
return multiply_tests(to_adapt, smart_server_version_scenarios, result)
91
88
self.transport = self.get_transport()
92
89
# make a branch that can be opened over the smart transport
93
90
self.local_wt = BzrDir.create_standalone_workingtree('.')
94
self.addCleanup(self.transport.disconnect)
93
self.transport.disconnect()
94
tests.TestCaseWithTransport.tearDown(self)
96
96
def test_create_remote_bzrdir(self):
97
97
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
121
121
def test_find_correct_format(self):
122
122
"""Should open a RemoteBzrDir over a RemoteTransport"""
123
123
fmt = BzrDirFormat.find_format(self.transport)
124
self.assertTrue(bzrdir.RemoteBzrProber
125
in controldir.ControlDirFormat._server_probers)
124
self.assertTrue(RemoteBzrDirFormat
125
in BzrDirFormat._control_server_formats)
126
126
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
128
128
def test_open_detected_smart_format(self):
358
358
a given client_base and transport_base.
360
360
client_medium = medium.SmartClientMedium(client_base)
361
t = transport.get_transport(transport_base)
362
result = client_medium.remote_path_from_transport(t)
361
transport = get_transport(transport_base)
362
result = client_medium.remote_path_from_transport(transport)
363
363
self.assertEqual(expected, result)
365
365
def test_remote_path_from_transport(self):
376
376
a given transport_base and relpath of that transport. (Note that
377
377
HttpTransportBase is a subclass of SmartClientMedium)
379
base_transport = transport.get_transport(transport_base)
379
base_transport = get_transport(transport_base)
380
380
client_medium = base_transport.get_smart_medium()
381
381
cloned_transport = base_transport.clone(relpath)
382
382
result = client_medium.remote_path_from_transport(cloned_transport)
417
417
# Calling _remember_remote_is_before again with a lower value works.
418
418
client_medium._remember_remote_is_before((1, 5))
419
419
self.assertTrue(client_medium._is_remote_before((1, 5)))
420
# If you call _remember_remote_is_before with a higher value it logs a
421
# warning, and continues to remember the lower value.
422
self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
423
client_medium._remember_remote_is_before((1, 9))
424
self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
425
self.assertTrue(client_medium._is_remote_before((1, 5)))
420
# You cannot call _remember_remote_is_before with a larger value.
422
AssertionError, client_medium._remember_remote_is_before, (1, 9))
428
425
class TestBzrDirCloningMetaDir(TestRemote):
530
527
self.assertIsInstance(bd, RemoteBzrDir)
531
528
self.assertFinished(client)
533
def test_backwards_compat_hpss_v2(self):
534
client, transport = self.make_fake_client_and_transport()
535
# Monkey-patch fake client to simulate real-world behaviour with v2
536
# server: upon first RPC call detect the protocol version, and because
537
# the version is 2 also do _remember_remote_is_before((1, 6)) before
538
# continuing with the RPC.
539
orig_check_call = client._check_call
540
def check_call(method, args):
541
client._medium._protocol_version = 2
542
client._medium._remember_remote_is_before((1, 6))
543
client._check_call = orig_check_call
544
client._check_call(method, args)
545
client._check_call = check_call
546
client.add_expected_call(
547
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
548
client.add_expected_call(
549
'BzrDir.open', ('quack/',), 'success', ('yes',))
550
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
551
_client=client, _force_probe=True)
552
self.assertIsInstance(bd, RemoteBzrDir)
553
self.assertFinished(client)
556
531
class TestBzrDirOpenBranch(TestRemote):
608
583
# _get_tree_branch is a form of open_branch, but it should only ask for
609
584
# branch opening, not any other network requests.
611
def open_branch(name=None):
612
587
calls.append("Called")
613
588
return "a-branch"
614
589
transport = MemoryTransport()
687
662
self.assertRaises(errors.NotBranchError,
688
RemoteBzrProber.probe_transport, OldServerTransport())
663
RemoteBzrDirFormat.probe_transport, OldServerTransport())
691
666
class TestBzrDirCreateBranch(TestRemote):
1247
1222
len(branch.repository._real_repository._fallback_repositories))
1249
1224
def test_get_stacked_on_real_branch(self):
1250
base_branch = self.make_branch('base')
1251
stacked_branch = self.make_branch('stacked')
1225
base_branch = self.make_branch('base', format='1.6')
1226
stacked_branch = self.make_branch('stacked', format='1.6')
1252
1227
stacked_branch.set_stacked_on_url('../base')
1253
1228
reference_format = self.get_repo_format()
1254
1229
network_name = reference_format.network_name()
1259
1234
'success', ('branch', branch_network_name))
1260
1235
client.add_expected_call(
1261
1236
'BzrDir.find_repositoryV3', ('stacked/',),
1262
'success', ('ok', '', 'yes', 'no', 'yes', network_name))
1237
'success', ('ok', '', 'no', 'no', 'yes', network_name))
1263
1238
# called twice, once from constructor and then again by us
1264
1239
client.add_expected_call(
1265
1240
'Branch.get_stacked_on_url', ('stacked/',),
1617
1592
def test_get_multi_line_branch_conf(self):
1618
1593
# Make sure that multiple-line branch.conf files are supported
1620
# https://bugs.launchpad.net/bzr/+bug/354075
1595
# https://bugs.edge.launchpad.net/bzr/+bug/354075
1621
1596
client = FakeClient()
1622
1597
client.add_expected_call(
1623
1598
'Branch.get_stacked_on_url', ('memory:///',),
1651
1626
branch.unlock()
1652
1627
self.assertFinished(client)
1654
def test_set_option_with_dict(self):
1655
client = FakeClient()
1656
client.add_expected_call(
1657
'Branch.get_stacked_on_url', ('memory:///',),
1658
'error', ('NotStacked',),)
1659
client.add_expected_call(
1660
'Branch.lock_write', ('memory:///', '', ''),
1661
'success', ('ok', 'branch token', 'repo token'))
1662
encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1663
client.add_expected_call(
1664
'Branch.set_config_option_dict', ('memory:///', 'branch token',
1665
'repo token', encoded_dict_value, 'foo', ''),
1667
client.add_expected_call(
1668
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1670
transport = MemoryTransport()
1671
branch = self.make_remote_branch(transport, client)
1673
config = branch._get_config()
1675
{'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1678
self.assertFinished(client)
1680
1629
def test_backwards_compat_set_option(self):
1681
1630
self.setup_smart_server_with_call_log()
1682
1631
branch = self.make_branch('.')
1689
1638
self.assertLength(10, self.hpss_calls)
1690
1639
self.assertEqual('value', branch._get_config().get_option('name'))
1692
def test_backwards_compat_set_option_with_dict(self):
1693
self.setup_smart_server_with_call_log()
1694
branch = self.make_branch('.')
1695
verb = 'Branch.set_config_option_dict'
1696
self.disable_verb(verb)
1698
self.addCleanup(branch.unlock)
1699
self.reset_smart_call_log()
1700
config = branch._get_config()
1701
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1702
config.set_option(value_dict, 'name')
1703
self.assertLength(10, self.hpss_calls)
1704
self.assertEqual(value_dict, branch._get_config().get_option('name'))
1707
1642
class TestBranchLockWrite(RemoteBranchTestCase):
2073
2008
self.assertLength(1, self.hpss_calls)
2075
2010
def disableExtraResults(self):
2076
self.overrideAttr(SmartServerRepositoryGetParentMap,
2077
'no_extra_results', True)
2011
old_flag = SmartServerRepositoryGetParentMap.no_extra_results
2012
SmartServerRepositoryGetParentMap.no_extra_results = True
2014
SmartServerRepositoryGetParentMap.no_extra_results = old_flag
2015
self.addCleanup(reset_values)
2079
2017
def test_null_cached_missing_and_stop_key(self):
2080
2018
self.setup_smart_server_with_call_log()
2140
2078
def test_allows_new_revisions(self):
2141
2079
"""get_parent_map's results can be updated by commit."""
2142
smart_server = test_server.SmartTCPServer_for_testing()
2080
smart_server = server.SmartTCPServer_for_testing()
2143
2081
self.start_server(smart_server)
2144
2082
self.make_branch('branch')
2145
2083
branch = Branch.open(smart_server.get_url() + '/branch')
2256
2194
# Make a repo with a fallback repo, both using a FakeClient.
2257
2195
format = remote.response_tuple_to_repo_format(
2258
('yes', 'no', 'yes', self.get_repo_format().network_name()))
2196
('yes', 'no', 'yes', 'fake-network-name'))
2259
2197
repo, client = self.setup_fake_client_and_repository('quack')
2260
2198
repo._format = format
2261
2199
fallback_repo, ignored = self.setup_fake_client_and_repository(
2263
2201
fallback_repo._client = client
2264
fallback_repo._format = format
2265
2202
repo.add_fallback_repository(fallback_repo)
2266
2203
# First the client should ask the primary repo
2267
2204
client.add_expected_call(
2341
2277
transport_path = 'quack'
2342
2278
repo, client = self.setup_fake_client_and_repository(transport_path)
2343
2279
client.add_success_response('ok', 'a token')
2344
token = repo.lock_write().repository_token
2280
result = repo.lock_write()
2345
2281
self.assertEqual(
2346
2282
[('call', 'Repository.lock_write', ('quack/', ''))],
2348
self.assertEqual('a token', token)
2284
self.assertEqual('a token', result)
2350
2286
def test_lock_write_already_locked(self):
2351
2287
transport_path = 'quack'
2689
2625
"""RemoteRepository.copy_content_into optimizations"""
2691
2627
def test_copy_content_remote_to_local(self):
2692
self.transport_server = test_server.SmartTCPServer_for_testing
2628
self.transport_server = server.SmartTCPServer_for_testing
2693
2629
src_repo = self.make_repository('repo1')
2694
2630
src_repo = repository.Repository.open(self.get_url('repo1'))
2695
2631
# At the moment the tarball-based copy_content_into can't write back
3008
2944
stacked_branch = self.make_branch('stacked', format='1.9')
3009
2945
stacked_branch.set_stacked_on_url('../base')
3010
2946
# start a server looking at this
3011
smart_server = test_server.SmartTCPServer_for_testing()
2947
smart_server = server.SmartTCPServer_for_testing()
3012
2948
self.start_server(smart_server)
3013
2949
remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
3014
2950
# can get its branch and repository
3170
3106
super(TestRemoteBranchEffort, self).setUp()
3171
3107
# Create a smart server that publishes whatever the backing VFS server
3173
self.smart_server = test_server.SmartTCPServer_for_testing()
3109
self.smart_server = server.SmartTCPServer_for_testing()
3174
3110
self.start_server(self.smart_server, self.get_server())
3175
3111
# Log all HPSS calls into self.hpss_calls.
3176
3112
_SmartClient.hooks.install_named_hook(