/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Robert Collins
  • Date: 2009-08-26 01:18:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4656.
  • Revision ID: robertc@robertcollins.net-20090826011813-46x8kcuzwz97opoi
Deserialise IncompatibleRepositories errors in the client, generating
nicer feedback when the smart server encounters such a situation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
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
27
27
from cStringIO import StringIO
28
28
 
29
29
from bzrlib import (
30
 
    branch,
31
30
    bzrdir,
32
31
    config,
33
32
    errors,
37
36
    pack,
38
37
    remote,
39
38
    repository,
 
39
    smart,
40
40
    tests,
41
41
    treebuilder,
42
42
    urlutils,
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,
 
64
    KnownFailure,
65
65
    )
66
 
from bzrlib.transport import get_transport
 
66
from bzrlib.transport import get_transport, http
67
67
from bzrlib.transport.memory import MemoryTransport
68
68
from bzrlib.transport.remote import (
69
69
    RemoteTransport,
76
76
        standard_tests, condition_isinstance(BasicRemoteObjectTests))
77
77
    smart_server_version_scenarios = [
78
78
        ('HPSS-v2',
79
 
         {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
 
79
            {'transport_server': server.SmartTCPServer_for_testing_v2_only}),
80
80
        ('HPSS-v3',
81
 
         {'transport_server': test_server.SmartTCPServer_for_testing})]
 
81
            {'transport_server': server.SmartTCPServer_for_testing})]
82
82
    return multiply_tests(to_adapt, smart_server_version_scenarios, result)
83
83
 
84
84
 
135
135
        b = BzrDir.open_from_transport(self.transport).open_branch()
136
136
        self.assertStartsWith(str(b), 'RemoteBranch(')
137
137
 
138
 
    def test_remote_bzrdir_repr(self):
139
 
        b = BzrDir.open_from_transport(self.transport)
140
 
        self.assertStartsWith(str(b), 'RemoteBzrDir(')
141
 
 
142
138
    def test_remote_branch_format_supports_stacking(self):
143
139
        t = self.transport
144
140
        self.make_branch('unstackable', format='pack-0.92')
284
280
        self.expecting_body = True
285
281
        return result[1], FakeProtocol(result[2], self)
286
282
 
287
 
    def call_with_body_bytes(self, method, args, body):
288
 
        self._check_call(method, args)
289
 
        self._calls.append(('call_with_body_bytes', method, args, body))
290
 
        result = self._get_next_response()
291
 
        return result[1], FakeProtocol(result[2], self)
292
 
 
293
283
    def call_with_body_bytes_expecting_body(self, method, args, body):
294
284
        self._check_call(method, args)
295
285
        self._calls.append(('call_with_body_bytes_expecting_body', method,
418
408
        # Calling _remember_remote_is_before again with a lower value works.
419
409
        client_medium._remember_remote_is_before((1, 5))
420
410
        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)))
 
411
        # You cannot call _remember_remote_is_before with a larger value.
 
412
        self.assertRaises(
 
413
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
427
414
 
428
415
 
429
416
class TestBzrDirCloningMetaDir(TestRemote):
448
435
            'BzrDir.cloning_metadir', ('quack/', 'False'),
449
436
            'error', ('BranchReference',)),
450
437
        client.add_expected_call(
451
 
            'BzrDir.open_branchV3', ('quack/',),
 
438
            'BzrDir.open_branchV2', ('quack/',),
452
439
            'success', ('ref', self.get_url('referenced'))),
453
440
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
454
441
            _client=client)
481
468
        self.assertFinished(client)
482
469
 
483
470
 
484
 
class TestBzrDirOpen(TestRemote):
485
 
 
486
 
    def make_fake_client_and_transport(self, path='quack'):
487
 
        transport = MemoryTransport()
488
 
        transport.mkdir(path)
489
 
        transport = transport.clone(path)
490
 
        client = FakeClient(transport.base)
491
 
        return client, transport
492
 
 
493
 
    def test_absent(self):
494
 
        client, transport = self.make_fake_client_and_transport()
