~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Merge 2.0 into 2.1 including fixes for #262450, #373898, #498409

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
    )
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,
63
63
    multiply_tests,
64
 
    test_server,
65
64
    )
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 = [
78
77
        ('HPSS-v2',
79
 
         {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
 
78
            {'transport_server': server.SmartTCPServer_for_testing_v2_only}),
80
79
        ('HPSS-v3',
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)
83
82
 
84
83
 
418
417
        # Calling _remember_remote_is_before again with a lower value works.
419
418
        client_medium._remember_remote_is_before((1, 5))
420
419
        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)))
 
420
        # You cannot call _remember_remote_is_before with a larger value.
 
421
        self.assertRaises(
 
422
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
427
423
 
428
424
 
429
425
class TestBzrDirCloningMetaDir(TestRemote):
531
527
        self.assertIsInstance(bd, RemoteBzrDir)
532
528
        self.assertFinished(client)
533
529
 
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)
555
 
 
556
530
 
557
531
class TestBzrDirOpenBranch(TestRemote):
558
532
 
609
583
        # _get_tree_branch is a form of open_branch, but it should only ask for
610
584
        # branch opening, not any other network requests.
611
585
        calls = []
612
 
        def open_branch(name=None):
 
586
        def open_branch():
613
587
            calls.append("Called")
614
588
            return "a-branch"
615
589
        transport = MemoryTransport()
1248
1222
            len(branch.repository._real_repository._fallback_repositories))
1249
1223
 
1250
1224
    def test_get_stacked_on_real_branch(self):
1251
 
        base_branch = self.make_branch('base')
1252
 
        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')
1253
1227
        stacked_branch.set_stacked_on_url('../base')
1254
1228
        reference_format = self.get_repo_format()
1255
1229
        network_name = reference_format.network_name()
1260
1234
            'success', ('branch', branch_network_name))
1261
1235
        client.add_expected_call(
1262
1236
            'BzrDir.find_repositoryV3', ('stacked/',),
1263
 
            'success', ('ok', '', 'yes', 'no', 'yes', network_name))
 
1237
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
1264
1238
        # called twice, once from constructor and then again by us
1265
1239
        client.add_expected_call(
1266
1240
            'Branch.get_stacked_on_url', ('stacked/',),
2034
2008
        self.assertLength(1, self.hpss_calls)
2035
2009
 
2036
2010
    def disableExtraResults(self):
2037
 
        self.overrideAttr(SmartServerRepositoryGetParentMap,
2038
 
                          'no_extra_results', True)
 
2011
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
2012
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
2013
        def reset_values():
 
2014
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
2015
        self.addCleanup(reset_values)
2039
2016
 
2040
2017
    def test_null_cached_missing_and_stop_key(self):
2041
2018
        self.setup_smart_server_with_call_log()
2100
2077
 
2101
2078
    def test_allows_new_revisions(self):
2102
2079
        """get_parent_map's results can be updated by commit."""
2103
 
        smart_server = test_server.SmartTCPServer_for_testing()
 
2080
        smart_server = server.SmartTCPServer_for_testing()
2104
2081
        self.start_server(smart_server)
2105
2082
        self.make_branch('branch')
2106
2083
        branch = Branch.open(smart_server.get_url() + '/branch')
2216
2193
        """
2217
2194
        # Make a repo with a fallback repo, both using a FakeClient.
2218
2195
        format = remote.response_tuple_to_repo_format(
2219
 
            ('yes', 'no', 'yes', self.get_repo_format().network_name()))
 
2196
            ('yes', 'no', 'yes', 'fake-network-name'))
2220
2197
        repo, client = self.setup_fake_client_and_repository('quack')
2221
2198
        repo._format = format
2222
2199
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2223
2200
            'fallback')
2224
2201
        fallback_repo._client = client
2225
 
        fallback_repo._format = format
2226
2202
        repo.add_fallback_repository(fallback_repo)
2227
2203
        # First the client should ask the primary repo
2228
2204
        client.add_expected_call(
2301
2277
        transport_path = 'quack'
2302
2278
        repo, client = self.setup_fake_client_and_repository(transport_path)
2303
2279
        client.add_success_response('ok', 'a token')
2304
 
        token = repo.lock_write().repository_token
 
2280
        result = repo.lock_write()
2305
2281
        self.assertEqual(
2306
2282
            [('call', 'Repository.lock_write', ('quack/', ''))],
2307
2283
            client._calls)
2308
 
        self.assertEqual('a token', token)
 
2284
        self.assertEqual('a token', result)
2309
2285
 
2310
2286
    def test_lock_write_already_locked(self):
2311
2287
        transport_path = 'quack'
2649
2625
    """RemoteRepository.copy_content_into optimizations"""
2650
2626
 
2651
2627
    def test_copy_content_remote_to_local(self):
2652
 
        self.transport_server = test_server.SmartTCPServer_for_testing
 
2628
        self.transport_server = server.SmartTCPServer_for_testing
2653
2629
        src_repo = self.make_repository('repo1')
2654
2630
        src_repo = repository.Repository.open(self.get_url('repo1'))
2655
2631
        # At the moment the tarball-based copy_content_into can't write back
2968
2944
        stacked_branch = self.make_branch('stacked', format='1.9')
2969
2945
        stacked_branch.set_stacked_on_url('../base')
2970
2946
        # start a server looking at this
2971
 
        smart_server = test_server.SmartTCPServer_for_testing()
 
2947
        smart_server = server.SmartTCPServer_for_testing()
2972
2948
        self.start_server(smart_server)
2973
2949
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2974
2950
        # can get its branch and repository
3130
3106
        super(TestRemoteBranchEffort, self).setUp()
3131
3107
        # Create a smart server that publishes whatever the backing VFS server
3132
3108
        # does.
3133
 
        self.smart_server = test_server.SmartTCPServer_for_testing()
 
3109
        self.smart_server = server.SmartTCPServer_for_testing()
3134
3110
        self.start_server(self.smart_server, self.get_server())
3135
3111
        # Log all HPSS calls into self.hpss_calls.
3136
3112
        _SmartClient.hooks.install_named_hook(