~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Jelmer Vernooij
  • Date: 2009-04-10 15:58:09 UTC
  • mto: This revision was merged to the branch mainline in revision 4284.
  • Revision ID: jelmer@samba.org-20090410155809-kdibzcjvp7pdb83f
Fix missing import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 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
25
25
 
26
26
import bz2
27
27
from cStringIO import StringIO
 
28
import getpass
28
29
 
29
30
from bzrlib import (
30
 
    branch,
31
31
    bzrdir,
32
32
    config,
33
 
    controldir,
34
33
    errors,
35
 
    graph as _mod_graph,
36
 
    inventory,
37
 
    inventory_delta,
 
34
    graph,
 
35
    pack,
38
36
    remote,
39
37
    repository,
 
38
    smart,
40
39
    tests,
41
 
    transport,
42
40
    treebuilder,
43
 
    versionedfile,
 
41
    urlutils,
44
42
    )
45
43
from bzrlib.branch import Branch
46
 
from bzrlib.bzrdir import (
47
 
    BzrDir,
48
 
    BzrDirFormat,
49
 
    RemoteBzrProber,
50
 
    )
 
44
from bzrlib.bzrdir import BzrDir, BzrDirFormat
51
45
from bzrlib.remote import (
52
46
    RemoteBranch,
53
47
    RemoteBranchFormat,
56
50
    RemoteRepository,
57
51
    RemoteRepositoryFormat,
58
52
    )
59
 
from bzrlib.repofmt import groupcompress_repo, knitpack_repo
 
53
from bzrlib.repofmt import pack_repo
60
54
from bzrlib.revision import NULL_REVISION
61
 
from bzrlib.smart import medium, request
 
55
from bzrlib.smart import server, medium
62
56
from bzrlib.smart.client import _SmartClient
63
 
from bzrlib.smart.repository import (
64
 
    SmartServerRepositoryGetParentMap,
65
 
    SmartServerRepositoryGetStream_1_19,
66
 
    )
 
57
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
67
58
from bzrlib.tests import (
68
 
    test_server,
 
59
    condition_isinstance,
 
60
    split_suite_by_condition,
 
61
    multiply_tests,
69
62
    )
70
 
from bzrlib.tests.scenarios import load_tests_apply_scenarios
 
63
from bzrlib.transport import get_transport, http
71
64
from bzrlib.transport.memory import MemoryTransport
72
65
from bzrlib.transport.remote import (
73
66
    RemoteTransport,
74
67
    RemoteSSHTransport,
75
68
    RemoteTCPTransport,
76
 
    )
77
 
 
78
 
 
79
 
load_tests = load_tests_apply_scenarios
80
 
 
81
 
 
82
 
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
83
 
 
84
 
    scenarios = [
 
69
)
 
70
 
 
71
def load_tests(standard_tests, module, loader):
 
72
    to_adapt, result = split_suite_by_condition(
 
73
        standard_tests, condition_isinstance(BasicRemoteObjectTests))
 
74
    smart_server_version_scenarios = [
85
75
        ('HPSS-v2',
86
 
            {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
 
76
            {'transport_server': server.SmartTCPServer_for_testing_v2_only}),
87
77
        ('HPSS-v3',
88
 
            {'transport_server': test_server.SmartTCPServer_for_testing})]
89
 
 
 
78
            {'transport_server': server.SmartTCPServer_for_testing})]
 
79
    return multiply_tests(to_adapt, smart_server_version_scenarios, result)
 
80
 
 
81
 
 
82
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
90
83
 
91
84
    def setUp(self):
92
85
        super(BasicRemoteObjectTests, self).setUp()
93
86
        self.transport = self.get_transport()
94
87
        # make a branch that can be opened over the smart transport
95
88
        self.local_wt = BzrDir.create_standalone_workingtree('.')
96
 
        self.addCleanup(self.transport.disconnect)
 
89
 
 
90
    def tearDown(self):
 
91
        self.transport.disconnect()
 
92
        tests.TestCaseWithTransport.tearDown(self)
97
93
 
98
94
    def test_create_remote_bzrdir(self):
99
 
        b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
 
95
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
100
96
        self.assertIsInstance(b, BzrDir)
101
97
 
102
98
    def test_open_remote_branch(self):
103
99
        # open a standalone branch in the working directory
104
 
        b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
 
100
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
105
101
        branch = b.open_branch()
106
102
        self.assertIsInstance(branch, Branch)
107
103
 
123
119
    def test_find_correct_format(self):
124
120
        """Should open a RemoteBzrDir over a RemoteTransport"""
125
121
        fmt = BzrDirFormat.find_format(self.transport)
126
 
        self.assertTrue(bzrdir.RemoteBzrProber
127
 
                        in controldir.ControlDirFormat._server_probers)
128
 
        self.assertIsInstance(fmt, RemoteBzrDirFormat)
 
122
        self.assertTrue(RemoteBzrDirFormat
 
123
                        in BzrDirFormat._control_server_formats)
 
124
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
129
125
 
130
126
    def test_open_detected_smart_format(self):
131
127
        fmt = BzrDirFormat.find_format(self.transport)
136
132
        b = BzrDir.open_from_transport(self.transport).open_branch()
137
133
        self.assertStartsWith(str(b), 'RemoteBranch(')
138
134
 
139
 
    def test_remote_bzrdir_repr(self):
140
 
        b = BzrDir.open_from_transport(self.transport)
141
 
        self.assertStartsWith(str(b), 'RemoteBzrDir(')
142
 
 
143
135
    def test_remote_branch_format_supports_stacking(self):
144
136
        t = self.transport
145
137
        self.make_branch('unstackable', format='pack-0.92')
162
154
        r = BzrDir.open_from_transport(t.clone('stackable')).open_repository()
163
155
        self.assertTrue(r._format.supports_external_lookups)
164
156
 
165
 
    def test_remote_branch_set_append_revisions_only(self):
166
 
        # Make a format 1.9 branch, which supports append_revisions_only
167
 
        branch = self.make_branch('branch', format='1.9')
168
 
        config = branch.get_config()
169
 
        branch.set_append_revisions_only(True)
170
 
        self.assertEqual(
171
 
            'True', config.get_user_option('append_revisions_only'))
172
 
        branch.set_append_revisions_only(False)
173
 
        self.assertEqual(
174
 
            'False', config.get_user_option('append_revisions_only'))
175
 
 
176
 
    def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
177
 
        branch = self.make_branch('branch', format='knit')
178
 
        config = branch.get_config()
179
 
        self.assertRaises(
180
 
            errors.UpgradeRequired, branch.set_append_revisions_only, True)
181
 
 
182
157
 
183
158
class FakeProtocol(object):
184
159
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
285
260
        self.expecting_body = True
286
261
        return result[1], FakeProtocol(result[2], self)
287
262
 
288
 
    def call_with_body_bytes(self, method, args, body):
289
 
        self._check_call(method, args)
290
 
        self._calls.append(('call_with_body_bytes', method, args, body))
291
 
        result = self._get_next_response()
292
 
        return result[1], FakeProtocol(result[2], self)
293
 
 
294
263
    def call_with_body_bytes_expecting_body(self, method, args, body):
295
264
        self._check_call(method, args)
296
265
        self._calls.append(('call_with_body_bytes_expecting_body', method,
346
315
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
347
316
        return reference_bzrdir_format.repository_format
348
317
 
349
 
    def assertFinished(self, fake_client):
350
 
        """Assert that all of a FakeClient's expected calls have occurred."""
351
 
        fake_client.finished_test()
 
318
    def disable_verb(self, verb):
 
319
        """Disable a verb for one test."""
 
320
        request_handlers = smart.request.request_handlers
 
321
        orig_method = request_handlers.get(verb)
 
322
        request_handlers.remove(verb)
 
323
        def restoreVerb():
 
324
            request_handlers.register(verb, orig_method)
 
325
        self.addCleanup(restoreVerb)
352
326
 
353
327
 
354
328
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):
360
334
        a given client_base and transport_base.
361
335
        """
362
336
        client_medium = medium.SmartClientMedium(client_base)
363
 
        t = transport.get_transport(transport_base)
364
 
        result = client_medium.remote_path_from_transport(t)
 
337
        transport = get_transport(transport_base)
 
338
        result = client_medium.remote_path_from_transport(transport)
365
339
        self.assertEqual(expected, result)
366
340
 
367
341
    def test_remote_path_from_transport(self):
378
352
        a given transport_base and relpath of that transport.  (Note that
379
353
        HttpTransportBase is a subclass of SmartClientMedium)
380
354
        """
381
 
        base_transport = transport.get_transport(transport_base)
 
355
        base_transport = get_transport(transport_base)
382
356
        client_medium = base_transport.get_smart_medium()
383
357
        cloned_transport = base_transport.clone(relpath)
384
358
        result = client_medium.remote_path_from_transport(cloned_transport)
419
393
        # Calling _remember_remote_is_before again with a lower value works.
420
394
        client_medium._remember_remote_is_before((1, 5))
421
395
        self.assertTrue(client_medium._is_remote_before((1, 5)))
422
 
        # If you call _remember_remote_is_before with a higher value it logs a
423
 
        # warning, and continues to remember the lower value.
424
 
        self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
425
 
        client_medium._remember_remote_is_before((1, 9))
426
 
        self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
427
 
        self.assertTrue(client_medium._is_remote_before((1, 5)))
 
396
        # You cannot call _remember_remote_is_before with a larger value.
 
397
        self.assertRaises(
 
398
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
428
399
 
429
400
 
430
401
class TestBzrDirCloningMetaDir(TestRemote):
449
420
            'BzrDir.cloning_metadir', ('quack/', 'False'),
450
421
            'error', ('BranchReference',)),
451
422
        client.add_expected_call(
452
 
            'BzrDir.open_branchV3', ('quack/',),
 
423
            'BzrDir.open_branchV2', ('quack/',),
453
424
            'success', ('ref', self.get_url('referenced'))),
454
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
425
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
455
426
            _client=client)
456
427
        result = a_bzrdir.cloning_metadir()
457
428
        # We should have got a control dir matching the referenced branch.
458
429
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
459
430
        self.assertEqual(expected._repository_format, result._repository_format)
460
431
        self.assertEqual(expected._branch_format, result._branch_format)
461
 
        self.assertFinished(client)
 
432
        client.finished_test()
462
433
 
463
434
    def test_current_server(self):
464
435
        transport = self.get_transport('.')
470
441
        client.add_expected_call(
471
442
            'BzrDir.cloning_metadir', ('quack/', 'False'),
472
443
            'success', (control_name, '', ('branch', ''))),
473
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
444
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
474
445
            _client=client)
475
446
        result = a_bzrdir.cloning_metadir()
476
447
        # We should have got a reference control dir with default branch and
479
450
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
480
451
        self.assertEqual(None, result._repository_format)
481
452
        self.assertEqual(None, result._branch_format)
482
 
        self.assertFinished(client)
483
 
 
484
 
 
485
 
class TestBzrDirOpen(TestRemote):
486
 
 
487
 
    def make_fake_client_and_transport(self, path='quack'):
488
 
        transport = MemoryTransport()
489
 
        transport.mkdir(path)
490
 
        transport = transport.clone(path)
491
 
        client = FakeClient(transport.base)
492
 
        return client, transport
493
 
 
494
 
    def test_absent(self):