495
 
        client.add_expected_call(
496
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
497
 
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
498
 
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
499
 
        self.assertFinished(client)
500
 
 
501
 
    def test_present_without_workingtree(self):
502
 
        client, transport = self.make_fake_client_and_transport()
503
 
        client.add_expected_call(
504
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
505
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
506
 
            _client=client, _force_probe=True)
507
 
        self.assertIsInstance(bd, RemoteBzrDir)
508
 
        self.assertFalse(bd.has_workingtree())
509
 
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
510
 
        self.assertFinished(client)
511
 
 
512
 
    def test_present_with_workingtree(self):
513
 
        client, transport = self.make_fake_client_and_transport()
514
 
        client.add_expected_call(
515
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
516
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
517
 
            _client=client, _force_probe=True)
518
 
        self.assertIsInstance(bd, RemoteBzrDir)
519
 
        self.assertTrue(bd.has_workingtree())
520
 
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
521
 
        self.assertFinished(client)
522
 
 
523
 
    def test_backwards_compat(self):
524
 
        client, transport = self.make_fake_client_and_transport()
525
 
        client.add_expected_call(
526
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
527
 
        client.add_expected_call(
528
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
529
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
530
 
            _client=client, _force_probe=True)
531
 
        self.assertIsInstance(bd, RemoteBzrDir)
532
 
        self.assertFinished(client)
533
 
 
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
 
 
557
471
class TestBzrDirOpenBranch(TestRemote):
558
472
 
559
473
    def test_backwards_compat(self):
561
475
        self.make_branch('.')
562
476
        a_dir = BzrDir.open(self.get_url('.'))
563
477
        self.reset_smart_call_log()
564
 
        verb = 'BzrDir.open_branchV3'
 
478
        verb = 'BzrDir.open_branchV2'
565
479
        self.disable_verb(verb)
566
480
        format = a_dir.open_branch()
567
481
        call_count = len([call for call in self.hpss_calls if
577
491
        transport = transport.clone('quack')
578
492
        client = FakeClient(transport.base)
579
493
        client.add_expected_call(
580
 
            'BzrDir.open_branchV3', ('quack/',),
 
494
            'BzrDir.open_branchV2', ('quack/',),
581
495
            'success', ('branch', branch_network_name))
582
496
        client.add_expected_call(
583
497
            'BzrDir.find_repositoryV3', ('quack/',),
602
516
            _client=client)
603
517
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
604
518
        self.assertEqual(
605
 
            [('call', 'BzrDir.open_branchV3', ('quack/',))],
 
519
            [('call', 'BzrDir.open_branchV2', ('quack/',))],
606
520
            client._calls)
607
521
 
608
522
    def test__get_tree_branch(self):
632
546
        network_name = reference_format.network_name()
633
547
        branch_network_name = self.get_branch_format().network_name()
634
548
        client.add_expected_call(
635
 
            'BzrDir.open_branchV3', ('~hello/',),
 
549
            'BzrDir.open_branchV2', ('~hello/',),
636
550
            'success', ('branch', branch_network_name))
637
551
        client.add_expected_call(
638
552
            'BzrDir.find_repositoryV3', ('~hello/',),
769
683
        # fallback all the way to the first version.
770
684
        reference_format = self.get_repo_format()
771
685
        network_name = reference_format.network_name()
772
 
        server_url = 'bzr://example.com/'
773
 
        self.permit_url(server_url)
774
 
        client = FakeClient(server_url)
 
686
        client = FakeClient('bzr://example.com/')
775
687
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
776
688
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
777
689
        client.add_success_response('ok', '', 'no', 'no')
783
695
            reference_format.get_format_string(), 'ok')
784
696
        # PackRepository wants to do a stat
785
697
        client.add_success_response('stat', '0', '65535')
786
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
 
698
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
787
699
            _client=client)
788
700
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
789
701
            _client=client)
803
715
        # fallback to find_repositoryV2
804
716
        reference_format = self.get_repo_format()
805
717
        network_name = reference_format.network_name()
806
 
        server_url = 'bzr://example.com/'
807
 
        self.permit_url(server_url)
808
 
        client = FakeClient(server_url)
 
718
        client = FakeClient('bzr://example.com/')
809
719
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
810
720
        client.add_success_response('ok', '', 'no', 'no', 'no')
811
721
        # A real repository instance will be created to determine the network
816
726
            reference_format.get_format_string(), 'ok')
817
727
        # PackRepository wants to do a stat
818
728
        client.add_success_response('stat', '0', '65535')
819
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
 
729
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
820
730
            _client=client)
821
731
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
822
732
            _client=client)
941
851
 
942
852
class RemoteBranchTestCase(RemoteBzrDirTestCase):
943
853
 
944
 
    def lock_remote_branch(self, branch):
945
 
        """Trick a RemoteBranch into thinking it is locked."""
946
 
        branch._lock_mode = 'w'
947
 
        branch._lock_count = 2
948
 
        branch._lock_token = 'branch token'
949
 
        branch._repo_lock_token = 'repo token'
950
 
        branch.repository._lock_mode = 'w'
951
 
        branch.repository._lock_count = 2
952
 
        branch.repository._lock_token = 'repo token'
953
 
 
954
854
    def make_remote_branch(self, transport, client):
955
855
        """Make a RemoteBranch using 'client' as its _SmartClient.
956
856
 
1095
995
        self.assertEqual({}, result)
1096
996
 
1097
997
 
1098
 
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1099
 
 
1100
 
    def test_trivial(self):
1101
 
        transport = MemoryTransport()
1102
 
        client = FakeClient(transport.base)
1103
 
        client.add_expected_call(
1104
 
            'Branch.get_stacked_on_url', ('quack/',),
1105
 
            'error', ('NotStacked',))
1106
 
        client.add_expected_call(
1107
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1108
 
            'success', ('',))
1109
 
        transport.mkdir('quack')
1110
 
        transport = transport.clone('quack')
1111
 
        branch = self.make_remote_branch(transport, client)
1112
 
        self.lock_remote_branch(branch)
1113
 
        branch._set_tags_bytes('tags bytes')
1114
 
        self.assertFinished(client)
1115
 
        self.assertEqual('tags bytes', client._calls[-1][-1])
1116
 
 
1117
 
    def test_backwards_compatible(self):
1118
 
        transport = MemoryTransport()
1119
 
        client = FakeClient(transport.base)
1120
 
        client.add_expected_call(
1121
 
            'Branch.get_stacked_on_url', ('quack/',),
1122
 
            'error', ('NotStacked',))
1123
 
        client.add_expected_call(
1124
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1125
 
            'unknown', ('Branch.set_tags_bytes',))
1126
 
        transport.mkdir('quack')
1127
 
        transport = transport.clone('quack')
1128
 
        branch = self.make_remote_branch(transport, client)
1129
 
        self.lock_remote_branch(branch)
1130
 
        class StubRealBranch(object):
1131
 
            def __init__(self):
1132
 
                self.calls = []
1133
 
            def _set_tags_bytes(self, bytes):
1134
 
                self.calls.append(('set_tags_bytes', bytes))
1135
 
        real_branch = StubRealBranch()
1136
 
        branch._real_branch = real_branch
1137
 
        branch._set_tags_bytes('tags bytes')
1138
 
        # Call a second time, to exercise the 'remote version already inferred'
1139
 
        # code path.
1140
 
        branch._set_tags_bytes('tags bytes')
1141
 
        self.assertFinished(client)
1142
 
        self.assertEqual(
1143
 
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1144
 
 
1145
 
 
1146
998
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1147
999
 
1148
1000
    def test_empty_branch(self):
1220
1072
        client = FakeClient(self.get_url())
1221
1073
        branch_network_name = self.get_branch_format().network_name()
1222
1074
        client.add_expected_call(
1223
 
            'BzrDir.open_branchV3', ('stacked/',),
 
1075
            'BzrDir.open_branchV2', ('stacked/',),
1224
1076
            'success', ('branch', branch_network_name))
1225
1077
        client.add_expected_call(
1226
1078
            'BzrDir.find_repositoryV3', ('stacked/',),
1248
1100
            len(branch.repository._real_repository._fallback_repositories))
1249
1101
 
1250
1102
    def test_get_stacked_on_real_branch(self):
1251
 
        base_branch = self.make_branch('base')
1252
 
        stacked_branch = self.make_branch('stacked')
 
1103
        base_branch = self.make_branch('base', format='1.6')
 
1104
        stacked_branch = self.make_branch('stacked', format='1.6')
1253
1105
        stacked_branch.set_stacked_on_url('../base')
1254
1106
        reference_format = self.get_repo_format()
1255
1107
        network_name = reference_format.network_name()
1256
1108
        client = FakeClient(self.get_url())
1257
1109
        branch_network_name = self.get_branch_format().network_name()
1258
1110
        client.add_expected_call(
1259
 
            'BzrDir.open_branchV3', ('stacked/',),
 
1111
            'BzrDir.open_branchV2', ('stacked/',),
1260
1112
            'success', ('branch', branch_network_name))
1261
1113
        client.add_expected_call(
1262
1114
            'BzrDir.find_repositoryV3', ('stacked/',),
1263
 
            'success', ('ok', '', 'yes', 'no', 'yes', network_name))
 
1115
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
1264
1116
        # called twice, once from constructor and then again by us
1265
1117
        client.add_expected_call(
1266
1118
            'Branch.get_stacked_on_url', ('stacked/',),
1490
1342
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1491
1343
        branch.unlock()
1492
1344
 
 
1345
    def lock_remote_branch(self, branch):
 
1346
        """Trick a RemoteBranch into thinking it is locked."""
 
1347
        branch._lock_mode = 'w'
 
1348
        branch._lock_count = 2
 
1349
        branch._lock_token = 'branch token'
 
1350
        branch._repo_lock_token = 'repo token'
 
1351
        branch.repository._lock_mode = 'w'
 
1352
        branch.repository._lock_count = 2
 
1353
        branch.repository._lock_token = 'repo token'
 
1354
 
1493
1355
    def test_backwards_compatibility(self):
1494
1356
        """If the server does not support the Branch.set_last_revision_info