495
 
        client, transport = self.make_fake_client_and_transport()
496
 
        client.add_expected_call(
497
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
498
 
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
499
 
                RemoteBzrDirFormat(), _client=client, _force_probe=True)
500
 
        self.assertFinished(client)
501
 
 
502
 
    def test_present_without_workingtree(self):
503
 
        client, transport = self.make_fake_client_and_transport()
504
 
        client.add_expected_call(
505
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
506
 
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
507
 
            _client=client, _force_probe=True)
508
 
        self.assertIsInstance(bd, RemoteBzrDir)
509
 
        self.assertFalse(bd.has_workingtree())
510
 
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
511
 
        self.assertFinished(client)
512
 
 
513
 
    def test_present_with_workingtree(self):
514
 
        client, transport = self.make_fake_client_and_transport()
515
 
        client.add_expected_call(
516
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
517
 
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
518
 
            _client=client, _force_probe=True)
519
 
        self.assertIsInstance(bd, RemoteBzrDir)
520
 
        self.assertTrue(bd.has_workingtree())
521
 
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
522
 
        self.assertFinished(client)
523
 
 
524
 
    def test_backwards_compat(self):
525
 
        client, transport = self.make_fake_client_and_transport()
526
 
        client.add_expected_call(
527
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
528
 
        client.add_expected_call(
529
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
530
 
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
531
 
            _client=client, _force_probe=True)
532
 
        self.assertIsInstance(bd, RemoteBzrDir)
533
 
        self.assertFinished(client)
534
 
 
535
 
    def test_backwards_compat_hpss_v2(self):
536
 
        client, transport = self.make_fake_client_and_transport()
537
 
        # Monkey-patch fake client to simulate real-world behaviour with v2
538
 
        # server: upon first RPC call detect the protocol version, and because
539
 
        # the version is 2 also do _remember_remote_is_before((1, 6)) before
540
 
        # continuing with the RPC.
541
 
        orig_check_call = client._check_call
542
 
        def check_call(method, args):
543
 
            client._medium._protocol_version = 2
544
 
            client._medium._remember_remote_is_before((1, 6))
545
 
            client._check_call = orig_check_call
546
 
            client._check_call(method, args)
547
 
        client._check_call = check_call
548
 
        client.add_expected_call(
549
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
550
 
        client.add_expected_call(
551
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
552
 
        bd = RemoteBzrDir(transport, RemoteBzrDirFormat(),
553
 
            _client=client, _force_probe=True)
554
 
        self.assertIsInstance(bd, RemoteBzrDir)
555
 
        self.assertFinished(client)
 
453
        client.finished_test()
556
454
 
557
455
 
558
456
class TestBzrDirOpenBranch(TestRemote):
562
460
        self.make_branch('.')
563
461
        a_dir = BzrDir.open(self.get_url('.'))
564
462
        self.reset_smart_call_log()
565
 
        verb = 'BzrDir.open_branchV3'
 
463
        verb = 'BzrDir.open_branchV2'
566
464
        self.disable_verb(verb)
567
465
        format = a_dir.open_branch()
568
466
        call_count = len([call for call in self.hpss_calls if
578
476
        transport = transport.clone('quack')
579
477
        client = FakeClient(transport.base)
580
478
        client.add_expected_call(
581
 
            'BzrDir.open_branchV3', ('quack/',),
 
479
            'BzrDir.open_branchV2', ('quack/',),
582
480
            'success', ('branch', branch_network_name))
583
481
        client.add_expected_call(
584
482
            'BzrDir.find_repositoryV3', ('quack/',),
586
484
        client.add_expected_call(
587
485
            'Branch.get_stacked_on_url', ('quack/',),
588
486
            'error', ('NotStacked',))
589
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
487
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
590
488
            _client=client)
591
489
        result = bzrdir.open_branch()
592
490
        self.assertIsInstance(result, RemoteBranch)
593
491
        self.assertEqual(bzrdir, result.bzrdir)
594
 
        self.assertFinished(client)
 
492
        client.finished_test()
595
493
 
596
494
    def test_branch_missing(self):
597
495
        transport = MemoryTransport()
599
497
        transport = transport.clone('quack')
600
498
        client = FakeClient(transport.base)
601
499
        client.add_error_response('nobranch')
602
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
500
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
603
501
            _client=client)
604
502
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
605
503
        self.assertEqual(
606
 
            [('call', 'BzrDir.open_branchV3', ('quack/',))],
 
504
            [('call', 'BzrDir.open_branchV2', ('quack/',))],
607
505
            client._calls)
608
506
 
609
507
    def test__get_tree_branch(self):
610
508
        # _get_tree_branch is a form of open_branch, but it should only ask for
611
509
        # branch opening, not any other network requests.
612
510
        calls = []
613
 
        def open_branch(name=None):
 
511
        def open_branch():
614
512
            calls.append("Called")
615
513
            return "a-branch"
616
514
        transport = MemoryTransport()
617
515
        # no requests on the network - catches other api calls being made.
618
516
        client = FakeClient(transport.base)
619
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
517
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
620
518
            _client=client)
621
519
        # patch the open_branch call to record that it was called.
622
520
        bzrdir.open_branch = open_branch
633
531
        network_name = reference_format.network_name()
634
532
        branch_network_name = self.get_branch_format().network_name()
635
533
        client.add_expected_call(
636
 
            'BzrDir.open_branchV3', ('~hello/',),
 
534
            'BzrDir.open_branchV2', ('~hello/',),
637
535
            'success', ('branch', branch_network_name))
638
536
        client.add_expected_call(
639
537
            'BzrDir.find_repositoryV3', ('~hello/',),
641
539
        client.add_expected_call(
642
540
            'Branch.get_stacked_on_url', ('~hello/',),
643
541
            'error', ('NotStacked',))
644
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
542
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
645
543
            _client=client)
646
544
        result = bzrdir.open_branch()
647
 
        self.assertFinished(client)
 
545
        client.finished_test()
648
546
 
649
547
    def check_open_repository(self, rich_root, subtrees, external_lookup='no'):
650
548
        reference_format = self.get_repo_format()
664
562
        client.add_success_response(
665
563
            'ok', '', rich_response, subtree_response, external_lookup,
666
564
            network_name)
667
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
565
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
668
566
            _client=client)
669
567
        result = bzrdir.open_repository()
670
568
        self.assertEqual(
687
585
        old.
688
586
        """
689
587
        self.assertRaises(errors.NotBranchError,
690
 
            RemoteBzrProber.probe_transport, OldServerTransport())
 
588
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
691
589
 
692
590
 
693
591
class TestBzrDirCreateBranch(TestRemote):
716
614
            'BzrDir.create_branch', ('quack/', network_name),
717
615
            'success', ('ok', network_name, '', 'no', 'no', 'yes',
718
616
            reference_repo_name))
719
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
617
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
720
618
            _client=client)
721
619
        branch = a_bzrdir.create_branch()
722
620
        # We should have got a remote branch
725
623
        format = branch._format
726
624
        self.assertEqual(network_name, format.network_name())
727
625
 
728
 
    def test_already_open_repo_and_reused_medium(self):
729
 
        """Bug 726584: create_branch(..., repository=repo) should work
730
 
        regardless of what the smart medium's base URL is.
731
 
        """
732
 
        self.transport_server = test_server.SmartTCPServer_for_testing
733
 
        transport = self.get_transport('.')
734
 
        repo = self.make_repository('quack')
735
 
        # Client's medium rooted a transport root (not at the bzrdir)
736
 
        client = FakeClient(transport.base)
737
 
        transport = transport.clone('quack')
738
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
739
 
        reference_format = reference_bzrdir_format.get_branch_format()
740
 
        network_name = reference_format.network_name()
741
 
        reference_repo_fmt = reference_bzrdir_format.repository_format
742
 
        reference_repo_name = reference_repo_fmt.network_name()
743
 
        client.add_expected_call(
744
 
            'BzrDir.create_branch', ('extra/quack/', network_name),
745
 
            'success', ('ok', network_name, '', 'no', 'no', 'yes',
746
 
            reference_repo_name))
747
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
748
 
            _client=client)
749
 
        branch = a_bzrdir.create_branch(repository=repo)
750
 
        # We should have got a remote branch
751
 
        self.assertIsInstance(branch, remote.RemoteBranch)
752
 
        # its format should have the settings from the response
753
 
        format = branch._format
754
 
        self.assertEqual(network_name, format.network_name())
755
 
 
756
626
 
757
627
class TestBzrDirCreateRepository(TestRemote):
758
628
 
776
646
        network_name = reference_format.network_name()
777
647
        client.add_expected_call(
778
648
            'BzrDir.create_repository', ('quack/',
779
 
                'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
780
 
                'False'),
781
 
            'success', ('ok', 'yes', 'yes', 'yes', network_name))
782
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
649
                'Bazaar pack repository format 1 (needs bzr 0.92)\n', 'False'),
 
650
            'success', ('ok', 'no', 'no', 'no', network_name))
 
651
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
783
652
            _client=client)
784
653
        repo = a_bzrdir.create_repository()
785
654
        # We should have got a remote repository
786
655
        self.assertIsInstance(repo, remote.RemoteRepository)
787
656
        # its format should have the settings from the response
788
657
        format = repo._format
789
 
        self.assertTrue(format.rich_root_data)
790
 
        self.assertTrue(format.supports_tree_reference)
791
 
        self.assertTrue(format.supports_external_lookups)
 
658
        self.assertFalse(format.rich_root_data)
 
659
        self.assertFalse(format.supports_tree_reference)
 
660
        self.assertFalse(format.supports_external_lookups)
792
661
        self.assertEqual(network_name, format.network_name())
793
662
 
794
663
 
798
667
        # fallback all the way to the first version.
799
668
        reference_format = self.get_repo_format()
800
669
        network_name = reference_format.network_name()
801
 
        server_url = 'bzr://example.com/'
802
 
        self.permit_url(server_url)
803
 
        client = FakeClient(server_url)
 
670
        client = FakeClient('bzr://example.com/')
804
671
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
805
672
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
806
673
        client.add_success_response('ok', '', 'no', 'no')
812
679
            reference_format.get_format_string(), 'ok')
813
680
        # PackRepository wants to do a stat
814
681
        client.add_success_response('stat', '0', '65535')
815
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
 
682
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
816
683
            _client=client)
817
 
        bzrdir = RemoteBzrDir(remote_transport, RemoteBzrDirFormat(),
 
684
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
818
685
            _client=client)
819
686
        repo = bzrdir.open_repository()
820
687
        self.assertEqual(
832
699
        # fallback to find_repositoryV2
833
700
        reference_format = self.get_repo_format()
834
701
        network_name = reference_format.network_name()
835
 
        server_url = 'bzr://example.com/'
836
 
        self.permit_url(server_url)
837
 
        client = FakeClient(server_url)
 
702
        client = FakeClient('bzr://example.com/')
838
703
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
839
704
        client.add_success_response('ok', '', 'no', 'no', 'no')
840
705
        # A real repository instance will be created to determine the network
845
710
            reference_format.get_format_string(), 'ok')
846
711
        # PackRepository wants to do a stat
847
712
        client.add_success_response('stat', '0', '65535')
848
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
 
713
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
849
714
            _client=client)
850
 
        bzrdir = RemoteBzrDir(remote_transport, RemoteBzrDirFormat(),
 
715
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
851
716
            _client=client)
852
717
        repo = bzrdir.open_repository()
853
718
        self.assertEqual(
868
733
        transport = transport.clone('quack')
869
734
        client = FakeClient(transport.base)
870
735
        client.add_success_response('ok', '', 'no', 'no', 'no', network_name)
871
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
736
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
872
737
            _client=client)
873
738
        repo = bzrdir.open_repository()
874
739
        self.assertEqual(
877
742
        self.assertEqual(network_name, repo._format.network_name())
878
743
 
879
744
 
880
 
class TestBzrDirFormatInitializeEx(TestRemote):
881
 
 
882
 
    def test_success(self):
883
 
        """Simple test for typical successful call."""
884
 
        fmt = RemoteBzrDirFormat()
885
 
        default_format_name = BzrDirFormat.get_default_format().network_name()
886
 
        transport = self.get_transport()
887
 
        client = FakeClient(transport.base)
888
 
        client.add_expected_call(
889
 
            'BzrDirFormat.initialize_ex_1.16',
890
 
                (default_format_name, 'path', 'False', 'False', 'False', '',
891
 
                 '', '', '', 'False'),
892
 
            'success',
893
 
                ('.', 'no', 'no', 'yes', 'repo fmt', 'repo bzrdir fmt',
894
 
                 'bzrdir fmt', 'False', '', '', 'repo lock token'))
895
 
        # XXX: It would be better to call fmt.initialize_on_transport_ex, but
896
 
        # it's currently hard to test that without supplying a real remote
897
 
        # transport connected to a real server.
898
 
        result = fmt._initialize_on_transport_ex_rpc(client, 'path',
899
 
            transport, False, False, False, None, None, None, None, False)
900
 
        self.assertFinished(client)
901
 
 
902
 
    def test_error(self):
903
 
        """Error responses are translated, e.g. 'PermissionDenied' raises the
904
 
        corresponding error from the client.
905
 
        """
906
 
        fmt = RemoteBzrDirFormat()
907
 
        default_format_name = BzrDirFormat.get_default_format().network_name()
908
 
        transport = self.get_transport()
909
 
        client = FakeClient(transport.base)
910
 
        client.add_expected_call(
911
 
            'BzrDirFormat.initialize_ex_1.16',
912
 
                (default_format_name, 'path', 'False', 'False', 'False', '',
913
 
                 '', '', '', 'False'),
914
 
            'error',
915
 
                ('PermissionDenied', 'path', 'extra info'))
916
 
        # XXX: It would be better to call fmt.initialize_on_transport_ex, but
917
 
        # it's currently hard to test that without supplying a real remote
918
 
        # transport connected to a real server.
919
 
        err = self.assertRaises(errors.PermissionDenied,
920
 
            fmt._initialize_on_transport_ex_rpc, client, 'path', transport,
921
 
            False, False, False, None, None, None, None, False)
922
 
        self.assertEqual('path', err.path)
923
 
        self.assertEqual(': extra info', err.extra)
924
 
        self.assertFinished(client)
925
 
 
926
 
    def test_error_from_real_server(self):
927
 
        """Integration test for error translation."""
928
 
        transport = self.make_smart_server('foo')
929
 
        transport = transport.clone('no-such-path')
930
 
        fmt = RemoteBzrDirFormat()
931
 
        err = self.assertRaises(errors.NoSuchFile,
932
 
            fmt.initialize_on_transport_ex, transport, create_prefix=False)
933
 
 
934
 
 
935
745
class OldSmartClient(object):
936
746
    """A fake smart client for test_old_version that just returns a version one
937
747
    response to the 'hello' (query version) command.
960
770
        return OldSmartClient()
961
771
 
962
772
 
963
 
class RemoteBzrDirTestCase(TestRemote):
964
 
 
965
 
    def make_remote_bzrdir(self, transport, client):
966
 
        """Make a RemotebzrDir using 'client' as the _client."""
967
 
        return RemoteBzrDir(transport, RemoteBzrDirFormat(),
968
 
            _client=client)
969
 
 
970
 
 
971
 
class RemoteBranchTestCase(RemoteBzrDirTestCase):
972
 
 
973
 
    def lock_remote_branch(self, branch):
974
 
        """Trick a RemoteBranch into thinking it is locked."""
975
 
        branch._lock_mode = 'w'
976
 
        branch._lock_count = 2
977
 
        branch._lock_token = 'branch token'
978
 
        branch._repo_lock_token = 'repo token'
979
 
        branch.repository._lock_mode = 'w'
980
 
        branch.repository._lock_count = 2
981
 
        branch.repository._lock_token = 'repo token'
 
773
class RemoteBranchTestCase(TestRemote):
982
774
 
983
775
    def make_remote_branch(self, transport, client):
984
776
        """Make a RemoteBranch using 'client' as its _SmartClient.
989
781
        # we do not want bzrdir to make any remote calls, so use False as its
990
782
        # _client.  If it tries to make a remote call, this will fail
991
783
        # immediately.
992
 
        bzrdir = self.make_remote_bzrdir(transport, False)
 
784
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
785
            _client=False)
993
786
        repo = RemoteRepository(bzrdir, None, _client=client)
994
787
        branch_format = self.get_branch_format()
995
788
        format = RemoteBranchFormat(network_name=branch_format.network_name())
1012
805
        transport = transport.clone('quack')
1013
806
        branch = self.make_remote_branch(transport, client)
1014
807
        result = branch.get_parent()
1015
 
        self.assertFinished(client)
 
808
        client.finished_test()
1016
809
        self.assertEqual(None, result)
1017
810
 
1018
811
    def test_parent_relative(self):
1044
837
        branch = self.make_remote_branch(transport, client)
1045
838
        result = branch.get_parent()
1046
839
        self.assertEqual('http://foo/', result)
1047
 
        self.assertFinished(client)
1048
 
 
1049
 
 
1050
 
class TestBranchSetParentLocation(RemoteBranchTestCase):
1051
 
 
1052
 
    def test_no_parent(self):
1053
 
        # We call the verb when setting parent to None
1054
 
        transport = MemoryTransport()
1055
 
        client = FakeClient(transport.base)
1056
 
        client.add_expected_call(
1057
 
            'Branch.get_stacked_on_url', ('quack/',),
1058
 
            'error', ('NotStacked',))
1059
 
        client.add_expected_call(
1060
 
            'Branch.set_parent_location', ('quack/', 'b', 'r', ''),
1061
 
            'success', ())
1062
 
        transport.mkdir('quack')
1063
 
        transport = transport.clone('quack')
1064
 
        branch = self.make_remote_branch(transport, client)
1065
 
        branch._lock_token = 'b'
1066
 
        branch._repo_lock_token = 'r'
1067
 
        branch._set_parent_location(None)
1068
 
        self.assertFinished(client)
1069
 
 
1070
 
    def test_parent(self):
1071
 
        transport = MemoryTransport()
1072
 
        client = FakeClient(transport.base)
1073
 
        client.add_expected_call(
1074
 
            'Branch.get_stacked_on_url', ('kwaak/',),
1075
 
            'error', ('NotStacked',))
1076
 
        client.add_expected_call(
1077
 
            'Branch.set_parent_location', ('kwaak/', 'b', 'r', 'foo'),
1078
 
            'success', ())
1079
 
        transport.mkdir('kwaak')
1080
 
        transport = transport.clone('kwaak')
1081
 
        branch = self.make_remote_branch(transport, client)
1082
 
        branch._lock_token = 'b'
1083
 
        branch._repo_lock_token = 'r'
1084
 
        branch._set_parent_location('foo')
1085
 
        self.assertFinished(client)
1086
 
 
1087
 
    def test_backwards_compat(self):
1088
 
        self.setup_smart_server_with_call_log()
1089
 
        branch = self.make_branch('.')
1090
 
        self.reset_smart_call_log()
1091
 
        verb = 'Branch.set_parent_location'
1092
 
        self.disable_verb(verb)
1093
 
        branch.set_parent('http://foo/')
1094
 
        self.assertLength(12, self.hpss_calls)
1095
840
 
1096
841
 
1097
842
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1120
865
        transport = transport.clone('quack')
1121
866
        branch = self.make_remote_branch(transport, client)
1122
867
        result = branch.tags.get_tag_dict()
1123
 
        self.assertFinished(client)
 
868
        client.finished_test()
1124
869
        self.assertEqual({}, result)
1125
870
 
1126
871
 
1127
 
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1128
 
 
1129
 
    def test_trivial(self):
1130
 
        transport = MemoryTransport()
1131
 
        client = FakeClient(transport.base)
1132
 
        client.add_expected_call(
1133
 
            'Branch.get_stacked_on_url', ('quack/',),
1134
 
            'error', ('NotStacked',))
1135
 
        client.add_expected_call(
1136
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1137
 
            'success', ('',))
1138
 
        transport.mkdir('quack')
1139
 
        transport = transport.clone('quack')
1140
 
        branch = self.make_remote_branch(transport, client)
1141
 
        self.lock_remote_branch(branch)
1142
 
        branch._set_tags_bytes('tags bytes')
1143
 
        self.assertFinished(client)
1144
 
        self.assertEqual('tags bytes', client._calls[-1][-1])
1145
 
 
1146
 
    def test_backwards_compatible(self):
1147
 
        transport = MemoryTransport()
1148
 
        client = FakeClient(transport.base)
1149
 
        client.add_expected_call(
1150
 
            'Branch.get_stacked_on_url', ('quack/',),
1151
 
            'error', ('NotStacked',))
1152
 
        client.add_expected_call(
1153
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1154
 
            'unknown', ('Branch.set_tags_bytes',))
1155
 
        transport.mkdir('quack')
1156
 
        transport = transport.clone('quack')
1157
 
        branch = self.make_remote_branch(transport, client)
1158
 
        self.lock_remote_branch(branch)
1159
 
        class StubRealBranch(object):
1160
 
            def __init__(self):
1161
 
                self.calls = []
1162
 
            def _set_tags_bytes(self, bytes):
1163
 
                self.calls.append(('set_tags_bytes', bytes))
1164
 
        real_branch = StubRealBranch()
1165
 
        branch._real_branch = real_branch
1166
 
        branch._set_tags_bytes('tags bytes')
1167
 
        # Call a second time, to exercise the 'remote version already inferred'
1168
 
        # code path.
1169
 
        branch._set_tags_bytes('tags bytes')
1170
 
        self.assertFinished(client)
1171
 
        self.assertEqual(
1172
 
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1173
 
 
1174
 
 
1175
 
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1176
 
 
1177
 
    def test_uses_last_revision_info_and_tags_by_default(self):
1178
 
        transport = MemoryTransport()
1179
 
        client = FakeClient(transport.base)
1180
 
        client.add_expected_call(
1181
 
            'Branch.get_stacked_on_url', ('quack/',),
1182
 
            'error', ('NotStacked',))
1183
 
        client.add_expected_call(
1184
 
            'Branch.last_revision_info', ('quack/',),
1185
 
            'success', ('ok', '1', 'rev-tip'))
1186
 
        # XXX: this will break if the default format's serialization of tags
1187
 
        # changes, or if the RPC for fetching tags changes from get_tags_bytes.
1188
 
        client.add_expected_call(
1189
 
            'Branch.get_tags_bytes', ('quack/',),
1190
 
            'success', ('d5:tag-17:rev-foo5:tag-27:rev-bare',))
1191
 
        transport.mkdir('quack')
1192
 
        transport = transport.clone('quack')
1193
 
        branch = self.make_remote_branch(transport, client)
1194
 
        result = branch.heads_to_fetch()
1195
 
        self.assertFinished(client)
1196
 
        self.assertEqual(
1197
 
            (set(['rev-tip']), set(['rev-foo', 'rev-bar'])), result)
1198
 
 
1199
 
    def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1200
 
        transport = MemoryTransport()
1201
 
        client = FakeClient(transport.base)
1202
 
        client.add_expected_call(
1203
 
            'Branch.get_stacked_on_url', ('quack/',),
1204
 
            'error', ('NotStacked',))
1205
 
        client.add_expected_call(
1206
 
            'Branch.heads_to_fetch', ('quack/',),
1207
 
            'success', (['tip'], ['tagged-1', 'tagged-2']))
1208
 
        transport.mkdir('quack')
1209
 
        transport = transport.clone('quack')
1210
 
        branch = self.make_remote_branch(transport, client)
1211
 
        branch._format._use_default_local_heads_to_fetch = lambda: False
1212
 
        result = branch.heads_to_fetch()
1213
 
        self.assertFinished(client)
1214
 
        self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1215
 
 
1216
 
    def test_backwards_compatible(self):
1217
 
        self.setup_smart_server_with_call_log()
1218
 
        # Make a branch with a single revision.
1219
 
        builder = self.make_branch_builder('foo')
1220
 
        builder.start_series()
1221
 
        builder.build_snapshot('tip', None, [
1222
 
            ('add', ('', 'root-id', 'directory', ''))])
1223
 
        builder.finish_series()
1224
 
        branch = builder.get_branch()
1225
 
        # Add two tags to that branch
1226
 
        branch.tags.set_tag('tag-1', 'rev-1')
1227
 
        branch.tags.set_tag('tag-2', 'rev-2')
1228
 
        self.addCleanup(branch.lock_read().unlock)
1229
 
        # Disable the heads_to_fetch verb
1230
 
        verb = 'Branch.heads_to_fetch'
1231
 
        self.disable_verb(verb)
1232
 
        self.reset_smart_call_log()
1233
 
        result = branch.heads_to_fetch()
1234
 
        self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1235
 
        self.assertEqual(
1236
 
            ['Branch.last_revision_info', 'Branch.get_tags_bytes'],
1237
 
            [call.call.method for call in self.hpss_calls])
1238
 
 
1239
 
 
1240
872
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1241
873
 
1242
874
    def test_empty_branch(self):
1253
885
        transport = transport.clone('quack')
1254
886
        branch = self.make_remote_branch(transport, client)
1255
887
        result = branch.last_revision_info()
1256
 
        self.assertFinished(client)
 
888
        client.finished_test()
1257
889
        self.assertEqual((0, NULL_REVISION), result)
1258
890
 
1259
891
    def test_non_empty_branch(self):
1297
929
        client.add_expected_call(
1298
930
            'Branch.get_stacked_on_url', ('stacked/',),
1299
931
            'success', ('ok', vfs_url))
1300
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
932
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
1301
933
            _client=client)
1302
934
        repo_fmt = remote.RemoteRepositoryFormat()
1303
935
        repo_fmt._custom_format = stacked_branch.repository._format
1314
946
        client = FakeClient(self.get_url())
1315
947
        branch_network_name = self.get_branch_format().network_name()
1316
948
        client.add_expected_call(
1317
 
            'BzrDir.open_branchV3', ('stacked/',),
 
949
            'BzrDir.open_branchV2', ('stacked/',),
1318
950
            'success', ('branch', branch_network_name))
1319
951
        client.add_expected_call(
1320
952
            'BzrDir.find_repositoryV3', ('stacked/',),
1330
962
        # this will also do vfs access, but that goes direct to the transport
1331
963
        # and isn't seen by the FakeClient.
1332
964
        bzrdir = RemoteBzrDir(self.get_transport('stacked'),
1333
 
            RemoteBzrDirFormat(), _client=client)
 
965
            remote.RemoteBzrDirFormat(), _client=client)
1334
966
        branch = bzrdir.open_branch()
1335
967
        result = branch.get_stacked_on_url()
1336
968
        self.assertEqual('../base', result)
1337
 
        self.assertFinished(client)
 
969
        client.finished_test()
1338
970
        # it's in the fallback list both for the RemoteRepository and its vfs
1339
971
        # repository
1340
972
        self.assertEqual(1, len(branch.repository._fallback_repositories))
1342
974
            len(branch.repository._real_repository._fallback_repositories))
1343
975
 
1344
976
    def test_get_stacked_on_real_branch(self):
1345
 
        base_branch = self.make_branch('base')
1346
 
        stacked_branch = self.make_branch('stacked')
 
977
        base_branch = self.make_branch('base', format='1.6')
 
978
        stacked_branch = self.make_branch('stacked', format='1.6')
1347
979
        stacked_branch.set_stacked_on_url('../base')
1348
980
        reference_format = self.get_repo_format()
1349
981
        network_name = reference_format.network_name()
1350
982
        client = FakeClient(self.get_url())
1351
983
        branch_network_name = self.get_branch_format().network_name()
1352
984
        client.add_expected_call(
1353
 
            'BzrDir.open_branchV3', ('stacked/',),
 
985
            'BzrDir.open_branchV2', ('stacked/',),
1354
986
            'success', ('branch', branch_network_name))
1355
987
        client.add_expected_call(
1356
988
            'BzrDir.find_repositoryV3', ('stacked/',),
1357
 
            'success', ('ok', '', 'yes', 'no', 'yes', network_name))
 
989
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
1358
990
        # called twice, once from constructor and then again by us
1359
991
        client.add_expected_call(
1360
992
            'Branch.get_stacked_on_url', ('stacked/',),
1363
995
            'Branch.get_stacked_on_url', ('stacked/',),
1364
996
            'success', ('ok', '../base'))
1365
997
        bzrdir = RemoteBzrDir(self.get_transport('stacked'),
1366
 
            RemoteBzrDirFormat(), _client=client)
 
998
            remote.RemoteBzrDirFormat(), _client=client)
1367
999
        branch = bzrdir.open_branch()
1368
1000
        result = branch.get_stacked_on_url()
1369
1001
        self.assertEqual('../base', result)
1370
 
        self.assertFinished(client)
 
1002
        client.finished_test()
1371
1003
        # it's in the fallback list both for the RemoteRepository.
1372
1004
        self.assertEqual(1, len(branch.repository._fallback_repositories))
1373
1005
        # And we haven't had to construct a real repository.
1377
1009
class TestBranchSetLastRevision(RemoteBranchTestCase):
1378
1010
 
1379
1011
    def test_set_empty(self):
1380
 
        # _set_last_revision_info('null:') is translated to calling
 
1012
        # set_revision_history([]) is translated to calling
1381
1013
        # Branch.set_last_revision(path, '') on the wire.
1382
1014
        transport = MemoryTransport()
1383
1015
        transport.mkdir('branch')
1405
1037
        # unnecessarily invokes _ensure_real upon a call to lock_write.
1406
1038
        branch._ensure_real = lambda: None
1407
1039
        branch.lock_write()
1408
 
        result = branch._set_last_revision(NULL_REVISION)
 
1040
        result = branch.set_revision_history([])
1409
1041
        branch.unlock()
1410
1042
        self.assertEqual(None, result)
1411
 
        self.assertFinished(client)
 
1043
        client.finished_test()
1412
1044
 
1413
1045
    def test_set_nonempty(self):
1414
 
        # set_last_revision_info(N, rev-idN) is translated to calling
 
1046
        # set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
1415
1047
        # Branch.set_last_revision(path, rev-idN) on the wire.
1416
1048
        transport = MemoryTransport()
1417
1049
        transport.mkdir('branch')
1443
1075
        branch._ensure_real = lambda: None
1444
1076
        # Lock the branch, reset the record of remote calls.
1445
1077
        branch.lock_write()
1446
 
        result = branch._set_last_revision('rev-id2')
 
1078
        result = branch.set_revision_history(['rev-id1', 'rev-id2'])
1447
1079
        branch.unlock()
1448
1080
        self.assertEqual(None, result)
1449
 
        self.assertFinished(client)
 
1081
        client.finished_test()
1450
1082
 
1451
1083
    def test_no_such_revision(self):
1452
1084
        transport = MemoryTransport()
1479
1111
        branch = self.make_remote_branch(transport, client)
1480
1112
        branch.lock_write()
1481
1113
        self.assertRaises(
1482
 
            errors.NoSuchRevision, branch._set_last_revision, 'rev-id')
 
1114
            errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])
1483
1115
        branch.unlock()
1484
 
        self.assertFinished(client)
 
1116
        client.finished_test()
1485
1117
 
1486
1118
    def test_tip_change_rejected(self):
1487
1119
        """TipChangeRejected responses cause a TipChangeRejected exception to
1516
1148
        branch._ensure_real = lambda: None
1517
1149
        branch.lock_write()
1518
1150
        # The 'TipChangeRejected' error response triggered by calling
1519
 
        # set_last_revision_info causes a TipChangeRejected exception.
 
1151
        # set_revision_history causes a TipChangeRejected exception.
1520
1152
        err = self.assertRaises(
1521
 
            errors.TipChangeRejected,
1522
 
            branch._set_last_revision, 'rev-id')
 
1153
            errors.TipChangeRejected, branch.set_revision_history, ['rev-id'])
1523
1154
        # The UTF-8 message from the response has been decoded into a unicode
1524
1155
        # object.
1525
1156
        self.assertIsInstance(err.msg, unicode)
1526
1157
        self.assertEqual(rejection_msg_unicode, err.msg)
1527
1158
        branch.unlock()
1528
 
        self.assertFinished(client)
 
1159
        client.finished_test()
1529
1160
 
1530
1161
 
1531
1162
class TestBranchSetLastRevisionInfo(RemoteBranchTestCase):
1585
1216
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1586
1217
        branch.unlock()
1587
1218
 
 
1219
    def lock_remote_branch(self, branch):
 
1220
        """Trick a RemoteBranch into thinking it is locked."""
 
1221
        branch._lock_mode = 'w'
 
1222
        branch._lock_count = 2
 
1223
        branch._lock_token = 'branch token'
 
1224
        branch._repo_lock_token = 'repo token'
 
1225
        branch.repository._lock_mode = 'w'
 
1226
        branch.repository._lock_count = 2
 
1227
        branch.repository._lock_token = 'repo token'
 
1228
 
1588
1229
    def test_backwards_compatibility(self):
1589
1230
        """If the server does not support the Branch.set_last_revision_info
1590
1231
        verb (which is new in 1.4), then the client falls back to VFS methods.
1631
1272
        self.assertEqual(
1632
1273
            [('set_last_revision_info', 1234, 'a-revision-id')],
1633
1274
            real_branch.calls)
1634
 
        self.assertFinished(client)
 
1275
        client.finished_test()
1635
1276
 
1636
1277
    def test_unexpected_error(self):
1637
1278
        # If the server sends an error the client doesn't understand, it gets
1713
1354
    def test_get_multi_line_branch_conf(self):
1714
1355
        # Make sure that multiple-line branch.conf files are supported
1715
1356
        #
1716
 
        # https://bugs.launchpad.net/bzr/+bug/354075
 
1357
        # https://bugs.edge.launchpad.net/bzr/+bug/354075
1717
1358
        client = FakeClient()
1718
1359
        client.add_expected_call(
1719
1360
            'Branch.get_stacked_on_url', ('memory:///',),
1745
1386
        config = branch._get_config()
1746
1387
        config.set_option('foo', 'bar')
1747
1388
        branch.unlock()
1748
 
        self.assertFinished(client)
1749
 
 
1750
 
    def test_set_option_with_dict(self):
1751
 
        client = FakeClient()
1752
 
        client.add_expected_call(
1753
 
            'Branch.get_stacked_on_url', ('memory:///',),
1754
 
            'error', ('NotStacked',),)
1755
 
        client.add_expected_call(
1756
 
            'Branch.lock_write', ('memory:///', '', ''),
1757
 
            'success', ('ok', 'branch token', 'repo token'))
1758
 
        encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1759
 
        client.add_expected_call(
1760
 
            'Branch.set_config_option_dict', ('memory:///', 'branch token',
1761
 
            'repo token', encoded_dict_value, 'foo', ''),
1762
 
            'success', ())
1763
 
        client.add_expected_call(
1764
 
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1765
 
            'success', ('ok',))
1766
 
        transport = MemoryTransport()
1767
 
        branch = self.make_remote_branch(transport, client)
1768
 
        branch.lock_write()
1769
 
        config = branch._get_config()
1770
 
        config.set_option(
1771
 
            {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1772
 
            'foo')
1773
 
        branch.unlock()
1774
 
        self.assertFinished(client)
 
1389
        client.finished_test()
1775
1390
 
1776
1391
    def test_backwards_compat_set_option(self):
1777
1392
        self.setup_smart_server_with_call_log()
1785
1400
        self.assertLength(10, self.hpss_calls)
1786
1401
        self.assertEqual('value', branch._get_config().get_option('name'))
1787
1402
 
1788
 
    def test_backwards_compat_set_option_with_dict(self):
1789
 
        self.setup_smart_server_with_call_log()
1790
 
        branch = self.make_branch('.')
1791
 
        verb = 'Branch.set_config_option_dict'
1792
 
        self.disable_verb(verb)
1793
 
        branch.lock_write()
1794
 
        self.addCleanup(branch.unlock)
1795
 
        self.reset_smart_call_log()
1796
 
        config = branch._get_config()
1797
 
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1798
 
        config.set_option(value_dict, 'name')
1799
 
        self.assertLength(10, self.hpss_calls)
1800
 
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
1801
 
 
1802
1403
 
1803
1404
class TestBranchLockWrite(RemoteBranchTestCase):
1804
1405
 
1815
1416
        transport = transport.clone('quack')
1816
1417
        branch = self.make_remote_branch(transport, client)
1817
1418
        self.assertRaises(errors.UnlockableTransport, branch.lock_write)
1818
 
        self.assertFinished(client)
1819
 
 
1820
 
 
1821
 
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1822
 
 
1823
 
    def test__get_config(self):
1824
 
        client = FakeClient()
1825
 
        client.add_success_response_with_body('default_stack_on = /\n', 'ok')
1826
 
        transport = MemoryTransport()
1827
 
        bzrdir = self.make_remote_bzrdir(transport, client)
1828
 
        config = bzrdir.get_config()
1829
 
        self.assertEqual('/', config.get_default_stack_on())
1830
 
        self.assertEqual(
1831
 
            [('call_expecting_body', 'BzrDir.get_config_file', ('memory:///',))],
1832
 
            client._calls)
1833
 
 
1834
 
    def test_set_option_uses_vfs(self):
1835
 
        self.setup_smart_server_with_call_log()
1836
 
        bzrdir = self.make_bzrdir('.')
1837
 
        self.reset_smart_call_log()
1838
 
        config = bzrdir.get_config()
1839
 
        config.set_default_stack_on('/')
1840
 
        self.assertLength(3, self.hpss_calls)
1841
 
 
1842
 
    def test_backwards_compat_get_option(self):
1843
 
        self.setup_smart_server_with_call_log()
1844
 
        bzrdir = self.make_bzrdir('.')
1845
 
        verb = 'BzrDir.get_config_file'
1846
 
        self.disable_verb(verb)
1847
 
        self.reset_smart_call_log()
1848
 
        self.assertEqual(None,
1849
 
            bzrdir._get_config().get_option('default_stack_on'))
1850
 
        self.assertLength(3, self.hpss_calls)
 
1419
        client.finished_test()
1851
1420
 
1852
1421
 
1853
1422
class TestTransportIsReadonly(tests.TestCase):
1904
1473
 
1905
1474
class TestRemoteSSHTransportAuthentication(tests.TestCaseInTempDir):
1906
1475
 
1907
 
    def test_defaults_to_none(self):
 
1476
    def test_defaults_to_getuser(self):
1908
1477
        t = RemoteSSHTransport('bzr+ssh://example.com')
1909
 
        self.assertIs(None, t._get_credentials()[0])
 
1478
        self.assertIs(getpass.getuser(), t._get_credentials()[0])
1910
1479
 
1911
1480
    def test_uses_authentication_config(self):
1912
1481
        conf = config.AuthenticationConfig()
1940
1509
        client = FakeClient(transport.base)
1941
1510
        transport = transport.clone(transport_path)
1942
1511
        # we do not want bzrdir to make any remote calls
1943
 
        bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
1512
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
1944
1513
            _client=False)
1945
1514
        repo = RemoteRepository(bzrdir, None, _client=client)
1946
1515
        return repo, client
1947
1516
 
1948
1517
 
1949
 
def remoted_description(format):
1950
 
    return 'Remote: ' + format.get_format_description()
1951
 
 
1952
 
 
1953
 
class TestBranchFormat(tests.TestCase):
1954
 
 
1955
 
    def test_get_format_description(self):
1956
 
        remote_format = RemoteBranchFormat()
1957
 
        real_format = branch.format_registry.get_default()
1958
 
        remote_format._network_name = real_format.network_name()
1959
 
        self.assertEqual(remoted_description(real_format),
1960
 
            remote_format.get_format_description())
1961
 
 
1962
 
 
1963
1518
class TestRepositoryFormat(TestRemoteRepository):
1964
1519
 
1965
1520
    def test_fast_delta(self):
1966
 
        true_name = groupcompress_repo.RepositoryFormat2a().network_name()
 
1521
        true_name = pack_repo.RepositoryFormatPackDevelopment2().network_name()
1967
1522
        true_format = RemoteRepositoryFormat()
1968
1523
        true_format._network_name = true_name
1969
1524
        self.assertEqual(True, true_format.fast_deltas)
1970
 
        false_name = knitpack_repo.RepositoryFormatKnitPack1().network_name()
 
1525
        false_name = pack_repo.RepositoryFormatKnitPack1().network_name()
1971
1526
        false_format = RemoteRepositoryFormat()
1972
1527
        false_format._network_name = false_name
1973
1528
        self.assertEqual(False, false_format.fast_deltas)
1974
1529
 
1975
 
    def test_get_format_description(self):
1976
 
        remote_repo_format = RemoteRepositoryFormat()
1977
 
        real_format = repository.format_registry.get_default()
1978
 
        remote_repo_format._network_name = real_format.network_name()
1979
 
        self.assertEqual(remoted_description(real_format),
1980
 
            remote_repo_format.get_format_description())
1981
 
 
1982
1530
 
1983
1531
class TestRepositoryGatherStats(TestRemoteRepository):
1984
1532
 
2169
1717
        self.assertLength(1, self.hpss_calls)
2170
1718
 
2171
1719
    def disableExtraResults(self):
2172
 
        self.overrideAttr(SmartServerRepositoryGetParentMap,
2173
 
                          'no_extra_results', True)
 
1720
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
1721
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
1722
        def reset_values():
 
1723
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
1724
        self.addCleanup(reset_values)
2174
1725
 
2175
1726
    def test_null_cached_missing_and_stop_key(self):
2176
1727
        self.setup_smart_server_with_call_log()
2235
1786
 
2236
1787
    def test_allows_new_revisions(self):
2237
1788
        """get_parent_map's results can be updated by commit."""
2238
 
        smart_server = test_server.SmartTCPServer_for_testing()
2239
 
        self.start_server(smart_server)
 
1789
        smart_server = server.SmartTCPServer_for_testing()
 
1790
        smart_server.setUp()
 
1791
        self.addCleanup(smart_server.tearDown)
2240
1792
        self.make_branch('branch')
2241
1793
        branch = Branch.open(smart_server.get_url() + '/branch')
2242
1794
        tree = branch.create_checkout('tree', lightweight=True)
2325
1877
        self.assertEqual(('AnUnexpectedError',), e.error_tuple)
2326
1878
 
2327
1879
 
2328
 
class TestRepositoryGetRevIdForRevno(TestRemoteRepository):
2329
 
 
2330
 
    def test_ok(self):
2331
 
        repo, client = self.setup_fake_client_and_repository('quack')
2332
 
        client.add_expected_call(
2333
 
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2334
 
            'success', ('ok', 'rev-five'))
2335
 
        result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2336
 
        self.assertEqual((True, 'rev-five'), result)
2337
 
        self.assertFinished(client)
2338
 
 
2339
 
    def test_history_incomplete(self):
2340
 
        repo, client = self.setup_fake_client_and_repository('quack')
2341
 
        client.add_expected_call(
2342
 
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2343
 
            'success', ('history-incomplete', 10, 'rev-ten'))
2344
 
        result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2345
 
        self.assertEqual((False, (10, 'rev-ten')), result)
2346
 
        self.assertFinished(client)
2347
 
 
2348
 
    def test_history_incomplete_with_fallback(self):
2349
 
        """A 'history-incomplete' response causes the fallback repository to be
2350
 
        queried too, if one is set.
2351
 
        """
2352
 
        # Make a repo with a fallback repo, both using a FakeClient.
2353
 
        format = remote.response_tuple_to_repo_format(
2354
 
            ('yes', 'no', 'yes', self.get_repo_format().network_name()))
2355
 
        repo, client = self.setup_fake_client_and_repository('quack')
2356
 
        repo._format = format
2357
 
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2358
 
            'fallback')
2359
 
        fallback_repo._client = client
2360
 
        fallback_repo._format = format
2361
 
        repo.add_fallback_repository(fallback_repo)
2362
 
        # First the client should ask the primary repo
2363
 
        client.add_expected_call(
2364
 
            'Repository.get_rev_id_for_revno', ('quack/', 1, (42, 'rev-foo')),
2365
 
            'success', ('history-incomplete', 2, 'rev-two'))
2366
 
        # Then it should ask the fallback, using revno/revid from the
2367
 
        # history-incomplete response as the known revno/revid.
2368
 
        client.add_expected_call(
2369
 
            'Repository.get_rev_id_for_revno',('fallback/', 1, (2, 'rev-two')),
2370
 
            'success', ('ok', 'rev-one'))
2371
 
        result = repo.get_rev_id_for_revno(1, (42, 'rev-foo'))
2372
 
        self.assertEqual((True, 'rev-one'), result)
2373
 
        self.assertFinished(client)
2374
 
 
2375
 
    def test_nosuchrevision(self):
2376
 
        # 'nosuchrevision' is returned when the known-revid is not found in the
2377
 
        # remote repo.  The client translates that response to NoSuchRevision.
2378
 
        repo, client = self.setup_fake_client_and_repository('quack')
2379
 
        client.add_expected_call(
2380
 
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2381
 
            'error', ('nosuchrevision', 'rev-foo'))
2382
 
        self.assertRaises(
2383
 
            errors.NoSuchRevision,
2384
 
            repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2385
 
        self.assertFinished(client)
2386
 
 
2387
 
    def test_branch_fallback_locking(self):
2388
 
        """RemoteBranch.get_rev_id takes a read lock, and tries to call the
2389
 
        get_rev_id_for_revno verb.  If the verb is unknown the VFS fallback
2390
 
        will be invoked, which will fail if the repo is unlocked.
2391
 
        """
2392
 
        self.setup_smart_server_with_call_log()
2393
 
        tree = self.make_branch_and_memory_tree('.')
2394
 
        tree.lock_write()
2395
 
        tree.add('')
2396
 
        rev1 = tree.commit('First')
2397
 
        rev2 = tree.commit('Second')
2398
 
        tree.unlock()
2399
 
        branch = tree.branch
2400
 
        self.assertFalse(branch.is_locked())
2401
 
        self.reset_smart_call_log()
2402
 
        verb = 'Repository.get_rev_id_for_revno'
2403
 
        self.disable_verb(verb)
2404
 
        self.assertEqual(rev1, branch.get_rev_id(1))
2405
 
        self.assertLength(1, [call for call in self.hpss_calls if
2406
 
                              call.call.method == verb])
2407
 
 
2408
 
 
2409
1880
class TestRepositoryIsShared(TestRemoteRepository):
2410
1881
 
2411
1882
    def test_is_shared(self):
2437
1908
        transport_path = 'quack'
2438
1909
        repo, client = self.setup_fake_client_and_repository(transport_path)
2439
1910
        client.add_success_response('ok', 'a token')
2440
 
        token = repo.lock_write().repository_token
 
1911
        result = repo.lock_write()
2441
1912
        self.assertEqual(
2442
1913
            [('call', 'Repository.lock_write', ('quack/', ''))],
2443
1914
            client._calls)
2444
 
        self.assertEqual('a token', token)
 
1915
        self.assertEqual('a token', result)
2445
1916
 
2446
1917
    def test_lock_write_already_locked(self):
2447
1918
        transport_path = 'quack'
2526
1997
        self.assertEqual([], client._calls)
2527
1998
 
2528
1999
 
2529
 
class TestRepositoryInsertStreamBase(TestRemoteRepository):
2530
 
    """Base class for Repository.insert_stream and .insert_stream_1.19
2531
 
    tests.
2532
 
    """
2533
 
    
2534
 
    def checkInsertEmptyStream(self, repo, client):
2535
 
        """Insert an empty stream, checking the result.
2536
 
 
2537
 
        This checks that there are no resume_tokens or missing_keys, and that
2538
 
        the client is finished.
2539
 
        """
2540
 
        sink = repo._get_sink()
2541
 
        fmt = repository.format_registry.get_default()
2542
 
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
2543
 
        self.assertEqual([], resume_tokens)
2544
 
        self.assertEqual(set(), missing_keys)
2545
 
        self.assertFinished(client)
2546
 
 
2547
 
 
2548
 
class TestRepositoryInsertStream(TestRepositoryInsertStreamBase):
2549
 
    """Tests for using Repository.insert_stream verb when the _1.19 variant is
2550
 
    not available.
2551
 
 
2552
 
    This test case is very similar to TestRepositoryInsertStream_1_19.
2553
 
    """
2554
 
 
2555
 
    def setUp(self):
2556
 
        TestRemoteRepository.setUp(self)
2557
 
        self.disable_verb('Repository.insert_stream_1.19')
2558
 
 
2559
 
    def test_unlocked_repo(self):
2560
 
        transport_path = 'quack'
2561
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2562
 
        client.add_expected_call(
2563
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2564
 
            'unknown', ('Repository.insert_stream_1.19',))
2565
 
        client.add_expected_call(
2566
 
            'Repository.insert_stream', ('quack/', ''),
2567
 
            'success', ('ok',))
2568
 
        client.add_expected_call(
2569
 
            'Repository.insert_stream', ('quack/', ''),
2570
 
            'success', ('ok',))
2571
 
        self.checkInsertEmptyStream(repo, client)
2572
 
 
2573
 
    def test_locked_repo_with_no_lock_token(self):
2574
 
        transport_path = 'quack'
2575
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2576
 
        client.add_expected_call(
2577
 
            'Repository.lock_write', ('quack/', ''),
2578
 
            'success', ('ok', ''))
2579
 
        client.add_expected_call(
2580
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2581
 
            'unknown', ('Repository.insert_stream_1.19',))
2582
 
        client.add_expected_call(
2583
 
            'Repository.insert_stream', ('quack/', ''),
2584
 
            'success', ('ok',))
2585
 
        client.add_expected_call(
2586
 
            'Repository.insert_stream', ('quack/', ''),
2587
 
            'success', ('ok',))
2588
 
        repo.lock_write()
2589
 
        self.checkInsertEmptyStream(repo, client)
2590
 
 
2591
 
    def test_locked_repo_with_lock_token(self):
2592
 
        transport_path = 'quack'
2593
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2594
 
        client.add_expected_call(
2595
 
            'Repository.lock_write', ('quack/', ''),
2596
 
            'success', ('ok', 'a token'))
2597
 
        client.add_expected_call(
2598
 
            'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2599
 
            'unknown', ('Repository.insert_stream_1.19',))
2600
 
        client.add_expected_call(
2601
 
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
2602
 
            'success', ('ok',))
2603
 
        client.add_expected_call(
2604
 
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
2605
 
            'success', ('ok',))
2606
 
        repo.lock_write()
2607
 
        self.checkInsertEmptyStream(repo, client)
2608
 
 
2609
 
    def test_stream_with_inventory_deltas(self):
2610
 
        """'inventory-deltas' substreams cannot be sent to the
2611
 
        Repository.insert_stream verb, because not all servers that implement
2612
 
        that verb will accept them.  So when one is encountered the RemoteSink
2613
 
        immediately stops using that verb and falls back to VFS insert_stream.
2614
 
        """
2615
 
        transport_path = 'quack'
2616
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2617
 
        client.add_expected_call(
2618
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2619
 
            'unknown', ('Repository.insert_stream_1.19',))
2620
 
        client.add_expected_call(
2621
 
            'Repository.insert_stream', ('quack/', ''),
2622
 
            'success', ('ok',))
2623
 
        client.add_expected_call(
2624
 
            'Repository.insert_stream', ('quack/', ''),
2625
 
            'success', ('ok',))
2626
 
        # Create a fake real repository for insert_stream to fall back on, so
2627
 
        # that we can directly see the records the RemoteSink passes to the
2628
 
        # real sink.
2629
 
        class FakeRealSink:
2630
 
            def __init__(self):
2631
 
                self.records = []
2632
 
            def insert_stream(self, stream, src_format, resume_tokens):
2633
 
                for substream_kind, substream in stream:
2634
 
                    self.records.append(
2635
 
                        (substream_kind, [record.key for record in substream]))
2636
 
                return ['fake tokens'], ['fake missing keys']
2637
 
        fake_real_sink = FakeRealSink()
2638
 
        class FakeRealRepository:
2639
 
            def _get_sink(self):
2640
 
                return fake_real_sink
2641
 
            def is_in_write_group(self):
2642
 
                return False
2643
 
            def refresh_data(self):
2644
 
                return True
2645
 
        repo._real_repository = FakeRealRepository()
2646
 
        sink = repo._get_sink()
2647
 
        fmt = repository.format_registry.get_default()
2648
 
        stream = self.make_stream_with_inv_deltas(fmt)
2649
 
        resume_tokens, missing_keys = sink.insert_stream(stream, fmt, [])
2650
 
        # Every record from the first inventory delta should have been sent to
2651
 
        # the VFS sink.
2652
 
        expected_records = [
2653
 
            ('inventory-deltas', [('rev2',), ('rev3',)]),
2654
 
            ('texts', [('some-rev', 'some-file')])]
2655
 
        self.assertEqual(expected_records, fake_real_sink.records)
2656
 
        # The return values from the real sink's insert_stream are propagated
2657
 
        # back to the original caller.
2658
 
        self.assertEqual(['fake tokens'], resume_tokens)
2659
 
        self.assertEqual(['fake missing keys'], missing_keys)
2660
 
        self.assertFinished(client)
2661
 
 
2662
 
    def make_stream_with_inv_deltas(self, fmt):
2663
 
        """Make a simple stream with an inventory delta followed by more
2664
 
        records and more substreams to test that all records and substreams
2665
 
        from that point on are used.
2666
 
 
2667
 
        This sends, in order:
2668
 
           * inventories substream: rev1, rev2, rev3.  rev2 and rev3 are
2669
 
             inventory-deltas.
2670
 
           * texts substream: (some-rev, some-file)
2671
 
        """
2672
 
        # Define a stream using generators so that it isn't rewindable.
2673
 
        inv = inventory.Inventory(revision_id='rev1')
2674
 
        inv.root.revision = 'rev1'
2675
 
        def stream_with_inv_delta():
2676
 
            yield ('inventories', inventories_substream())
2677
 
            yield ('inventory-deltas', inventory_delta_substream())
2678
 
            yield ('texts', [
2679
 
                versionedfile.FulltextContentFactory(
2680
 
                    ('some-rev', 'some-file'), (), None, 'content')])
2681
 
        def inventories_substream():
2682
 
            # An empty inventory fulltext.  This will be streamed normally.
2683
 
            text = fmt._serializer.write_inventory_to_string(inv)
2684
 
            yield versionedfile.FulltextContentFactory(
2685
 
                ('rev1',), (), None, text)
2686
 
        def inventory_delta_substream():
2687
 
            # An inventory delta.  This can't be streamed via this verb, so it
2688
 
            # will trigger a fallback to VFS insert_stream.
2689
 
            entry = inv.make_entry(
2690
 
                'directory', 'newdir', inv.root.file_id, 'newdir-id')
2691
 
            entry.revision = 'ghost'
2692
 
            delta = [(None, 'newdir', 'newdir-id', entry)]
2693
 
            serializer = inventory_delta.InventoryDeltaSerializer(
2694
 
                versioned_root=True, tree_references=False)
2695
 
            lines = serializer.delta_to_lines('rev1', 'rev2', delta)
2696
 
            yield versionedfile.ChunkedContentFactory(
2697
 
                ('rev2',), (('rev1',)), None, lines)
2698
 
            # Another delta.
2699
 
            lines = serializer.delta_to_lines('rev1', 'rev3', delta)
2700
 
            yield versionedfile.ChunkedContentFactory(
2701
 
                ('rev3',), (('rev1',)), None, lines)
2702
 
        return stream_with_inv_delta()
2703
 
 
2704
 
 
2705
 
class TestRepositoryInsertStream_1_19(TestRepositoryInsertStreamBase):
2706
 
 
2707
 
    def test_unlocked_repo(self):
2708
 
        transport_path = 'quack'
2709
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2710
 
        client.add_expected_call(
2711
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2712
 
            'success', ('ok',))
2713
 
        client.add_expected_call(
2714
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2715
 
            'success', ('ok',))
2716
 
        self.checkInsertEmptyStream(repo, client)
2717
 
 
2718
 
    def test_locked_repo_with_no_lock_token(self):
2719
 
        transport_path = 'quack'
2720
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2721
 
        client.add_expected_call(
2722
 
            'Repository.lock_write', ('quack/', ''),
2723
 
            'success', ('ok', ''))
2724
 
        client.add_expected_call(
2725
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2726
 
            'success', ('ok',))
2727
 
        client.add_expected_call(
2728
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2729
 
            'success', ('ok',))
2730
 
        repo.lock_write()
2731
 
        self.checkInsertEmptyStream(repo, client)
2732
 
 
2733
 
    def test_locked_repo_with_lock_token(self):
2734
 
        transport_path = 'quack'
2735
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2736
 
        client.add_expected_call(
2737
 
            'Repository.lock_write', ('quack/', ''),
2738
 
            'success', ('ok', 'a token'))
2739
 
        client.add_expected_call(
2740
 
            'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2741
 
            'success', ('ok',))
2742
 
        client.add_expected_call(
2743
 
            'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2744
 
            'success', ('ok',))
2745
 
        repo.lock_write()
2746
 
        self.checkInsertEmptyStream(repo, client)
 
2000
class TestRepositoryInsertStream(TestRemoteRepository):
 
2001
 
 
2002
    def test_unlocked_repo(self):
 
2003
        transport_path = 'quack'
 
2004
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
2005
        client.add_expected_call(
 
2006
            'Repository.insert_stream', ('quack/', ''),
 
2007
            'success', ('ok',))
 
2008
        client.add_expected_call(
 
2009
            'Repository.insert_stream', ('quack/', ''),
 
2010
            'success', ('ok',))
 
2011
        sink = repo._get_sink()
 
2012
        fmt = repository.RepositoryFormat.get_default_format()
 
2013
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
 
2014
        self.assertEqual([], resume_tokens)
 
2015
        self.assertEqual(set(), missing_keys)
 
2016
        client.finished_test()
 
2017
 
 
2018
    def test_locked_repo_with_no_lock_token(self):
 
2019
        transport_path = 'quack'
 
2020
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
2021
        client.add_expected_call(
 
2022
            'Repository.lock_write', ('quack/', ''),
 
2023
            'success', ('ok', ''))
 
2024
        client.add_expected_call(
 
2025
            'Repository.insert_stream', ('quack/', ''),
 
2026
            'success', ('ok',))
 
2027
        client.add_expected_call(
 
2028
            'Repository.insert_stream', ('quack/', ''),
 
2029
            'success', ('ok',))
 
2030
        repo.lock_write()
 
2031
        sink = repo._get_sink()
 
2032
        fmt = repository.RepositoryFormat.get_default_format()
 
2033
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
 
2034
        self.assertEqual([], resume_tokens)
 
2035
        self.assertEqual(set(), missing_keys)
 
2036
        client.finished_test()
 
2037
 
 
2038
    def test_locked_repo_with_lock_token(self):
 
2039
        transport_path = 'quack'
 
2040
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
2041
        client.add_expected_call(
 
2042
            'Repository.lock_write', ('quack/', ''),
 
2043
            'success', ('ok', 'a token'))
 
2044
        client.add_expected_call(
 
2045
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
 
2046
            'success', ('ok',))
 
2047
        client.add_expected_call(
 
2048
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
 
2049
            'success', ('ok',))
 
2050
        repo.lock_write()
 
2051
        sink = repo._get_sink()
 
2052
        fmt = repository.RepositoryFormat.get_default_format()
 
2053
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
 
2054
        self.assertEqual([], resume_tokens)
 
2055
        self.assertEqual(set(), missing_keys)
 
2056
        client.finished_test()
2747
2057
 
2748
2058
 
2749
2059
class TestRepositoryTarball(TestRemoteRepository):
2785
2095
    """RemoteRepository.copy_content_into optimizations"""
2786
2096
 
2787
2097
    def test_copy_content_remote_to_local(self):
2788
 
        self.transport_server = test_server.SmartTCPServer_for_testing
 
2098
        self.transport_server = server.SmartTCPServer_for_testing
2789
2099
        src_repo = self.make_repository('repo1')
2790
2100
        src_repo = repository.Repository.open(self.get_url('repo1'))
2791
2101
        # At the moment the tarball-based copy_content_into can't write back
2834
2144
        client.add_expected_call(
2835
2145
            'PackRepository.autopack', ('quack/',), 'success', ('ok',))
2836
2146
        repo.autopack()
2837
 
        self.assertFinished(client)
 
2147
        client.finished_test()
2838
2148
 
2839
2149
    def test_ok_with_real_repo(self):
2840
2150
        """When the server returns 'ok' and there is a _real_repository, then
2870
2180
             ('pack collection autopack',)],
2871
2181
            client._calls)
2872
2182
 
2873
 
    def test_oom_error_reporting(self):
2874
 
        """An out-of-memory condition on the server is reported clearly"""
2875
 
        transport_path = 'quack'
2876
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2877
 
        client.add_expected_call(
2878
 
            'PackRepository.autopack', ('quack/',),
2879
 
            'error', ('MemoryError',))
2880
 
        err = self.assertRaises(errors.BzrError, repo.autopack)
2881
 
        self.assertContainsRe(str(err), "^remote server out of mem")
2882
 
 
2883
2183
 
2884
2184
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
2885
2185
    """Base class for unit tests for bzrlib.remote._translate_error."""
2949
2249
        expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
2950
2250
        self.assertEqual(expected_error, translated_error)
2951
2251
 
2952
 
    def test_nobranch_one_arg(self):
2953
 
        bzrdir = self.make_bzrdir('')
2954
 
        translated_error = self.translateTuple(
2955
 
            ('nobranch', 'extra detail'), bzrdir=bzrdir)
2956
 
        expected_error = errors.NotBranchError(
2957
 
            path=bzrdir.root_transport.base,
2958
 
            detail='extra detail')
2959
 
        self.assertEqual(expected_error, translated_error)
2960
 
 
2961
 
    def test_norepository(self):
2962
 
        bzrdir = self.make_bzrdir('')
2963
 
        translated_error = self.translateTuple(('norepository',),
2964
 
            bzrdir=bzrdir)
2965
 
        expected_error = errors.NoRepositoryPresent(bzrdir)
2966
 
        self.assertEqual(expected_error, translated_error)
2967
 
 
2968
2252
    def test_LockContention(self):
2969
2253
        translated_error = self.translateTuple(('LockContention',))
2970
2254
        expected_error = errors.LockContention('(remote lock)')
2998
2282
        expected_error = errors.DivergedBranches(branch, other_branch)
2999
2283
        self.assertEqual(expected_error, translated_error)
3000
2284
 
3001
 
    def test_NotStacked(self):
3002
 
        branch = self.make_branch('')
3003
 
        translated_error = self.translateTuple(('NotStacked',), branch=branch)
3004
 
        expected_error = errors.NotStacked(branch)
3005
 
        self.assertEqual(expected_error, translated_error)
3006
 
 
3007
2285
    def test_ReadError_no_args(self):
3008
2286
        path = 'a path'
3009
2287
        translated_error = self.translateTuple(('ReadError',), path=path)
3016
2294
        expected_error = errors.ReadError(path)
3017
2295
        self.assertEqual(expected_error, translated_error)
3018
2296
 
3019
 
    def test_IncompatibleRepositories(self):
3020
 
        translated_error = self.translateTuple(('IncompatibleRepositories',
3021
 
            "repo1", "repo2", "details here"))
3022
 
        expected_error = errors.IncompatibleRepositories("repo1", "repo2",
3023
 
            "details here")
3024
 
        self.assertEqual(expected_error, translated_error)
3025
 
 
3026
2297
    def test_PermissionDenied_no_args(self):
3027
2298
        path = 'a path'
3028
 
        translated_error = self.translateTuple(('PermissionDenied',),
3029
 
            path=path)
 
2299
        translated_error = self.translateTuple(('PermissionDenied',), path=path)
3030
2300
        expected_error = errors.PermissionDenied(path)
3031
2301
        self.assertEqual(expected_error, translated_error)
3032
2302
 
3055
2325
        expected_error = errors.PermissionDenied(path, extra)
3056
2326
        self.assertEqual(expected_error, translated_error)
3057
2327
 
3058
 
    # GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3059
 
 
3060
 
    def test_NoSuchFile_context_path(self):
3061
 
        local_path = "local path"
3062
 
        translated_error = self.translateTuple(('ReadError', "remote path"),
3063
 
            path=local_path)
3064
 
        expected_error = errors.ReadError(local_path)
3065
 
        self.assertEqual(expected_error, translated_error)
3066
 
 
3067
 
    def test_NoSuchFile_without_context(self):
3068
 
        remote_path = "remote path"
3069
 
        translated_error = self.translateTuple(('ReadError', remote_path))
3070
 
        expected_error = errors.ReadError(remote_path)
3071
 
        self.assertEqual(expected_error, translated_error)
3072
 
 
3073
 
    def test_ReadOnlyError(self):
3074
 
        translated_error = self.translateTuple(('ReadOnlyError',))
3075
 
        expected_error = errors.TransportNotPossible("readonly transport")
3076
 
        self.assertEqual(expected_error, translated_error)
3077
 
 
3078
 
    def test_MemoryError(self):
3079
 
        translated_error = self.translateTuple(('MemoryError',))
3080
 
        self.assertStartsWith(str(translated_error),
3081
 
            "remote server out of memory")
3082
 
 
3083
 
    def test_generic_IndexError_no_classname(self):
3084
 
        err = errors.ErrorFromSmartServer(('error', "list index out of range"))
3085
 
        translated_error = self.translateErrorFromSmartServer(err)
3086
 
        expected_error = errors.UnknownErrorFromSmartServer(err)
3087
 
        self.assertEqual(expected_error, translated_error)
3088
 
 
3089
 
    # GZ 2011-03-02: TODO test generic non-ascii error string
3090
 
 
3091
 
    def test_generic_KeyError(self):
3092
 
        err = errors.ErrorFromSmartServer(('error', 'KeyError', "1"))
3093
 
        translated_error = self.translateErrorFromSmartServer(err)
3094
 
        expected_error = errors.UnknownErrorFromSmartServer(err)
3095
 
        self.assertEqual(expected_error, translated_error)
3096
 
 
3097
2328
 
3098
2329
class TestErrorTranslationRobustness(TestErrorTranslationBase):
3099
2330
    """Unit tests for bzrlib.remote._translate_error's robustness.
3129
2360
        # In addition to re-raising ErrorFromSmartServer, some debug info has
3130
2361
        # been muttered to the log file for developer to look at.
3131
2362
        self.assertContainsRe(
3132
 
            self.get_log(),
 
2363
            self._get_log(keep_log_file=True),
3133
2364
            "Missing key 'branch' in context")
3134
2365
 
3135
2366
    def test_path_missing(self):
3143
2374
        self.assertEqual(server_error, translated_error)
3144
2375
        # In addition to re-raising ErrorFromSmartServer, some debug info has
3145
2376
        # been muttered to the log file for developer to look at.
3146
 
        self.assertContainsRe(self.get_log(), "Missing key 'path' in context")
 
2377
        self.assertContainsRe(
 
2378
            self._get_log(keep_log_file=True), "Missing key 'path' in context")
3147
2379
 
3148
2380
 
3149
2381
class TestStacking(tests.TestCaseWithTransport):
3167
2399
        stacked_branch = self.make_branch('stacked', format='1.9')
3168
2400
        stacked_branch.set_stacked_on_url('../base')
3169
2401
        # start a server looking at this
3170
 
        smart_server = test_server.SmartTCPServer_for_testing()
3171
 
        self.start_server(smart_server)
 
2402
        smart_server = server.SmartTCPServer_for_testing()
 
2403
        smart_server.setUp()
 
2404
        self.addCleanup(smart_server.tearDown)
3172
2405
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
3173
2406
        # can get its branch and repository
3174
2407
        remote_branch = remote_bzrdir.open_branch()
3177
2410
        try:
3178
2411
            # it should have an appropriate fallback repository, which should also
3179
2412
            # be a RemoteRepository
3180
 
            self.assertLength(1, remote_repo._fallback_repositories)
 
2413
            self.assertEquals(len(remote_repo._fallback_repositories), 1)
3181
2414
            self.assertIsInstance(remote_repo._fallback_repositories[0],
3182
2415
                RemoteRepository)
3183
2416
            # and it has the revision committed to the underlying repository;
3196
2429
        tree1.commit('rev1', rev_id='rev1')
3197
2430
        tree2 = tree1.branch.bzrdir.sprout('tree2', stacked=True
3198
2431
            ).open_workingtree()
3199
 
        local_tree = tree2.branch.create_checkout('local')
3200
 
        local_tree.commit('local changes make me feel good.')
 
2432
        tree2.commit('local changes make me feel good.')
3201
2433
        branch2 = Branch.open(self.get_url('tree2'))
3202
2434
        branch2.lock_read()
3203
2435
        self.addCleanup(branch2.unlock)
3225
2457
                    result.append(content.key[-1])
3226
2458
        return result
3227
2459
 
3228
 
    def get_ordered_revs(self, format, order, branch_factory=None):
 
2460
    def get_ordered_revs(self, format, order):
3229
2461
        """Get a list of the revisions in a stream to format format.
3230
2462
 
3231
2463
        :param format: The format of the target.
3232
2464
        :param order: the order that target should have requested.
3233
 
        :param branch_factory: A callable to create a trunk and stacked branch
3234
 
            to fetch from. If none, self.prepare_stacked_remote_branch is used.
3235
2465
        :result: The revision ids in the stream, in the order seen,
3236
2466
            the topological order of revisions in the source.
3237
2467
        """
3239
2469
        target_repository_format = unordered_format.repository_format
3240
2470
        # Cross check
3241
2471
        self.assertEqual(order, target_repository_format._fetch_order)
3242
 
        if branch_factory is None:
3243
 
            branch_factory = self.prepare_stacked_remote_branch
3244
 
        _, stacked = branch_factory()
 
2472
        trunk, stacked = self.prepare_stacked_remote_branch()
3245
2473
        source = stacked.repository._get_source(target_repository_format)
3246
2474
        tip = stacked.last_revision()
3247
 
        stacked.repository._ensure_real()
3248
 
        graph = stacked.repository.get_graph()
3249
 
        revs = [r for (r,ps) in graph.iter_ancestry([tip])
3250
 
                if r != NULL_REVISION]
3251
 
        revs.reverse()
3252
 
        search = _mod_graph.PendingAncestryResult([tip], stacked.repository)
 
2475
        revs = stacked.repository.get_ancestry(tip)
 
2476
        search = graph.PendingAncestryResult([tip], stacked.repository)
3253
2477
        self.reset_smart_call_log()
3254
2478
        stream = source.get_stream(search)
 
2479
        if None in revs:
 
2480
            revs.remove(None)
3255
2481
        # We trust that if a revision is in the stream the rest of the new
3256
2482
        # content for it is too, as per our main fetch tests; here we are
3257
2483
        # checking that the revisions are actually included at all, and their
3268
2494
        # from the server, then one from the backing branch.
3269
2495
        self.assertLength(2, self.hpss_calls)
3270
2496
 
3271
 
    def test_stacked_on_stacked_get_stream_unordered(self):
3272
 
        # Repository._get_source.get_stream() from a stacked repository which
3273
 
        # is itself stacked yields the full data from all three sources.
3274
 
        def make_stacked_stacked():
3275
 
            _, stacked = self.prepare_stacked_remote_branch()
3276
 
            tree = stacked.bzrdir.sprout('tree3', stacked=True
3277
 
                ).open_workingtree()
3278
 
            local_tree = tree.branch.create_checkout('local-tree3')
3279
 
            local_tree.commit('more local changes are better')
3280
 
            branch = Branch.open(self.get_url('tree3'))
3281
 
            branch.lock_read()
3282
 
            self.addCleanup(branch.unlock)
3283
 
            return None, branch
3284
 
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
3285
 
            branch_factory=make_stacked_stacked)
3286
 
        self.assertEqual(set(expected_revs), set(rev_ord))
3287
 
        # Getting unordered results should have made a streaming data request
3288
 
        # from the server, and one from each backing repo
3289
 
        self.assertLength(3, self.hpss_calls)
3290
 
 
3291
2497
    def test_stacked_get_stream_topological(self):
3292
2498
        # Repository._get_source.get_stream() from a stacked repository with
3293
2499
        # topological sorting yields the full data from both stacked and
3294
2500
        # stacked upon sources in topological order.
3295
2501
        rev_ord, expected_revs = self.get_ordered_revs('knit', 'topological')
3296
2502
        self.assertEqual(expected_revs, rev_ord)
3297
 
        # Getting topological sort requires VFS calls still - one of which is
3298
 
        # pushing up from the bound branch.
3299
 
        self.assertLength(14, self.hpss_calls)
 
2503
        # Getting topological sort requires VFS calls still
 
2504
        self.assertLength(12, self.hpss_calls)
3300
2505
 
3301
2506
    def test_stacked_get_stream_groupcompress(self):
3302
2507
        # Repository._get_source.get_stream() from a stacked repository with
3309
2514
        # from the backing branch, and one from the stacked on branch.
3310
2515
        self.assertLength(2, self.hpss_calls)
3311
2516
 
3312
 
    def test_stacked_pull_more_than_stacking_has_bug_360791(self):
3313
 
        # When pulling some fixed amount of content that is more than the
3314
 
        # source has (because some is coming from a fallback branch, no error
3315
 
        # should be received. This was reported as bug 360791.
3316
 
        # Need three branches: a trunk, a stacked branch, and a preexisting
3317
 
        # branch pulling content from stacked and trunk.
3318
 
        self.setup_smart_server_with_call_log()
3319
 
        trunk = self.make_branch_and_tree('trunk', format="1.9-rich-root")
3320
 
        r1 = trunk.commit('start')
3321
 
        stacked_branch = trunk.branch.create_clone_on_transport(
3322
 
            self.get_transport('stacked'), stacked_on=trunk.branch.base)
3323
 
        local = self.make_branch('local', format='1.9-rich-root')
3324
 
        local.repository.fetch(stacked_branch.repository,
3325
 
            stacked_branch.last_revision())
3326
 
 
3327
2517
 
3328
2518
class TestRemoteBranchEffort(tests.TestCaseWithTransport):
3329
2519
 
3331
2521
        super(TestRemoteBranchEffort, self).setUp()
3332
2522
        # Create a smart server that publishes whatever the backing VFS server
3333
2523
        # does.
3334
 
        self.smart_server = test_server.SmartTCPServer_for_testing()
3335
 
        self.start_server(self.smart_server, self.get_server())
 
2524
        self.smart_server = server.SmartTCPServer_for_testing()
 
2525
        self.smart_server.setUp(self.get_server())
 
2526
        self.addCleanup(self.smart_server.tearDown)
3336
2527
        # Log all HPSS calls into self.hpss_calls.
3337
2528
        _SmartClient.hooks.install_named_hook(
3338
2529
            'call', self.capture_hpss_call, None)
3343
2534
 
3344
2535
    def test_copy_content_into_avoids_revision_history(self):
3345
2536
        local = self.make_branch('local')
3346
 
        builder = self.make_branch_builder('remote')
3347
 
        builder.build_commit(message="Commit.")
 
2537
        remote_backing_tree = self.make_branch_and_tree('remote')
 
2538
        remote_backing_tree.commit("Commit.")
3348
2539
        remote_branch_url = self.smart_server.get_url() + 'remote'
3349
2540
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3350
2541
        local.repository.fetch(remote_branch.repository)
3351
2542
        self.hpss_calls = []
3352
2543
        remote_branch.copy_content_into(local)
3353
2544
        self.assertFalse('Branch.revision_history' in self.hpss_calls)
3354
 
 
3355
 
    def test_fetch_everything_needs_just_one_call(self):
3356
 
        local = self.make_branch('local')
3357
 
        builder = self.make_branch_builder('remote')
3358
 
        builder.build_commit(message="Commit.")
3359
 
        remote_branch_url = self.smart_server.get_url() + 'remote'
3360
 
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3361
 
        self.hpss_calls = []
3362
 
        local.repository.fetch(remote_branch.repository,
3363
 
                fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
3364
 
        self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
3365
 
 
3366
 
    def override_verb(self, verb_name, verb):
3367
 
        request_handlers = request.request_handlers
3368
 
        orig_verb = request_handlers.get(verb_name)
3369
 
        request_handlers.register(verb_name, verb, override_existing=True)
3370
 
        self.addCleanup(request_handlers.register, verb_name, orig_verb,
3371
 
                override_existing=True)
3372
 
 
3373
 
    def test_fetch_everything_backwards_compat(self):
3374
 
        """Can fetch with EverythingResult even with pre 2.4 servers.
3375
 
        
3376
 
        Pre-2.4 do not support 'everything' searches with the
3377
 
        Repository.get_stream_1.19 verb.
3378
 
        """
3379
 
        verb_log = []
3380
 
        class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
3381
 
            """A version of the Repository.get_stream_1.19 verb patched to
3382
 
            reject 'everything' searches the way 2.3 and earlier do.
3383
 
            """
3384
 
            def recreate_search(self, repository, search_bytes, discard_excess=False):
3385
 
                verb_log.append(search_bytes.split('\n', 1)[0])
3386
 
                if search_bytes == 'everything':
3387
 
                    return (None, request.FailedSmartServerResponse(('BadSearch',)))
3388
 
                return super(OldGetStreamVerb,
3389
 
                        self).recreate_search(repository, search_bytes,
3390
 
                            discard_excess=discard_excess)
3391
 
        self.override_verb('Repository.get_stream_1.19', OldGetStreamVerb)
3392
 
        local = self.make_branch('local')
3393
 
        builder = self.make_branch_builder('remote')
3394
 
        builder.build_commit(message="Commit.")
3395
 
        remote_branch_url = self.smart_server.get_url() + 'remote'
3396
 
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3397
 
        self.hpss_calls = []
3398
 
        local.repository.fetch(remote_branch.repository,
3399
 
                fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
3400
 
        # make sure the overridden verb was used
3401
 
        self.assertLength(1, verb_log)
3402
 
        # more than one HPSS call is needed, but because it's a VFS callback
3403
 
        # its hard to predict exactly how many.
3404
 
        self.assertTrue(len(self.hpss_calls) > 1)
3405