1495
1357
        verb (which is new in 1.4), then the client falls back to VFS methods.
1811
1673
        return repo, client
1812
1674
 
1813
1675
 
1814
 
def remoted_description(format):
1815
 
    return 'Remote: ' + format.get_format_description()
1816
 
 
1817
 
 
1818
 
class TestBranchFormat(tests.TestCase):
1819
 
 
1820
 
    def test_get_format_description(self):
1821
 
        remote_format = RemoteBranchFormat()
1822
 
        real_format = branch.BranchFormat.get_default_format()
1823
 
        remote_format._network_name = real_format.network_name()
1824
 
        self.assertEqual(remoted_description(real_format),
1825
 
            remote_format.get_format_description())
1826
 
 
1827
 
 
1828
1676
class TestRepositoryFormat(TestRemoteRepository):
1829
1677
 
1830
1678
    def test_fast_delta(self):
1837
1685
        false_format._network_name = false_name
1838
1686
        self.assertEqual(False, false_format.fast_deltas)
1839
1687
 
1840
 
    def test_get_format_description(self):
1841
 
        remote_repo_format = RemoteRepositoryFormat()
1842
 
        real_format = repository.RepositoryFormat.get_default_format()
1843
 
        remote_repo_format._network_name = real_format.network_name()
1844
 
        self.assertEqual(remoted_description(real_format),
1845
 
            remote_repo_format.get_format_description())
1846
 
 
1847
1688
 
1848
1689
class TestRepositoryGatherStats(TestRemoteRepository):
1849
1690
 
2034
1875
        self.assertLength(1, self.hpss_calls)
2035
1876
 
2036
1877
    def disableExtraResults(self):
2037
 
        self.overrideAttr(SmartServerRepositoryGetParentMap,
2038
 
                          'no_extra_results', True)
 
1878
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
1879
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
1880
        def reset_values():
 
1881
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
1882
        self.addCleanup(reset_values)
2039
1883
 
2040
1884
    def test_null_cached_missing_and_stop_key(self):
2041
1885
        self.setup_smart_server_with_call_log()
2100
1944
 
2101
1945
    def test_allows_new_revisions(self):
2102
1946
        """get_parent_map's results can be updated by commit."""
2103
 
        smart_server = test_server.SmartTCPServer_for_testing()
2104
 
        self.start_server(smart_server)
 
1947
        smart_server = server.SmartTCPServer_for_testing()
 
1948
        smart_server.setUp()
 
1949
        self.addCleanup(smart_server.tearDown)
2105
1950
        self.make_branch('branch')
2106
1951
        branch = Branch.open(smart_server.get_url() + '/branch')
2107
1952
        tree = branch.create_checkout('tree', lightweight=True)
2216
2061
        """
2217
2062
        # Make a repo with a fallback repo, both using a FakeClient.
2218
2063
        format = remote.response_tuple_to_repo_format(
2219
 
            ('yes', 'no', 'yes', self.get_repo_format().network_name()))
 
2064
            ('yes', 'no', 'yes', 'fake-network-name'))
2220
2065
        repo, client = self.setup_fake_client_and_repository('quack')
2221
2066
        repo._format = format
2222
2067
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2223
2068
            'fallback')
2224
2069
        fallback_repo._client = client
2225
 
        fallback_repo._format = format
2226
2070
        repo.add_fallback_repository(fallback_repo)
2227
2071
        # First the client should ask the primary repo
2228
2072
        client.add_expected_call(
2249
2093
            repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2250
2094
        self.assertFinished(client)
2251
2095
 
2252
 
    def test_branch_fallback_locking(self):
2253
 
        """RemoteBranch.get_rev_id takes a read lock, and tries to call the
2254
 
        get_rev_id_for_revno verb.  If the verb is unknown the VFS fallback
2255
 
        will be invoked, which will fail if the repo is unlocked.
2256
 
        """
2257
 
        self.setup_smart_server_with_call_log()
2258
 
        tree = self.make_branch_and_memory_tree('.')
2259
 
        tree.lock_write()
2260
 
        rev1 = tree.commit('First')
2261
 
        rev2 = tree.commit('Second')
2262
 
        tree.unlock()
2263
 
        branch = tree.branch
2264
 
        self.assertFalse(branch.is_locked())
2265
 
        self.reset_smart_call_log()
2266
 
        verb = 'Repository.get_rev_id_for_revno'
2267
 
        self.disable_verb(verb)
2268
 
        self.assertEqual(rev1, branch.get_rev_id(1))
2269
 
        self.assertLength(1, [call for call in self.hpss_calls if
2270
 
                              call.call.method == verb])
2271
 
 
2272
2096
 
2273
2097
class TestRepositoryIsShared(TestRemoteRepository):
2274
2098
 
2502
2326
        class FakeRealRepository:
2503
2327
            def _get_sink(self):
2504
2328
                return fake_real_sink
2505
 
            def is_in_write_group(self):
2506
 
                return False
2507
 
            def refresh_data(self):
2508
 
                return True
2509
2329
        repo._real_repository = FakeRealRepository()
2510
2330
        sink = repo._get_sink()
2511
2331
        fmt = repository.RepositoryFormat.get_default_format()
2649
2469
    """RemoteRepository.copy_content_into optimizations"""
2650
2470
 
2651
2471
    def test_copy_content_remote_to_local(self):
2652
 
        self.transport_server = test_server.SmartTCPServer_for_testing
 
2472
        self.transport_server = server.SmartTCPServer_for_testing
2653
2473
        src_repo = self.make_repository('repo1')
2654
2474
        src_repo = repository.Repository.open(self.get_url('repo1'))
2655
2475
        # At the moment the tarball-based copy_content_into can't write back
2803
2623
        expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
2804
2624
        self.assertEqual(expected_error, translated_error)
2805
2625
 
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)
2814
 
 
2815
2626
    def test_LockContention(self):
2816
2627
        translated_error = self.translateTuple(('LockContention',))
2817
2628
        expected_error = errors.LockContention('(remote lock)')
2930
2741
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2931
2742
        # been muttered to the log file for developer to look at.
2932
2743
        self.assertContainsRe(
2933
 
            self.get_log(),
 
2744
            self._get_log(keep_log_file=True),
2934
2745
            "Missing key 'branch' in context")
2935
2746
 
2936
2747
    def test_path_missing(self):
2944
2755
        self.assertEqual(server_error, translated_error)
2945
2756
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2946
2757
        # been muttered to the log file for developer to look at.
2947
 
        self.assertContainsRe(self.get_log(), "Missing key 'path' in context")
 
2758
        self.assertContainsRe(
 
2759
            self._get_log(keep_log_file=True), "Missing key 'path' in context")
2948
2760
 
2949
2761
 
2950
2762
class TestStacking(tests.TestCaseWithTransport):
2968
2780
        stacked_branch = self.make_branch('stacked', format='1.9')
2969
2781
        stacked_branch.set_stacked_on_url('../base')
2970
2782
        # start a server looking at this
2971
 
        smart_server = test_server.SmartTCPServer_for_testing()
2972
 
        self.start_server(smart_server)
 
2783
        smart_server = server.SmartTCPServer_for_testing()
 
2784
        smart_server.setUp()
 
2785
        self.addCleanup(smart_server.tearDown)
2973
2786
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2974
2787
        # can get its branch and repository
2975
2788
        remote_branch = remote_bzrdir.open_branch()
3078
2891
            local_tree.commit('more local changes are better')
3079
2892
            branch = Branch.open(self.get_url('tree3'))
3080
2893
            branch.lock_read()
3081
 
            self.addCleanup(branch.unlock)
3082
2894
            return None, branch
3083
2895
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
3084
2896
            branch_factory=make_stacked_stacked)
3130
2942
        super(TestRemoteBranchEffort, self).setUp()
3131
2943
        # Create a smart server that publishes whatever the backing VFS server
3132
2944
        # does.
3133
 
        self.smart_server = test_server.SmartTCPServer_for_testing()
3134
 
        self.start_server(self.smart_server, self.get_server())
 
2945
        self.smart_server = server.SmartTCPServer_for_testing()
 
2946
        self.smart_server.setUp(self.get_server())
 
2947
        self.addCleanup(self.smart_server.tearDown)
3135
2948
        # Log all HPSS calls into self.hpss_calls.
3136
2949
        _SmartClient.hooks.install_named_hook(
3137
2950
            'call', self.capture_hpss_call, None)