~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-23 15:29:35 UTC
  • mfrom: (3943.7.7 bzr.code_style_cleanup)
  • mto: This revision was merged to the branch mainline in revision 4033.
  • Revision ID: john@arbash-meinel.com-20090223152935-oel9m92mwcc6nb4h
Merge the removal of all trailing whitespace, and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for remote bzrdir/branch/repo/etc
18
18
 
19
19
These are proxy objects which act on remote objects by sending messages
20
20
through a smart client.  The proxies are to be created when attempting to open
21
 
the object given a transport that supports smartserver rpc operations.
 
21
the object given a transport that supports smartserver rpc operations. 
22
22
 
23
23
These tests correspond to tests.test_smart, which exercises the server side.
24
24
"""
27
27
from cStringIO import StringIO
28
28
 
29
29
from bzrlib import (
30
 
    branch,
31
30
    bzrdir,
32
31
    config,
33
32
    errors,
34
33
    graph,
35
 
    inventory,
36
 
    inventory_delta,
37
34
    pack,
38
35
    remote,
39
36
    repository,
 
37
    smart,
40
38
    tests,
41
 
    treebuilder,
42
39
    urlutils,
43
 
    versionedfile,
44
40
    )
45
41
from bzrlib.branch import Branch
46
42
from bzrlib.bzrdir import BzrDir, BzrDirFormat
47
43
from bzrlib.remote import (
48
44
    RemoteBranch,
49
 
    RemoteBranchFormat,
50
45
    RemoteBzrDir,
51
46
    RemoteBzrDirFormat,
52
47
    RemoteRepository,
53
 
    RemoteRepositoryFormat,
54
48
    )
55
 
from bzrlib.repofmt import groupcompress_repo, pack_repo
56
49
from bzrlib.revision import NULL_REVISION
57
50
from bzrlib.smart import server, medium
58
51
from bzrlib.smart.client import _SmartClient
59
 
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
60
 
from bzrlib.tests import (
61
 
    condition_isinstance,
62
 
    split_suite_by_condition,
63
 
    multiply_tests,
64
 
    )
65
 
from bzrlib.transport import get_transport
 
52
from bzrlib.symbol_versioning import one_four
 
53
from bzrlib.transport import get_transport, http
66
54
from bzrlib.transport.memory import MemoryTransport
67
55
from bzrlib.transport.remote import (
68
56
    RemoteTransport,
70
58
    RemoteTCPTransport,
71
59
)
72
60
 
73
 
def load_tests(standard_tests, module, loader):
74
 
    to_adapt, result = split_suite_by_condition(
75
 
        standard_tests, condition_isinstance(BasicRemoteObjectTests))
76
 
    smart_server_version_scenarios = [
77
 
        ('HPSS-v2',
78
 
            {'transport_server': server.SmartTCPServer_for_testing_v2_only}),
79
 
        ('HPSS-v3',
80
 
            {'transport_server': server.SmartTCPServer_for_testing})]
81
 
    return multiply_tests(to_adapt, smart_server_version_scenarios, result)
82
 
 
83
61
 
84
62
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
85
63
 
86
64
    def setUp(self):
 
65
        self.transport_server = server.SmartTCPServer_for_testing
87
66
        super(BasicRemoteObjectTests, self).setUp()
88
67
        self.transport = self.get_transport()
89
68
        # make a branch that can be opened over the smart transport
134
113
        b = BzrDir.open_from_transport(self.transport).open_branch()
135
114
        self.assertStartsWith(str(b), 'RemoteBranch(')
136
115
 
137
 
    def test_remote_bzrdir_repr(self):
138
 
        b = BzrDir.open_from_transport(self.transport)
139
 
        self.assertStartsWith(str(b), 'RemoteBzrDir(')
140
 
 
141
 
    def test_remote_branch_format_supports_stacking(self):
142
 
        t = self.transport
143
 
        self.make_branch('unstackable', format='pack-0.92')
144
 
        b = BzrDir.open_from_transport(t.clone('unstackable')).open_branch()
145
 
        self.assertFalse(b._format.supports_stacking())
146
 
        self.make_branch('stackable', format='1.9')
147
 
        b = BzrDir.open_from_transport(t.clone('stackable')).open_branch()
148
 
        self.assertTrue(b._format.supports_stacking())
149
 
 
150
 
    def test_remote_repo_format_supports_external_references(self):
151
 
        t = self.transport
152
 
        bd = self.make_bzrdir('unstackable', format='pack-0.92')
153
 
        r = bd.create_repository()
154
 
        self.assertFalse(r._format.supports_external_lookups)
155
 
        r = BzrDir.open_from_transport(t.clone('unstackable')).open_repository()
156
 
        self.assertFalse(r._format.supports_external_lookups)
157
 
        bd = self.make_bzrdir('stackable', format='1.9')
158
 
        r = bd.create_repository()
159
 
        self.assertTrue(r._format.supports_external_lookups)
160
 
        r = BzrDir.open_from_transport(t.clone('stackable')).open_repository()
161
 
        self.assertTrue(r._format.supports_external_lookups)
162
 
 
163
 
    def test_remote_branch_set_append_revisions_only(self):
164
 
        # Make a format 1.9 branch, which supports append_revisions_only
165
 
        branch = self.make_branch('branch', format='1.9')
166
 
        config = branch.get_config()
167
 
        branch.set_append_revisions_only(True)
168
 
        self.assertEqual(
169
 
            'True', config.get_user_option('append_revisions_only'))
170
 
        branch.set_append_revisions_only(False)
171
 
        self.assertEqual(
172
 
            'False', config.get_user_option('append_revisions_only'))
173
 
 
174
 
    def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
175
 
        branch = self.make_branch('branch', format='knit')
176
 
        config = branch.get_config()
177
 
        self.assertRaises(
178
 
            errors.UpgradeRequired, branch.set_append_revisions_only, True)
179
 
 
180
116
 
181
117
class FakeProtocol(object):
182
118
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
283
219
        self.expecting_body = True
284
220
        return result[1], FakeProtocol(result[2], self)
285
221
 
286
 
    def call_with_body_bytes(self, method, args, body):
287
 
        self._check_call(method, args)
288
 
        self._calls.append(('call_with_body_bytes', method, args, body))
289
 
        result = self._get_next_response()
290
 
        return result[1], FakeProtocol(result[2], self)
291
 
 
292
222
    def call_with_body_bytes_expecting_body(self, method, args, body):
293
223
        self._check_call(method, args)
294
224
        self._calls.append(('call_with_body_bytes_expecting_body', method,
303
233
        stream = list(stream)
304
234
        self._check_call(args[0], args[1:])
305
235
        self._calls.append(('call_with_body_stream', args[0], args[1:], stream))
306
 
        result = self._get_next_response()
307
 
        # The second value returned from call_with_body_stream is supposed to
308
 
        # be a response_handler object, but so far no tests depend on that.
309
 
        response_handler = None 
310
 
        return result[1], response_handler
 
236
        return self._get_next_response()[1]
311
237
 
312
238
 
313
239
class FakeMedium(medium.SmartClientMedium):
336
262
 
337
263
class TestRemote(tests.TestCaseWithMemoryTransport):
338
264
 
339
 
    def get_branch_format(self):
340
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
341
 
        return reference_bzrdir_format.get_branch_format()
342
 
 
343
 
    def get_repo_format(self):
344
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
345
 
        return reference_bzrdir_format.repository_format
346
 
 
347
 
    def assertFinished(self, fake_client):
348
 
        """Assert that all of a FakeClient's expected calls have occurred."""
349
 
        fake_client.finished_test()
 
265
    def disable_verb(self, verb):
 
266
        """Disable a verb for one test."""
 
267
        request_handlers = smart.request.request_handlers
 
268
        orig_method = request_handlers.get(verb)
 
269
        request_handlers.remove(verb)
 
270
        def restoreVerb():
 
271
            request_handlers.register(verb, orig_method)
 
272
        self.addCleanup(restoreVerb)
350
273
 
351
274
 
352
275
class Test_ClientMedium_remote_path_from_transport(tests.TestCase):
422
345
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
423
346
 
424
347
 
425
 
class TestBzrDirCloningMetaDir(TestRemote):
426
 
 
427
 
    def test_backwards_compat(self):
428
 
        self.setup_smart_server_with_call_log()
429
 
        a_dir = self.make_bzrdir('.')
430
 
        self.reset_smart_call_log()
431
 
        verb = 'BzrDir.cloning_metadir'
432
 
        self.disable_verb(verb)
433
 
        format = a_dir.cloning_metadir()
434
 
        call_count = len([call for call in self.hpss_calls if
435
 
            call.call.method == verb])
436
 
        self.assertEqual(1, call_count)
437
 
 
438
 
    def test_branch_reference(self):
439
 
        transport = self.get_transport('quack')
440
 
        referenced = self.make_branch('referenced')
441
 
        expected = referenced.bzrdir.cloning_metadir()
442
 
        client = FakeClient(transport.base)
443
 
        client.add_expected_call(
444
 
            'BzrDir.cloning_metadir', ('quack/', 'False'),
445
 
            'error', ('BranchReference',)),
446
 
        client.add_expected_call(
447
 
            'BzrDir.open_branchV3', ('quack/',),
448
 
            'success', ('ref', self.get_url('referenced'))),
449
 
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
450
 
            _client=client)
451
 
        result = a_bzrdir.cloning_metadir()
452
 
        # We should have got a control dir matching the referenced branch.
453
 
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
454
 
        self.assertEqual(expected._repository_format, result._repository_format)
455
 
        self.assertEqual(expected._branch_format, result._branch_format)
456
 
        self.assertFinished(client)
457
 
 
458
 
    def test_current_server(self):
459
 
        transport = self.get_transport('.')
460
 
        transport = transport.clone('quack')
461
 
        self.make_bzrdir('quack')
462
 
        client = FakeClient(transport.base)
463
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
464
 
        control_name = reference_bzrdir_format.network_name()
465
 
        client.add_expected_call(
466
 
            'BzrDir.cloning_metadir', ('quack/', 'False'),
467
 
            'success', (control_name, '', ('branch', ''))),
468
 
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
469
 
            _client=client)
470
 
        result = a_bzrdir.cloning_metadir()
471
 
        # We should have got a reference control dir with default branch and
472
 
        # repository formats.
473
 
        # This pokes a little, just to be sure.
474
 
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
475
 
        self.assertEqual(None, result._repository_format)
476
 
        self.assertEqual(None, result._branch_format)
477
 
        self.assertFinished(client)
478
 
 
479
 
 
480
 
class TestBzrDirOpen(TestRemote):
481
 
 
482
 
    def make_fake_client_and_transport(self, path='quack'):
483
 
        transport = MemoryTransport()
484
 
        transport.mkdir(path)
485
 
        transport = transport.clone(path)
486
 
        client = FakeClient(transport.base)
487
 
        return client, transport
488
 
 
489
 
    def test_absent(self):
490
 
        client, transport = self.make_fake_client_and_transport()
491
 
        client.add_expected_call(
492
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
493
 
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
494
 
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
495
 
        self.assertFinished(client)
496
 
 
497
 
    def test_present_without_workingtree(self):
498
 
        client, transport = self.make_fake_client_and_transport()
499
 
        client.add_expected_call(
500
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
501
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
502
 
            _client=client, _force_probe=True)
503
 
        self.assertIsInstance(bd, RemoteBzrDir)
504
 
        self.assertFalse(bd.has_workingtree())
505
 
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
506
 
        self.assertFinished(client)
507
 
 
508
 
    def test_present_with_workingtree(self):
509
 
        client, transport = self.make_fake_client_and_transport()
510
 
        client.add_expected_call(
511
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
512
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
513
 
            _client=client, _force_probe=True)
514
 
        self.assertIsInstance(bd, RemoteBzrDir)
515
 
        self.assertTrue(bd.has_workingtree())
516
 
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
517
 
        self.assertFinished(client)
518
 
 
519
 
    def test_backwards_compat(self):
520
 
        client, transport = self.make_fake_client_and_transport()
521
 
        client.add_expected_call(
522
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
523
 
        client.add_expected_call(
524
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
525
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
526
 
            _client=client, _force_probe=True)
527
 
        self.assertIsInstance(bd, RemoteBzrDir)
528
 
        self.assertFinished(client)
529
 
 
530
 
 
531
 
class TestBzrDirOpenBranch(TestRemote):
532
 
 
533
 
    def test_backwards_compat(self):
534
 
        self.setup_smart_server_with_call_log()
535
 
        self.make_branch('.')
536
 
        a_dir = BzrDir.open(self.get_url('.'))
537
 
        self.reset_smart_call_log()
538
 
        verb = 'BzrDir.open_branchV3'
539
 
        self.disable_verb(verb)
540
 
        format = a_dir.open_branch()
541
 
        call_count = len([call for call in self.hpss_calls if
542
 
            call.call.method == verb])
543
 
        self.assertEqual(1, call_count)
 
348
class TestBzrDirOpenBranch(tests.TestCase):
544
349
 
545
350
    def test_branch_present(self):
546
 
        reference_format = self.get_repo_format()
547
 
        network_name = reference_format.network_name()
548
 
        branch_network_name = self.get_branch_format().network_name()
549
351
        transport = MemoryTransport()
550
352
        transport.mkdir('quack')
551
353
        transport = transport.clone('quack')
552
354
        client = FakeClient(transport.base)
553
355
        client.add_expected_call(
554
 
            'BzrDir.open_branchV3', ('quack/',),
555
 
            'success', ('branch', branch_network_name))
 
356
            'BzrDir.open_branch', ('quack/',),
 
357
            'success', ('ok', ''))
556
358
        client.add_expected_call(
557
 
            'BzrDir.find_repositoryV3', ('quack/',),
558
 
            'success', ('ok', '', 'no', 'no', 'no', network_name))
 
359
            'BzrDir.find_repositoryV2', ('quack/',),
 
360
            'success', ('ok', '', 'no', 'no', 'no'))
559
361
        client.add_expected_call(
560
362
            'Branch.get_stacked_on_url', ('quack/',),
561
363
            'error', ('NotStacked',))
564
366
        result = bzrdir.open_branch()
565
367
        self.assertIsInstance(result, RemoteBranch)
566
368
        self.assertEqual(bzrdir, result.bzrdir)
567
 
        self.assertFinished(client)
 
369
        client.finished_test()
568
370
 
569
371
    def test_branch_missing(self):
570
372
        transport = MemoryTransport()
576
378
            _client=client)
577
379
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
578
380
        self.assertEqual(
579
 
            [('call', 'BzrDir.open_branchV3', ('quack/',))],
 
381
            [('call', 'BzrDir.open_branch', ('quack/',))],
580
382
            client._calls)
581
383
 
582
384
    def test__get_tree_branch(self):
602
404
        # transmitted as "~", not "%7E".
603
405
        transport = RemoteTCPTransport('bzr://localhost/~hello/')
604
406
        client = FakeClient(transport.base)
605
 
        reference_format = self.get_repo_format()
606
 
        network_name = reference_format.network_name()
607
 
        branch_network_name = self.get_branch_format().network_name()
608
 
        client.add_expected_call(
609
 
            'BzrDir.open_branchV3', ('~hello/',),
610
 
            'success', ('branch', branch_network_name))
611
 
        client.add_expected_call(
612
 
            'BzrDir.find_repositoryV3', ('~hello/',),
613
 
            'success', ('ok', '', 'no', 'no', 'no', network_name))
 
407
        client.add_expected_call(
 
408
            'BzrDir.open_branch', ('~hello/',),
 
409
            'success', ('ok', ''))
 
410
        client.add_expected_call(
 
411
            'BzrDir.find_repositoryV2', ('~hello/',),
 
412
            'success', ('ok', '', 'no', 'no', 'no'))
614
413
        client.add_expected_call(
615
414
            'Branch.get_stacked_on_url', ('~hello/',),
616
415
            'error', ('NotStacked',))
617
416
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
618
417
            _client=client)
619
418
        result = bzrdir.open_branch()
620
 
        self.assertFinished(client)
 
419
        client.finished_test()
621
420
 
622
421
    def check_open_repository(self, rich_root, subtrees, external_lookup='no'):
623
 
        reference_format = self.get_repo_format()
624
 
        network_name = reference_format.network_name()
625
422
        transport = MemoryTransport()
626
423
        transport.mkdir('quack')
627
424
        transport = transport.clone('quack')
635
432
            subtree_response = 'no'
636
433
        client = FakeClient(transport.base)
637
434
        client.add_success_response(
638
 
            'ok', '', rich_response, subtree_response, external_lookup,
639
 
            network_name)
 
435
            'ok', '', rich_response, subtree_response, external_lookup)
640
436
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
641
437
            _client=client)
642
438
        result = bzrdir.open_repository()
643
439
        self.assertEqual(
644
 
            [('call', 'BzrDir.find_repositoryV3', ('quack/',))],
 
440
            [('call', 'BzrDir.find_repositoryV2', ('quack/',))],
645
441
            client._calls)
646
442
        self.assertIsInstance(result, RemoteRepository)
647
443
        self.assertEqual(bzrdir, result.bzrdir)
663
459
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
664
460
 
665
461
 
666
 
class TestBzrDirCreateBranch(TestRemote):
667
 
 
668
 
    def test_backwards_compat(self):
669
 
        self.setup_smart_server_with_call_log()
670
 
        repo = self.make_repository('.')
671
 
        self.reset_smart_call_log()
672
 
        self.disable_verb('BzrDir.create_branch')
673
 
        branch = repo.bzrdir.create_branch()
674
 
        create_branch_call_count = len([call for call in self.hpss_calls if
675
 
            call.call.method == 'BzrDir.create_branch'])
676
 
        self.assertEqual(1, create_branch_call_count)
677
 
 
678
 
    def test_current_server(self):
679
 
        transport = self.get_transport('.')
680
 
        transport = transport.clone('quack')
681
 
        self.make_repository('quack')
682
 
        client = FakeClient(transport.base)
683
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
684
 
        reference_format = reference_bzrdir_format.get_branch_format()
685
 
        network_name = reference_format.network_name()
686
 
        reference_repo_fmt = reference_bzrdir_format.repository_format
687
 
        reference_repo_name = reference_repo_fmt.network_name()
688
 
        client.add_expected_call(
689
 
            'BzrDir.create_branch', ('quack/', network_name),
690
 
            'success', ('ok', network_name, '', 'no', 'no', 'yes',
691
 
            reference_repo_name))
692
 
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
693
 
            _client=client)
694
 
        branch = a_bzrdir.create_branch()
695
 
        # We should have got a remote branch
696
 
        self.assertIsInstance(branch, remote.RemoteBranch)
697
 
        # its format should have the settings from the response
698
 
        format = branch._format
699
 
        self.assertEqual(network_name, format.network_name())
700
 
 
701
 
 
702
462
class TestBzrDirCreateRepository(TestRemote):
703
463
 
704
464
    def test_backwards_compat(self):
708
468
        self.disable_verb('BzrDir.create_repository')
709
469
        repo = bzrdir.create_repository()
710
470
        create_repo_call_count = len([call for call in self.hpss_calls if
711
 
            call.call.method == 'BzrDir.create_repository'])
 
471
            call[0].method == 'BzrDir.create_repository'])
712
472
        self.assertEqual(1, create_repo_call_count)
713
473
 
714
474
    def test_current_server(self):
721
481
        network_name = reference_format.network_name()
722
482
        client.add_expected_call(
723
483
            'BzrDir.create_repository', ('quack/',
724
 
                'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
725
 
                'False'),
726
 
            'success', ('ok', 'yes', 'yes', 'yes', network_name))
 
484
                'Bazaar pack repository format 1 (needs bzr 0.92)\n', 'False'),
 
485
            'success', ('ok', 'no', 'no', 'no', network_name))
727
486
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
728
487
            _client=client)
729
488
        repo = a_bzrdir.create_repository()
731
490
        self.assertIsInstance(repo, remote.RemoteRepository)
732
491
        # its format should have the settings from the response
733
492
        format = repo._format
734
 
        self.assertTrue(format.rich_root_data)
735
 
        self.assertTrue(format.supports_tree_reference)
736
 
        self.assertTrue(format.supports_external_lookups)
 
493
        self.assertFalse(format.rich_root_data)
 
494
        self.assertFalse(format.supports_tree_reference)
 
495
        self.assertFalse(format.supports_external_lookups)
737
496
        self.assertEqual(network_name, format.network_name())
738
497
 
739
498
 
740
 
class TestBzrDirOpenRepository(TestRemote):
 
499
class TestBzrDirOpenRepository(tests.TestCase):
741
500
 
742
 
    def test_backwards_compat_1_2_3(self):
743
 
        # fallback all the way to the first version.
744
 
        reference_format = self.get_repo_format()
745
 
        network_name = reference_format.network_name()
746
 
        server_url = 'bzr://example.com/'
747
 
        self.permit_url(server_url)
748
 
        client = FakeClient(server_url)
749
 
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
 
501
    def test_backwards_compat_1_2(self):
 
502
        transport = MemoryTransport()
 
503
        transport.mkdir('quack')
 
504
        transport = transport.clone('quack')
 
505
        client = FakeClient(transport.base)
750
506
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
751
507
        client.add_success_response('ok', '', 'no', 'no')
752
 
        # A real repository instance will be created to determine the network
753
 
        # name.
754
 
        client.add_success_response_with_body(
755
 
            "Bazaar-NG meta directory, format 1\n", 'ok')
756
 
        client.add_success_response_with_body(
757
 
            reference_format.get_format_string(), 'ok')
758
 
        # PackRepository wants to do a stat
759
 
        client.add_success_response('stat', '0', '65535')
760
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
761
 
            _client=client)
762
 
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
763
 
            _client=client)
764
 
        repo = bzrdir.open_repository()
765
 
        self.assertEqual(
766
 
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
767
 
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
768
 
             ('call', 'BzrDir.find_repository', ('quack/',)),
769
 
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
770
 
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
771
 
             ('call', 'stat', ('/quack/.bzr/repository',)),
772
 
             ],
773
 
            client._calls)
774
 
        self.assertEqual(network_name, repo._format.network_name())
775
 
 
776
 
    def test_backwards_compat_2(self):
777
 
        # fallback to find_repositoryV2
778
 
        reference_format = self.get_repo_format()
779
 
        network_name = reference_format.network_name()
780
 
        server_url = 'bzr://example.com/'
781
 
        self.permit_url(server_url)
782
 
        client = FakeClient(server_url)
783
 
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
784
 
        client.add_success_response('ok', '', 'no', 'no', 'no')
785
 
        # A real repository instance will be created to determine the network
786
 
        # name.
787
 
        client.add_success_response_with_body(
788
 
            "Bazaar-NG meta directory, format 1\n", 'ok')
789
 
        client.add_success_response_with_body(
790
 
            reference_format.get_format_string(), 'ok')
791
 
        # PackRepository wants to do a stat
792
 
        client.add_success_response('stat', '0', '65535')
793
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
794
 
            _client=client)
795
 
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
796
 
            _client=client)
797
 
        repo = bzrdir.open_repository()
798
 
        self.assertEqual(
799
 
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
800
 
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
801
 
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
802
 
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
803
 
             ('call', 'stat', ('/quack/.bzr/repository',)),
804
 
             ],
805
 
            client._calls)
806
 
        self.assertEqual(network_name, repo._format.network_name())
807
 
 
808
 
    def test_current_server(self):
809
 
        reference_format = self.get_repo_format()
810
 
        network_name = reference_format.network_name()
811
 
        transport = MemoryTransport()
812
 
        transport.mkdir('quack')
813
 
        transport = transport.clone('quack')
814
 
        client = FakeClient(transport.base)
815
 
        client.add_success_response('ok', '', 'no', 'no', 'no', network_name)
816
508
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
817
509
            _client=client)
818
510
        repo = bzrdir.open_repository()
819
511
        self.assertEqual(
820
 
            [('call', 'BzrDir.find_repositoryV3', ('quack/',))],
 
512
            [('call', 'BzrDir.find_repositoryV2', ('quack/',)),
 
513
             ('call', 'BzrDir.find_repository', ('quack/',))],
821
514
            client._calls)
822
 
        self.assertEqual(network_name, repo._format.network_name())
823
 
 
824
 
 
825
 
class TestBzrDirFormatInitializeEx(TestRemote):
826
 
 
827
 
    def test_success(self):
828
 
        """Simple test for typical successful call."""
829
 
        fmt = bzrdir.RemoteBzrDirFormat()
830
 
        default_format_name = BzrDirFormat.get_default_format().network_name()
831
 
        transport = self.get_transport()
832
 
        client = FakeClient(transport.base)
833
 
        client.add_expected_call(
834
 
            'BzrDirFormat.initialize_ex_1.16',
835
 
                (default_format_name, 'path', 'False', 'False', 'False', '',
836
 
                 '', '', '', 'False'),
837
 
            'success',
838
 
                ('.', 'no', 'no', 'yes', 'repo fmt', 'repo bzrdir fmt',
839
 
                 'bzrdir fmt', 'False', '', '', 'repo lock token'))
840
 
        # XXX: It would be better to call fmt.initialize_on_transport_ex, but
841
 
        # it's currently hard to test that without supplying a real remote
842
 
        # transport connected to a real server.
843
 
        result = fmt._initialize_on_transport_ex_rpc(client, 'path',
844
 
            transport, False, False, False, None, None, None, None, False)
845
 
        self.assertFinished(client)
846
 
 
847
 
    def test_error(self):
848
 
        """Error responses are translated, e.g. 'PermissionDenied' raises the
849
 
        corresponding error from the client.
850
 
        """
851
 
        fmt = bzrdir.RemoteBzrDirFormat()
852
 
        default_format_name = BzrDirFormat.get_default_format().network_name()
853
 
        transport = self.get_transport()
854
 
        client = FakeClient(transport.base)
855
 
        client.add_expected_call(
856
 
            'BzrDirFormat.initialize_ex_1.16',
857
 
                (default_format_name, 'path', 'False', 'False', 'False', '',
858
 
                 '', '', '', 'False'),
859
 
            'error',
860
 
                ('PermissionDenied', 'path', 'extra info'))
861
 
        # XXX: It would be better to call fmt.initialize_on_transport_ex, but
862
 
        # it's currently hard to test that without supplying a real remote
863
 
        # transport connected to a real server.
864
 
        err = self.assertRaises(errors.PermissionDenied,
865
 
            fmt._initialize_on_transport_ex_rpc, client, 'path', transport,
866
 
            False, False, False, None, None, None, None, False)
867
 
        self.assertEqual('path', err.path)
868
 
        self.assertEqual(': extra info', err.extra)
869
 
        self.assertFinished(client)
870
 
 
871
 
    def test_error_from_real_server(self):
872
 
        """Integration test for error translation."""
873
 
        transport = self.make_smart_server('foo')
874
 
        transport = transport.clone('no-such-path')
875
 
        fmt = bzrdir.RemoteBzrDirFormat()
876
 
        err = self.assertRaises(errors.NoSuchFile,
877
 
            fmt.initialize_on_transport_ex, transport, create_prefix=False)
878
515
 
879
516
 
880
517
class OldSmartClient(object):
905
542
        return OldSmartClient()
906
543
 
907
544
 
908
 
class RemoteBzrDirTestCase(TestRemote):
909
 
 
910
 
    def make_remote_bzrdir(self, transport, client):
911
 
        """Make a RemotebzrDir using 'client' as the _client."""
912
 
        return RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
913
 
            _client=client)
914
 
 
915
 
 
916
 
class RemoteBranchTestCase(RemoteBzrDirTestCase):
917
 
 
918
 
    def lock_remote_branch(self, branch):
919
 
        """Trick a RemoteBranch into thinking it is locked."""
920
 
        branch._lock_mode = 'w'
921
 
        branch._lock_count = 2
922
 
        branch._lock_token = 'branch token'
923
 
        branch._repo_lock_token = 'repo token'
924
 
        branch.repository._lock_mode = 'w'
925
 
        branch.repository._lock_count = 2
926
 
        branch.repository._lock_token = 'repo token'
 
545
class RemoteBranchTestCase(tests.TestCase):
927
546
 
928
547
    def make_remote_branch(self, transport, client):
929
548
        """Make a RemoteBranch using 'client' as its _SmartClient.
934
553
        # we do not want bzrdir to make any remote calls, so use False as its
935
554
        # _client.  If it tries to make a remote call, this will fail
936
555
        # immediately.
937
 
        bzrdir = self.make_remote_bzrdir(transport, False)
 
556
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
557
            _client=False)
938
558
        repo = RemoteRepository(bzrdir, None, _client=client)
939
 
        branch_format = self.get_branch_format()
940
 
        format = RemoteBranchFormat(network_name=branch_format.network_name())
941
 
        return RemoteBranch(bzrdir, repo, _client=client, format=format)
942
 
 
943
 
 
944
 
class TestBranchGetParent(RemoteBranchTestCase):
945
 
 
946
 
    def test_no_parent(self):
947
 
        # in an empty branch we decode the response properly
948
 
        transport = MemoryTransport()
949
 
        client = FakeClient(transport.base)
950
 
        client.add_expected_call(
951
 
            'Branch.get_stacked_on_url', ('quack/',),
952
 
            'error', ('NotStacked',))
953
 
        client.add_expected_call(
954
 
            'Branch.get_parent', ('quack/',),
955
 
            'success', ('',))
956
 
        transport.mkdir('quack')
957
 
        transport = transport.clone('quack')
958
 
        branch = self.make_remote_branch(transport, client)
959
 
        result = branch.get_parent()
960
 
        self.assertFinished(client)
961
 
        self.assertEqual(None, result)
962
 
 
963
 
    def test_parent_relative(self):
964
 
        transport = MemoryTransport()
965
 
        client = FakeClient(transport.base)
966
 
        client.add_expected_call(
967
 
            'Branch.get_stacked_on_url', ('kwaak/',),
968
 
            'error', ('NotStacked',))
969
 
        client.add_expected_call(
970
 
            'Branch.get_parent', ('kwaak/',),
971
 
            'success', ('../foo/',))
972
 
        transport.mkdir('kwaak')
973
 
        transport = transport.clone('kwaak')
974
 
        branch = self.make_remote_branch(transport, client)
975
 
        result = branch.get_parent()
976
 
        self.assertEqual(transport.clone('../foo').base, result)
977
 
 
978
 
    def test_parent_absolute(self):
979
 
        transport = MemoryTransport()
980
 
        client = FakeClient(transport.base)
981
 
        client.add_expected_call(
982
 
            'Branch.get_stacked_on_url', ('kwaak/',),
983
 
            'error', ('NotStacked',))
984
 
        client.add_expected_call(
985
 
            'Branch.get_parent', ('kwaak/',),
986
 
            'success', ('http://foo/',))
987
 
        transport.mkdir('kwaak')
988
 
        transport = transport.clone('kwaak')
989
 
        branch = self.make_remote_branch(transport, client)
990
 
        result = branch.get_parent()
991
 
        self.assertEqual('http://foo/', result)
992
 
        self.assertFinished(client)
993
 
 
994
 
 
995
 
class TestBranchSetParentLocation(RemoteBranchTestCase):
996
 
 
997
 
    def test_no_parent(self):
998
 
        # We call the verb when setting parent to None
999
 
        transport = MemoryTransport()
1000
 
        client = FakeClient(transport.base)
1001
 
        client.add_expected_call(
1002
 
            'Branch.get_stacked_on_url', ('quack/',),
1003
 
            'error', ('NotStacked',))
1004
 
        client.add_expected_call(
1005
 
            'Branch.set_parent_location', ('quack/', 'b', 'r', ''),
1006
 
            'success', ())
1007
 
        transport.mkdir('quack')
1008
 
        transport = transport.clone('quack')
1009
 
        branch = self.make_remote_branch(transport, client)
1010
 
        branch._lock_token = 'b'
1011
 
        branch._repo_lock_token = 'r'
1012
 
        branch._set_parent_location(None)
1013
 
        self.assertFinished(client)
1014
 
 
1015
 
    def test_parent(self):
1016
 
        transport = MemoryTransport()
1017
 
        client = FakeClient(transport.base)
1018
 
        client.add_expected_call(
1019
 
            'Branch.get_stacked_on_url', ('kwaak/',),
1020
 
            'error', ('NotStacked',))
1021
 
        client.add_expected_call(
1022
 
            'Branch.set_parent_location', ('kwaak/', 'b', 'r', 'foo'),
1023
 
            'success', ())
1024
 
        transport.mkdir('kwaak')
1025
 
        transport = transport.clone('kwaak')
1026
 
        branch = self.make_remote_branch(transport, client)
1027
 
        branch._lock_token = 'b'
1028
 
        branch._repo_lock_token = 'r'
1029
 
        branch._set_parent_location('foo')
1030
 
        self.assertFinished(client)
1031
 
 
1032
 
    def test_backwards_compat(self):
1033
 
        self.setup_smart_server_with_call_log()
1034
 
        branch = self.make_branch('.')
1035
 
        self.reset_smart_call_log()
1036
 
        verb = 'Branch.set_parent_location'
1037
 
        self.disable_verb(verb)
1038
 
        branch.set_parent('http://foo/')
1039
 
        self.assertLength(12, self.hpss_calls)
1040
 
 
1041
 
 
1042
 
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1043
 
 
1044
 
    def test_backwards_compat(self):
1045
 
        self.setup_smart_server_with_call_log()
1046
 
        branch = self.make_branch('.')
1047
 
        self.reset_smart_call_log()
1048
 
        verb = 'Branch.get_tags_bytes'
1049
 
        self.disable_verb(verb)
1050
 
        branch.tags.get_tag_dict()
1051
 
        call_count = len([call for call in self.hpss_calls if
1052
 
            call.call.method == verb])
1053
 
        self.assertEqual(1, call_count)
1054
 
 
1055
 
    def test_trivial(self):
1056
 
        transport = MemoryTransport()
1057
 
        client = FakeClient(transport.base)
1058
 
        client.add_expected_call(
1059
 
            'Branch.get_stacked_on_url', ('quack/',),
1060
 
            'error', ('NotStacked',))
1061
 
        client.add_expected_call(
1062
 
            'Branch.get_tags_bytes', ('quack/',),
1063
 
            'success', ('',))
1064
 
        transport.mkdir('quack')
1065
 
        transport = transport.clone('quack')
1066
 
        branch = self.make_remote_branch(transport, client)
1067
 
        result = branch.tags.get_tag_dict()
1068
 
        self.assertFinished(client)
1069
 
        self.assertEqual({}, result)
1070
 
 
1071
 
 
1072
 
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1073
 
 
1074
 
    def test_trivial(self):
1075
 
        transport = MemoryTransport()
1076
 
        client = FakeClient(transport.base)
1077
 
        client.add_expected_call(
1078
 
            'Branch.get_stacked_on_url', ('quack/',),
1079
 
            'error', ('NotStacked',))
1080
 
        client.add_expected_call(
1081
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1082
 
            'success', ('',))
1083
 
        transport.mkdir('quack')
1084
 
        transport = transport.clone('quack')
1085
 
        branch = self.make_remote_branch(transport, client)
1086
 
        self.lock_remote_branch(branch)
1087
 
        branch._set_tags_bytes('tags bytes')
1088
 
        self.assertFinished(client)
1089
 
        self.assertEqual('tags bytes', client._calls[-1][-1])
1090
 
 
1091
 
    def test_backwards_compatible(self):
1092
 
        transport = MemoryTransport()
1093
 
        client = FakeClient(transport.base)
1094
 
        client.add_expected_call(
1095
 
            'Branch.get_stacked_on_url', ('quack/',),
1096
 
            'error', ('NotStacked',))
1097
 
        client.add_expected_call(
1098
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1099
 
            'unknown', ('Branch.set_tags_bytes',))
1100
 
        transport.mkdir('quack')
1101
 
        transport = transport.clone('quack')
1102
 
        branch = self.make_remote_branch(transport, client)
1103
 
        self.lock_remote_branch(branch)
1104
 
        class StubRealBranch(object):
1105
 
            def __init__(self):
1106
 
                self.calls = []
1107
 
            def _set_tags_bytes(self, bytes):
1108
 
                self.calls.append(('set_tags_bytes', bytes))
1109
 
        real_branch = StubRealBranch()
1110
 
        branch._real_branch = real_branch
1111
 
        branch._set_tags_bytes('tags bytes')
1112
 
        # Call a second time, to exercise the 'remote version already inferred'
1113
 
        # code path.
1114
 
        branch._set_tags_bytes('tags bytes')
1115
 
        self.assertFinished(client)
1116
 
        self.assertEqual(
1117
 
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
 
559
        return RemoteBranch(bzrdir, repo, _client=client)
1118
560
 
1119
561
 
1120
562
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1133
575
        transport = transport.clone('quack')
1134
576
        branch = self.make_remote_branch(transport, client)
1135
577
        result = branch.last_revision_info()
1136
 
        self.assertFinished(client)
 
578
        client.finished_test()
1137
579
        self.assertEqual((0, NULL_REVISION), result)
1138
580
 
1139
581
    def test_non_empty_branch(self):
1154
596
        self.assertEqual((2, revid), result)
1155
597
 
1156
598
 
1157
 
class TestBranch_get_stacked_on_url(TestRemote):
 
599
class TestBranch_get_stacked_on_url(tests.TestCaseWithMemoryTransport):
1158
600
    """Test Branch._get_stacked_on_url rpc"""
1159
601
 
1160
602
    def test_get_stacked_on_invalid_url(self):
1179
621
            'success', ('ok', vfs_url))
1180
622
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
1181
623
            _client=client)
1182
 
        repo_fmt = remote.RemoteRepositoryFormat()
1183
 
        repo_fmt._custom_format = stacked_branch.repository._format
1184
 
        branch = RemoteBranch(bzrdir, RemoteRepository(bzrdir, repo_fmt),
 
624
        branch = RemoteBranch(bzrdir, RemoteRepository(bzrdir, None),
1185
625
            _client=client)
1186
626
        result = branch.get_stacked_on_url()
1187
627
        self.assertEqual(vfs_url, result)
1192
632
        stacked_branch = self.make_branch('stacked', format='1.6')
1193
633
        stacked_branch.set_stacked_on_url('../base')
1194
634
        client = FakeClient(self.get_url())
1195
 
        branch_network_name = self.get_branch_format().network_name()
1196
 
        client.add_expected_call(
1197
 
            'BzrDir.open_branchV3', ('stacked/',),
1198
 
            'success', ('branch', branch_network_name))
1199
 
        client.add_expected_call(
1200
 
            'BzrDir.find_repositoryV3', ('stacked/',),
1201
 
            'success', ('ok', '', 'no', 'no', 'yes',
1202
 
                stacked_branch.repository._format.network_name()))
 
635
        client.add_expected_call(
 
636
            'BzrDir.open_branch', ('stacked/',),
 
637
            'success', ('ok', ''))
 
638
        client.add_expected_call(
 
639
            'BzrDir.find_repositoryV2', ('stacked/',),
 
640
            'success', ('ok', '', 'no', 'no', 'no'))
1203
641
        # called twice, once from constructor and then again by us
1204
642
        client.add_expected_call(
1205
643
            'Branch.get_stacked_on_url', ('stacked/',),
1214
652
        branch = bzrdir.open_branch()
1215
653
        result = branch.get_stacked_on_url()
1216
654
        self.assertEqual('../base', result)
1217
 
        self.assertFinished(client)
 
655
        client.finished_test()
1218
656
        # it's in the fallback list both for the RemoteRepository and its vfs
1219
657
        # repository
1220
658
        self.assertEqual(1, len(branch.repository._fallback_repositories))
1225
663
        base_branch = self.make_branch('base', format='1.6')
1226
664
        stacked_branch = self.make_branch('stacked', format='1.6')
1227
665
        stacked_branch.set_stacked_on_url('../base')
1228
 
        reference_format = self.get_repo_format()
1229
 
        network_name = reference_format.network_name()
1230
666
        client = FakeClient(self.get_url())
1231
 
        branch_network_name = self.get_branch_format().network_name()
1232
 
        client.add_expected_call(
1233
 
            'BzrDir.open_branchV3', ('stacked/',),
1234
 
            'success', ('branch', branch_network_name))
1235
 
        client.add_expected_call(
1236
 
            'BzrDir.find_repositoryV3', ('stacked/',),
1237
 
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
 
667
        client.add_expected_call(
 
668
            'BzrDir.open_branch', ('stacked/',),
 
669
            'success', ('ok', ''))
 
670
        client.add_expected_call(
 
671
            'BzrDir.find_repositoryV2', ('stacked/',),
 
672
            'success', ('ok', '', 'no', 'no', 'no'))
1238
673
        # called twice, once from constructor and then again by us
1239
674
        client.add_expected_call(
1240
675
            'Branch.get_stacked_on_url', ('stacked/',),
1247
682
        branch = bzrdir.open_branch()
1248
683
        result = branch.get_stacked_on_url()
1249
684
        self.assertEqual('../base', result)
1250
 
        self.assertFinished(client)
1251
 
        # it's in the fallback list both for the RemoteRepository.
 
685
        client.finished_test()
 
686
        # it's in the fallback list both for the RemoteRepository and its vfs
 
687
        # repository
1252
688
        self.assertEqual(1, len(branch.repository._fallback_repositories))
1253
 
        # And we haven't had to construct a real repository.
1254
 
        self.assertEqual(None, branch.repository._real_repository)
 
689
        self.assertEqual(1,
 
690
            len(branch.repository._real_repository._fallback_repositories))
1255
691
 
1256
692
 
1257
693
class TestBranchSetLastRevision(RemoteBranchTestCase):
1288
724
        result = branch.set_revision_history([])
1289
725
        branch.unlock()
1290
726
        self.assertEqual(None, result)
1291
 
        self.assertFinished(client)
 
727
        client.finished_test()
1292
728
 
1293
729
    def test_set_nonempty(self):
1294
730
        # set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
1326
762
        result = branch.set_revision_history(['rev-id1', 'rev-id2'])
1327
763
        branch.unlock()
1328
764
        self.assertEqual(None, result)
1329
 
        self.assertFinished(client)
 
765
        client.finished_test()
1330
766
 
1331
767
    def test_no_such_revision(self):
1332
768
        transport = MemoryTransport()
1361
797
        self.assertRaises(
1362
798
            errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])
1363
799
        branch.unlock()
1364
 
        self.assertFinished(client)
 
800
        client.finished_test()
1365
801
 
1366
802
    def test_tip_change_rejected(self):
1367
803
        """TipChangeRejected responses cause a TipChangeRejected exception to
1395
831
        branch = self.make_remote_branch(transport, client)
1396
832
        branch._ensure_real = lambda: None
1397
833
        branch.lock_write()
 
834
        self.addCleanup(branch.unlock)
1398
835
        # The 'TipChangeRejected' error response triggered by calling
1399
836
        # set_revision_history causes a TipChangeRejected exception.
1400
837
        err = self.assertRaises(
1404
841
        self.assertIsInstance(err.msg, unicode)
1405
842
        self.assertEqual(rejection_msg_unicode, err.msg)
1406
843
        branch.unlock()
1407
 
        self.assertFinished(client)
 
844
        client.finished_test()
1408
845
 
1409
846
 
1410
847
class TestBranchSetLastRevisionInfo(RemoteBranchTestCase):
1464
901
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1465
902
        branch.unlock()
1466
903
 
 
904
    def lock_remote_branch(self, branch):
 
905
        """Trick a RemoteBranch into thinking it is locked."""
 
906
        branch._lock_mode = 'w'
 
907
        branch._lock_count = 2
 
908
        branch._lock_token = 'branch token'
 
909
        branch._repo_lock_token = 'repo token'
 
910
        branch.repository._lock_mode = 'w'
 
911
        branch.repository._lock_count = 2
 
912
        branch.repository._lock_token = 'repo token'
 
913
 
1467
914
    def test_backwards_compatibility(self):
1468
915
        """If the server does not support the Branch.set_last_revision_info
1469
916
        verb (which is new in 1.4), then the client falls back to VFS methods.
1510
957
        self.assertEqual(
1511
958
            [('set_last_revision_info', 1234, 'a-revision-id')],
1512
959
            real_branch.calls)
1513
 
        self.assertFinished(client)
 
960
        client.finished_test()
1514
961
 
1515
962
    def test_unexpected_error(self):
1516
963
        # If the server sends an error the client doesn't understand, it gets
1571
1018
        self.assertEqual('rejection message', err.msg)
1572
1019
 
1573
1020
 
1574
 
class TestBranchGetSetConfig(RemoteBranchTestCase):
 
1021
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
 
1022
    """Getting the branch configuration should use an abstract method not vfs.
 
1023
    """
1575
1024
 
1576
1025
    def test_get_branch_conf(self):
1577
 
        # in an empty branch we decode the response properly
1578
 
        client = FakeClient()
1579
 
        client.add_expected_call(
1580
 
            'Branch.get_stacked_on_url', ('memory:///',),
1581
 
            'error', ('NotStacked',),)
1582
 
        client.add_success_response_with_body('# config file body', 'ok')
1583
 
        transport = MemoryTransport()
1584
 
        branch = self.make_remote_branch(transport, client)
1585
 
        config = branch.get_config()
1586
 
        config.has_explicit_nickname()
1587
 
        self.assertEqual(
1588
 
            [('call', 'Branch.get_stacked_on_url', ('memory:///',)),
1589
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
1590
 
            client._calls)
1591
 
 
1592
 
    def test_get_multi_line_branch_conf(self):
1593
 
        # Make sure that multiple-line branch.conf files are supported
1594
 
        #
1595
 
        # https://bugs.edge.launchpad.net/bzr/+bug/354075
1596
 
        client = FakeClient()
1597
 
        client.add_expected_call(
1598
 
            'Branch.get_stacked_on_url', ('memory:///',),
1599
 
            'error', ('NotStacked',),)
1600
 
        client.add_success_response_with_body('a = 1\nb = 2\nc = 3\n', 'ok')
1601
 
        transport = MemoryTransport()
1602
 
        branch = self.make_remote_branch(transport, client)
1603
 
        config = branch.get_config()
1604
 
        self.assertEqual(u'2', config.get_user_option('b'))
1605
 
 
1606
 
    def test_set_option(self):
1607
 
        client = FakeClient()
1608
 
        client.add_expected_call(
1609
 
            'Branch.get_stacked_on_url', ('memory:///',),
1610
 
            'error', ('NotStacked',),)
1611
 
        client.add_expected_call(
1612
 
            'Branch.lock_write', ('memory:///', '', ''),
1613
 
            'success', ('ok', 'branch token', 'repo token'))
1614
 
        client.add_expected_call(
1615
 
            'Branch.set_config_option', ('memory:///', 'branch token',
1616
 
            'repo token', 'foo', 'bar', ''),
1617
 
            'success', ())
1618
 
        client.add_expected_call(
1619
 
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1620
 
            'success', ('ok',))
1621
 
        transport = MemoryTransport()
1622
 
        branch = self.make_remote_branch(transport, client)
1623
 
        branch.lock_write()
1624
 
        config = branch._get_config()
1625
 
        config.set_option('foo', 'bar')
1626
 
        branch.unlock()
1627
 
        self.assertFinished(client)
1628
 
 
1629
 
    def test_backwards_compat_set_option(self):
1630
 
        self.setup_smart_server_with_call_log()
1631
 
        branch = self.make_branch('.')
1632
 
        verb = 'Branch.set_config_option'
1633
 
        self.disable_verb(verb)
1634
 
        branch.lock_write()
1635
 
        self.addCleanup(branch.unlock)
1636
 
        self.reset_smart_call_log()
1637
 
        branch._get_config().set_option('value', 'name')
1638
 
        self.assertLength(10, self.hpss_calls)
1639
 
        self.assertEqual('value', branch._get_config().get_option('name'))
 
1026
        raise tests.KnownFailure('branch.conf is not retrieved by get_config_file')
 
1027
        ## # We should see that branch.get_config() does a single rpc to get the
 
1028
        ## # remote configuration file, abstracting away where that is stored on
 
1029
        ## # the server.  However at the moment it always falls back to using the
 
1030
        ## # vfs, and this would need some changes in config.py.
 
1031
 
 
1032
        ## # in an empty branch we decode the response properly
 
1033
        ## client = FakeClient([(('ok', ), '# config file body')], self.get_url())
 
1034
        ## # we need to make a real branch because the remote_branch.control_files
 
1035
        ## # will trigger _ensure_real.
 
1036
        ## branch = self.make_branch('quack')
 
1037
        ## transport = branch.bzrdir.root_transport
 
1038
        ## # we do not want bzrdir to make any remote calls
 
1039
        ## bzrdir = RemoteBzrDir(transport, _client=False)
 
1040
        ## branch = RemoteBranch(bzrdir, None, _client=client)
 
1041
        ## config = branch.get_config()
 
1042
        ## self.assertEqual(
 
1043
        ##     [('call_expecting_body', 'Branch.get_config_file', ('quack/',))],
 
1044
        ##     client._calls)
1640
1045
 
1641
1046
 
1642
1047
class TestBranchLockWrite(RemoteBranchTestCase):
1654
1059
        transport = transport.clone('quack')
1655
1060
        branch = self.make_remote_branch(transport, client)
1656
1061
        self.assertRaises(errors.UnlockableTransport, branch.lock_write)
1657
 
        self.assertFinished(client)
1658
 
 
1659
 
 
1660
 
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1661
 
 
1662
 
    def test__get_config(self):
1663
 
        client = FakeClient()
1664
 
        client.add_success_response_with_body('default_stack_on = /\n', 'ok')
1665
 
        transport = MemoryTransport()
1666
 
        bzrdir = self.make_remote_bzrdir(transport, client)
1667
 
        config = bzrdir.get_config()
1668
 
        self.assertEqual('/', config.get_default_stack_on())
1669
 
        self.assertEqual(
1670
 
            [('call_expecting_body', 'BzrDir.get_config_file', ('memory:///',))],
1671
 
            client._calls)
1672
 
 
1673
 
    def test_set_option_uses_vfs(self):
1674
 
        self.setup_smart_server_with_call_log()
1675
 
        bzrdir = self.make_bzrdir('.')
1676
 
        self.reset_smart_call_log()
1677
 
        config = bzrdir.get_config()
1678
 
        config.set_default_stack_on('/')
1679
 
        self.assertLength(3, self.hpss_calls)
1680
 
 
1681
 
    def test_backwards_compat_get_option(self):
1682
 
        self.setup_smart_server_with_call_log()
1683
 
        bzrdir = self.make_bzrdir('.')
1684
 
        verb = 'BzrDir.get_config_file'
1685
 
        self.disable_verb(verb)
1686
 
        self.reset_smart_call_log()
1687
 
        self.assertEqual(None,
1688
 
            bzrdir._get_config().get_option('default_stack_on'))
1689
 
        self.assertLength(3, self.hpss_calls)
 
1062
        client.finished_test()
1690
1063
 
1691
1064
 
1692
1065
class TestTransportIsReadonly(tests.TestCase):
1785
1158
        return repo, client
1786
1159
 
1787
1160
 
1788
 
def remoted_description(format):
1789
 
    return 'Remote: ' + format.get_format_description()
1790
 
 
1791
 
 
1792
 
class TestBranchFormat(tests.TestCase):
1793
 
 
1794
 
    def test_get_format_description(self):
1795
 
        remote_format = RemoteBranchFormat()
1796
 
        real_format = branch.BranchFormat.get_default_format()
1797
 
        remote_format._network_name = real_format.network_name()
1798
 
        self.assertEqual(remoted_description(real_format),
1799
 
            remote_format.get_format_description())
1800
 
 
1801
 
 
1802
 
class TestRepositoryFormat(TestRemoteRepository):
1803
 
 
1804
 
    def test_fast_delta(self):
1805
 
        true_name = groupcompress_repo.RepositoryFormatCHK1().network_name()
1806
 
        true_format = RemoteRepositoryFormat()
1807
 
        true_format._network_name = true_name
1808
 
        self.assertEqual(True, true_format.fast_deltas)
1809
 
        false_name = pack_repo.RepositoryFormatKnitPack1().network_name()
1810
 
        false_format = RemoteRepositoryFormat()
1811
 
        false_format._network_name = false_name
1812
 
        self.assertEqual(False, false_format.fast_deltas)
1813
 
 
1814
 
    def test_get_format_description(self):
1815
 
        remote_repo_format = RemoteRepositoryFormat()
1816
 
        real_format = repository.RepositoryFormat.get_default_format()
1817
 
        remote_repo_format._network_name = real_format.network_name()
1818
 
        self.assertEqual(remoted_description(real_format),
1819
 
            remote_repo_format.get_format_description())
1820
 
 
1821
 
 
1822
1161
class TestRepositoryGatherStats(TestRemoteRepository):
1823
1162
 
1824
1163
    def test_revid_none(self):
1912
1251
        self.assertEqual({r1: (NULL_REVISION,)}, parents)
1913
1252
        self.assertEqual(
1914
1253
            [('call_with_body_bytes_expecting_body',
1915
 
              'Repository.get_parent_map', ('quack/', 'include-missing:', r2),
1916
 
              '\n\n0')],
 
1254
              'Repository.get_parent_map', ('quack/', r2), '\n\n0')],
1917
1255
            client._calls)
1918
1256
        repo.unlock()
1919
1257
        # now we call again, and it should use the second response.
1923
1261
        self.assertEqual({r1: (NULL_REVISION,)}, parents)
1924
1262
        self.assertEqual(
1925
1263
            [('call_with_body_bytes_expecting_body',
1926
 
              'Repository.get_parent_map', ('quack/', 'include-missing:', r2),
1927
 
              '\n\n0'),
 
1264
              'Repository.get_parent_map', ('quack/', r2), '\n\n0'),
1928
1265
             ('call_with_body_bytes_expecting_body',
1929
 
              'Repository.get_parent_map', ('quack/', 'include-missing:', r1),
1930
 
              '\n\n0'),
 
1266
              'Repository.get_parent_map', ('quack/', r1), '\n\n0'),
1931
1267
            ],
1932
1268
            client._calls)
1933
1269
        repo.unlock()
1934
1270
 
1935
1271
    def test_get_parent_map_reconnects_if_unknown_method(self):
1936
1272
        transport_path = 'quack'
1937
 
        rev_id = 'revision-id'
1938
1273
        repo, client = self.setup_fake_client_and_repository(transport_path)
1939
 
        client.add_unknown_method_response('Repository.get_parent_map')
1940
 
        client.add_success_response_with_body(rev_id, 'ok')
 
1274
        client.add_unknown_method_response('Repository,get_parent_map')
 
1275
        client.add_success_response_with_body('', 'ok')
1941
1276
        self.assertFalse(client._medium._is_remote_before((1, 2)))
1942
 
        parents = repo.get_parent_map([rev_id])
 
1277
        rev_id = 'revision-id'
 
1278
        expected_deprecations = [
 
1279
            'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
 
1280
            'in version 1.4.']
 
1281
        parents = self.callDeprecated(
 
1282
            expected_deprecations, repo.get_parent_map, [rev_id])
1943
1283
        self.assertEqual(
1944
1284
            [('call_with_body_bytes_expecting_body',
1945
 
              'Repository.get_parent_map', ('quack/', 'include-missing:',
1946
 
              rev_id), '\n\n0'),
 
1285
              'Repository.get_parent_map', ('quack/', rev_id), '\n\n0'),
1947
1286
             ('disconnect medium',),
1948
1287
             ('call_expecting_body', 'Repository.get_revision_graph',
1949
1288
              ('quack/', ''))],
1950
1289
            client._calls)
1951
1290
        # The medium is now marked as being connected to an older server
1952
1291
        self.assertTrue(client._medium._is_remote_before((1, 2)))
1953
 
        self.assertEqual({rev_id: ('null:',)}, parents)
1954
1292
 
1955
1293
    def test_get_parent_map_fallback_parentless_node(self):
1956
1294
        """get_parent_map falls back to get_revision_graph on old servers.  The
1968
1306
        repo, client = self.setup_fake_client_and_repository(transport_path)
1969
1307
        client.add_success_response_with_body(rev_id, 'ok')
1970
1308
        client._medium._remember_remote_is_before((1, 2))
1971
 
        parents = repo.get_parent_map([rev_id])
 
1309
        expected_deprecations = [
 
1310
            'bzrlib.remote.RemoteRepository.get_revision_graph was deprecated '
 
1311
            'in version 1.4.']
 
1312
        parents = self.callDeprecated(
 
1313
            expected_deprecations, repo.get_parent_map, [rev_id])
1972
1314
        self.assertEqual(
1973
1315
            [('call_expecting_body', 'Repository.get_revision_graph',
1974
1316
             ('quack/', ''))],
1982
1324
            errors.UnexpectedSmartServerResponse,
1983
1325
            repo.get_parent_map, ['a-revision-id'])
1984
1326
 
1985
 
    def test_get_parent_map_negative_caches_missing_keys(self):
1986
 
        self.setup_smart_server_with_call_log()
1987
 
        repo = self.make_repository('foo')
1988
 
        self.assertIsInstance(repo, RemoteRepository)
1989
 
        repo.lock_read()
1990
 
        self.addCleanup(repo.unlock)
1991
 
        self.reset_smart_call_log()
1992
 
        graph = repo.get_graph()
1993
 
        self.assertEqual({},
1994
 
            graph.get_parent_map(['some-missing', 'other-missing']))
1995
 
        self.assertLength(1, self.hpss_calls)
1996
 
        # No call if we repeat this
1997
 
        self.reset_smart_call_log()
1998
 
        graph = repo.get_graph()
1999
 
        self.assertEqual({},
2000
 
            graph.get_parent_map(['some-missing', 'other-missing']))
2001
 
        self.assertLength(0, self.hpss_calls)
2002
 
        # Asking for more unknown keys makes a request.
2003
 
        self.reset_smart_call_log()
2004
 
        graph = repo.get_graph()
2005
 
        self.assertEqual({},
2006
 
            graph.get_parent_map(['some-missing', 'other-missing',
2007
 
                'more-missing']))
2008
 
        self.assertLength(1, self.hpss_calls)
2009
 
 
2010
 
    def disableExtraResults(self):
2011
 
        self.overrideAttr(SmartServerRepositoryGetParentMap,
2012
 
                          'no_extra_results', True)
2013
 
 
2014
 
    def test_null_cached_missing_and_stop_key(self):
2015
 
        self.setup_smart_server_with_call_log()
2016
 
        # Make a branch with a single revision.
2017
 
        builder = self.make_branch_builder('foo')
2018
 
        builder.start_series()
2019
 
        builder.build_snapshot('first', None, [
2020
 
            ('add', ('', 'root-id', 'directory', ''))])
2021
 
        builder.finish_series()
2022
 
        branch = builder.get_branch()
2023
 
        repo = branch.repository
2024
 
        self.assertIsInstance(repo, RemoteRepository)
2025
 
        # Stop the server from sending extra results.
2026
 
        self.disableExtraResults()
2027
 
        repo.lock_read()
2028
 
        self.addCleanup(repo.unlock)
2029
 
        self.reset_smart_call_log()
2030
 
        graph = repo.get_graph()
2031
 
        # Query for 'first' and 'null:'.  Because 'null:' is a parent of
2032
 
        # 'first' it will be a candidate for the stop_keys of subsequent
2033
 
        # requests, and because 'null:' was queried but not returned it will be
2034
 
        # cached as missing.
2035
 
        self.assertEqual({'first': ('null:',)},
2036
 
            graph.get_parent_map(['first', 'null:']))
2037
 
        # Now query for another key.  This request will pass along a recipe of
2038
 
        # start and stop keys describing the already cached results, and this
2039
 
        # recipe's revision count must be correct (or else it will trigger an
2040
 
        # error from the server).
2041
 
        self.assertEqual({}, graph.get_parent_map(['another-key']))
2042
 
        # This assertion guards against disableExtraResults silently failing to
2043
 
        # work, thus invalidating the test.
2044
 
        self.assertLength(2, self.hpss_calls)
2045
 
 
2046
 
    def test_get_parent_map_gets_ghosts_from_result(self):
2047
 
        # asking for a revision should negatively cache close ghosts in its
2048
 
        # ancestry.
2049
 
        self.setup_smart_server_with_call_log()
2050
 
        tree = self.make_branch_and_memory_tree('foo')
2051
 
        tree.lock_write()
2052
 
        try:
2053
 
            builder = treebuilder.TreeBuilder()
2054
 
            builder.start_tree(tree)
2055
 
            builder.build([])
2056
 
            builder.finish_tree()
2057
 
            tree.set_parent_ids(['non-existant'], allow_leftmost_as_ghost=True)
2058
 
            rev_id = tree.commit('')
2059
 
        finally:
2060
 
            tree.unlock()
2061
 
        tree.lock_read()
2062
 
        self.addCleanup(tree.unlock)
2063
 
        repo = tree.branch.repository
2064
 
        self.assertIsInstance(repo, RemoteRepository)
2065
 
        # ask for rev_id
2066
 
        repo.get_parent_map([rev_id])
2067
 
        self.reset_smart_call_log()
2068
 
        # Now asking for rev_id's ghost parent should not make calls
2069
 
        self.assertEqual({}, repo.get_parent_map(['non-existant']))
2070
 
        self.assertLength(0, self.hpss_calls)
2071
 
 
2072
1327
 
2073
1328
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
2074
1329
 
2075
1330
    def test_allows_new_revisions(self):
2076
1331
        """get_parent_map's results can be updated by commit."""
2077
1332
        smart_server = server.SmartTCPServer_for_testing()
2078
 
        self.start_server(smart_server)
 
1333
        smart_server.setUp()
 
1334
        self.addCleanup(smart_server.tearDown)
2079
1335
        self.make_branch('branch')
2080
1336
        branch = Branch.open(smart_server.get_url() + '/branch')
2081
1337
        tree = branch.create_checkout('tree', lightweight=True)
2097
1353
        transport_path = 'empty'
2098
1354
        repo, client = self.setup_fake_client_and_repository(transport_path)
2099
1355
        client.add_success_response('notused')
2100
 
        # actual RemoteRepository.get_revision_graph is gone, but there's an
2101
 
        # equivalent private method for testing
2102
 
        result = repo._get_revision_graph(NULL_REVISION)
 
1356
        result = self.applyDeprecated(one_four, repo.get_revision_graph,
 
1357
            NULL_REVISION)
2103
1358
        self.assertEqual([], client._calls)
2104
1359
        self.assertEqual({}, result)
2105
1360
 
2113
1368
        transport_path = 'sinhala'
2114
1369
        repo, client = self.setup_fake_client_and_repository(transport_path)
2115
1370
        client.add_success_response_with_body(encoded_body, 'ok')
2116
 
        # actual RemoteRepository.get_revision_graph is gone, but there's an
2117
 
        # equivalent private method for testing
2118
 
        result = repo._get_revision_graph(None)
 
1371
        result = self.applyDeprecated(one_four, repo.get_revision_graph)
2119
1372
        self.assertEqual(
2120
1373
            [('call_expecting_body', 'Repository.get_revision_graph',
2121
1374
             ('sinhala/', ''))],
2134
1387
        transport_path = 'sinhala'
2135
1388
        repo, client = self.setup_fake_client_and_repository(transport_path)
2136
1389
        client.add_success_response_with_body(encoded_body, 'ok')
2137
 
        result = repo._get_revision_graph(r2)
 
1390
        result = self.applyDeprecated(one_four, repo.get_revision_graph, r2)
2138
1391
        self.assertEqual(
2139
1392
            [('call_expecting_body', 'Repository.get_revision_graph',
2140
1393
             ('sinhala/', r2))],
2148
1401
        client.add_error_response('nosuchrevision', revid)
2149
1402
        # also check that the right revision is reported in the error
2150
1403
        self.assertRaises(errors.NoSuchRevision,
2151
 
            repo._get_revision_graph, revid)
 
1404
            self.applyDeprecated, one_four, repo.get_revision_graph, revid)
2152
1405
        self.assertEqual(
2153
1406
            [('call_expecting_body', 'Repository.get_revision_graph',
2154
1407
             ('sinhala/', revid))],
2160
1413
        repo, client = self.setup_fake_client_and_repository(transport_path)
2161
1414
        client.add_error_response('AnUnexpectedError')
2162
1415
        e = self.assertRaises(errors.UnknownErrorFromSmartServer,
2163
 
            repo._get_revision_graph, revid)
 
1416
            self.applyDeprecated, one_four, repo.get_revision_graph, revid)
2164
1417
        self.assertEqual(('AnUnexpectedError',), e.error_tuple)
2165
1418
 
2166
1419
 
2167
 
class TestRepositoryGetRevIdForRevno(TestRemoteRepository):
2168
 
 
2169
 
    def test_ok(self):
2170
 
        repo, client = self.setup_fake_client_and_repository('quack')
2171
 
        client.add_expected_call(
2172
 
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2173
 
            'success', ('ok', 'rev-five'))
2174
 
        result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2175
 
        self.assertEqual((True, 'rev-five'), result)
2176
 
        self.assertFinished(client)
2177
 
 
2178
 
    def test_history_incomplete(self):
2179
 
        repo, client = self.setup_fake_client_and_repository('quack')
2180
 
        client.add_expected_call(
2181
 
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2182
 
            'success', ('history-incomplete', 10, 'rev-ten'))
2183
 
        result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2184
 
        self.assertEqual((False, (10, 'rev-ten')), result)
2185
 
        self.assertFinished(client)
2186
 
 
2187
 
    def test_history_incomplete_with_fallback(self):
2188
 
        """A 'history-incomplete' response causes the fallback repository to be
2189
 
        queried too, if one is set.
2190
 
        """
2191
 
        # Make a repo with a fallback repo, both using a FakeClient.
2192
 
        format = remote.response_tuple_to_repo_format(
2193
 
            ('yes', 'no', 'yes', 'fake-network-name'))
2194
 
        repo, client = self.setup_fake_client_and_repository('quack')
2195
 
        repo._format = format
2196
 
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2197
 
            'fallback')
2198
 
        fallback_repo._client = client
2199
 
        repo.add_fallback_repository(fallback_repo)
2200
 
        # First the client should ask the primary repo
2201
 
        client.add_expected_call(
2202
 
            'Repository.get_rev_id_for_revno', ('quack/', 1, (42, 'rev-foo')),
2203
 
            'success', ('history-incomplete', 2, 'rev-two'))
2204
 
        # Then it should ask the fallback, using revno/revid from the
2205
 
        # history-incomplete response as the known revno/revid.
2206
 
        client.add_expected_call(
2207
 
            'Repository.get_rev_id_for_revno',('fallback/', 1, (2, 'rev-two')),
2208
 
            'success', ('ok', 'rev-one'))
2209
 
        result = repo.get_rev_id_for_revno(1, (42, 'rev-foo'))
2210
 
        self.assertEqual((True, 'rev-one'), result)
2211
 
        self.assertFinished(client)
2212
 
 
2213
 
    def test_nosuchrevision(self):
2214
 
        # 'nosuchrevision' is returned when the known-revid is not found in the
2215
 
        # remote repo.  The client translates that response to NoSuchRevision.
2216
 
        repo, client = self.setup_fake_client_and_repository('quack')
2217
 
        client.add_expected_call(
2218
 
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2219
 
            'error', ('nosuchrevision', 'rev-foo'))
2220
 
        self.assertRaises(
2221
 
            errors.NoSuchRevision,
2222
 
            repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2223
 
        self.assertFinished(client)
2224
 
 
2225
 
    def test_branch_fallback_locking(self):
2226
 
        """RemoteBranch.get_rev_id takes a read lock, and tries to call the
2227
 
        get_rev_id_for_revno verb.  If the verb is unknown the VFS fallback
2228
 
        will be invoked, which will fail if the repo is unlocked.
2229
 
        """
2230
 
        self.setup_smart_server_with_call_log()
2231
 
        tree = self.make_branch_and_memory_tree('.')
2232
 
        tree.lock_write()
2233
 
        rev1 = tree.commit('First')
2234
 
        rev2 = tree.commit('Second')
2235
 
        tree.unlock()
2236
 
        branch = tree.branch
2237
 
        self.assertFalse(branch.is_locked())
2238
 
        self.reset_smart_call_log()
2239
 
        verb = 'Repository.get_rev_id_for_revno'
2240
 
        self.disable_verb(verb)
2241
 
        self.assertEqual(rev1, branch.get_rev_id(1))
2242
 
        self.assertLength(1, [call for call in self.hpss_calls if
2243
 
                              call.call.method == verb])
2244
 
 
2245
 
 
2246
1420
class TestRepositoryIsShared(TestRemoteRepository):
2247
1421
 
2248
1422
    def test_is_shared(self):
2309
1483
        self.disable_verb(verb)
2310
1484
        repo.set_make_working_trees(True)
2311
1485
        call_count = len([call for call in self.hpss_calls if
2312
 
            call.call.method == verb])
 
1486
            call[0].method == verb])
2313
1487
        self.assertEqual(1, call_count)
2314
1488
 
2315
1489
    def test_current(self):
2363
1537
        self.assertEqual([], client._calls)
2364
1538
 
2365
1539
 
2366
 
class TestRepositoryInsertStreamBase(TestRemoteRepository):
2367
 
    """Base class for Repository.insert_stream and .insert_stream_1.19
2368
 
    tests.
2369
 
    """
2370
 
    
2371
 
    def checkInsertEmptyStream(self, repo, client):
2372
 
        """Insert an empty stream, checking the result.
2373
 
 
2374
 
        This checks that there are no resume_tokens or missing_keys, and that
2375
 
        the client is finished.
2376
 
        """
2377
 
        sink = repo._get_sink()
2378
 
        fmt = repository.RepositoryFormat.get_default_format()
2379
 
        resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
2380
 
        self.assertEqual([], resume_tokens)
2381
 
        self.assertEqual(set(), missing_keys)
2382
 
        self.assertFinished(client)
2383
 
 
2384
 
 
2385
 
class TestRepositoryInsertStream(TestRepositoryInsertStreamBase):
2386
 
    """Tests for using Repository.insert_stream verb when the _1.19 variant is
2387
 
    not available.
2388
 
 
2389
 
    This test case is very similar to TestRepositoryInsertStream_1_19.
2390
 
    """
2391
 
 
2392
 
    def setUp(self):
2393
 
        TestRemoteRepository.setUp(self)
2394
 
        self.disable_verb('Repository.insert_stream_1.19')
2395
 
 
2396
 
    def test_unlocked_repo(self):
2397
 
        transport_path = 'quack'
2398
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2399
 
        client.add_expected_call(
2400
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2401
 
            'unknown', ('Repository.insert_stream_1.19',))
2402
 
        client.add_expected_call(
2403
 
            'Repository.insert_stream', ('quack/', ''),
2404
 
            'success', ('ok',))
2405
 
        client.add_expected_call(
2406
 
            'Repository.insert_stream', ('quack/', ''),
2407
 
            'success', ('ok',))
2408
 
        self.checkInsertEmptyStream(repo, client)
2409
 
 
2410
 
    def test_locked_repo_with_no_lock_token(self):
2411
 
        transport_path = 'quack'
2412
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2413
 
        client.add_expected_call(
2414
 
            'Repository.lock_write', ('quack/', ''),
2415
 
            'success', ('ok', ''))
2416
 
        client.add_expected_call(
2417
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2418
 
            'unknown', ('Repository.insert_stream_1.19',))
2419
 
        client.add_expected_call(
2420
 
            'Repository.insert_stream', ('quack/', ''),
2421
 
            'success', ('ok',))
2422
 
        client.add_expected_call(
2423
 
            'Repository.insert_stream', ('quack/', ''),
2424
 
            'success', ('ok',))
2425
 
        repo.lock_write()
2426
 
        self.checkInsertEmptyStream(repo, client)
2427
 
 
2428
 
    def test_locked_repo_with_lock_token(self):
2429
 
        transport_path = 'quack'
2430
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2431
 
        client.add_expected_call(
2432
 
            'Repository.lock_write', ('quack/', ''),
2433
 
            'success', ('ok', 'a token'))
2434
 
        client.add_expected_call(
2435
 
            'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2436
 
            'unknown', ('Repository.insert_stream_1.19',))
2437
 
        client.add_expected_call(
2438
 
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
2439
 
            'success', ('ok',))
2440
 
        client.add_expected_call(
2441
 
            'Repository.insert_stream_locked', ('quack/', '', 'a token'),
2442
 
            'success', ('ok',))
2443
 
        repo.lock_write()
2444
 
        self.checkInsertEmptyStream(repo, client)
2445
 
 
2446
 
    def test_stream_with_inventory_deltas(self):
2447
 
        """'inventory-deltas' substreams cannot be sent to the
2448
 
        Repository.insert_stream verb, because not all servers that implement
2449
 
        that verb will accept them.  So when one is encountered the RemoteSink
2450
 
        immediately stops using that verb and falls back to VFS insert_stream.
2451
 
        """
2452
 
        transport_path = 'quack'
2453
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2454
 
        client.add_expected_call(
2455
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2456
 
            'unknown', ('Repository.insert_stream_1.19',))
2457
 
        client.add_expected_call(
2458
 
            'Repository.insert_stream', ('quack/', ''),
2459
 
            'success', ('ok',))
2460
 
        client.add_expected_call(
2461
 
            'Repository.insert_stream', ('quack/', ''),
2462
 
            'success', ('ok',))
2463
 
        # Create a fake real repository for insert_stream to fall back on, so
2464
 
        # that we can directly see the records the RemoteSink passes to the
2465
 
        # real sink.
2466
 
        class FakeRealSink:
2467
 
            def __init__(self):
2468
 
                self.records = []
2469
 
            def insert_stream(self, stream, src_format, resume_tokens):
2470
 
                for substream_kind, substream in stream:
2471
 
                    self.records.append(
2472
 
                        (substream_kind, [record.key for record in substream]))
2473
 
                return ['fake tokens'], ['fake missing keys']
2474
 
        fake_real_sink = FakeRealSink()
2475
 
        class FakeRealRepository:
2476
 
            def _get_sink(self):
2477
 
                return fake_real_sink
2478
 
            def is_in_write_group(self):
2479
 
                return False
2480
 
            def refresh_data(self):
2481
 
                return True
2482
 
        repo._real_repository = FakeRealRepository()
2483
 
        sink = repo._get_sink()
2484
 
        fmt = repository.RepositoryFormat.get_default_format()
2485
 
        stream = self.make_stream_with_inv_deltas(fmt)
2486
 
        resume_tokens, missing_keys = sink.insert_stream(stream, fmt, [])
2487
 
        # Every record from the first inventory delta should have been sent to
2488
 
        # the VFS sink.
2489
 
        expected_records = [
2490
 
            ('inventory-deltas', [('rev2',), ('rev3',)]),
2491
 
            ('texts', [('some-rev', 'some-file')])]
2492
 
        self.assertEqual(expected_records, fake_real_sink.records)
2493
 
        # The return values from the real sink's insert_stream are propagated
2494
 
        # back to the original caller.
2495
 
        self.assertEqual(['fake tokens'], resume_tokens)
2496
 
        self.assertEqual(['fake missing keys'], missing_keys)
2497
 
        self.assertFinished(client)
2498
 
 
2499
 
    def make_stream_with_inv_deltas(self, fmt):
2500
 
        """Make a simple stream with an inventory delta followed by more
2501
 
        records and more substreams to test that all records and substreams
2502
 
        from that point on are used.
2503
 
 
2504
 
        This sends, in order:
2505
 
           * inventories substream: rev1, rev2, rev3.  rev2 and rev3 are
2506
 
             inventory-deltas.
2507
 
           * texts substream: (some-rev, some-file)
2508
 
        """
2509
 
        # Define a stream using generators so that it isn't rewindable.
2510
 
        inv = inventory.Inventory(revision_id='rev1')
2511
 
        inv.root.revision = 'rev1'
2512
 
        def stream_with_inv_delta():
2513
 
            yield ('inventories', inventories_substream())
2514
 
            yield ('inventory-deltas', inventory_delta_substream())
2515
 
            yield ('texts', [
2516
 
                versionedfile.FulltextContentFactory(
2517
 
                    ('some-rev', 'some-file'), (), None, 'content')])
2518
 
        def inventories_substream():
2519
 
            # An empty inventory fulltext.  This will be streamed normally.
2520
 
            text = fmt._serializer.write_inventory_to_string(inv)
2521
 
            yield versionedfile.FulltextContentFactory(
2522
 
                ('rev1',), (), None, text)
2523
 
        def inventory_delta_substream():
2524
 
            # An inventory delta.  This can't be streamed via this verb, so it
2525
 
            # will trigger a fallback to VFS insert_stream.
2526
 
            entry = inv.make_entry(
2527
 
                'directory', 'newdir', inv.root.file_id, 'newdir-id')
2528
 
            entry.revision = 'ghost'
2529
 
            delta = [(None, 'newdir', 'newdir-id', entry)]
2530
 
            serializer = inventory_delta.InventoryDeltaSerializer(
2531
 
                versioned_root=True, tree_references=False)
2532
 
            lines = serializer.delta_to_lines('rev1', 'rev2', delta)
2533
 
            yield versionedfile.ChunkedContentFactory(
2534
 
                ('rev2',), (('rev1',)), None, lines)
2535
 
            # Another delta.
2536
 
            lines = serializer.delta_to_lines('rev1', 'rev3', delta)
2537
 
            yield versionedfile.ChunkedContentFactory(
2538
 
                ('rev3',), (('rev1',)), None, lines)
2539
 
        return stream_with_inv_delta()
2540
 
 
2541
 
 
2542
 
class TestRepositoryInsertStream_1_19(TestRepositoryInsertStreamBase):
2543
 
 
2544
 
    def test_unlocked_repo(self):
2545
 
        transport_path = 'quack'
2546
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2547
 
        client.add_expected_call(
2548
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2549
 
            'success', ('ok',))
2550
 
        client.add_expected_call(
2551
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2552
 
            'success', ('ok',))
2553
 
        self.checkInsertEmptyStream(repo, client)
2554
 
 
2555
 
    def test_locked_repo_with_no_lock_token(self):
2556
 
        transport_path = 'quack'
2557
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2558
 
        client.add_expected_call(
2559
 
            'Repository.lock_write', ('quack/', ''),
2560
 
            'success', ('ok', ''))
2561
 
        client.add_expected_call(
2562
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2563
 
            'success', ('ok',))
2564
 
        client.add_expected_call(
2565
 
            'Repository.insert_stream_1.19', ('quack/', ''),
2566
 
            'success', ('ok',))
2567
 
        repo.lock_write()
2568
 
        self.checkInsertEmptyStream(repo, client)
2569
 
 
2570
 
    def test_locked_repo_with_lock_token(self):
2571
 
        transport_path = 'quack'
2572
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2573
 
        client.add_expected_call(
2574
 
            'Repository.lock_write', ('quack/', ''),
2575
 
            'success', ('ok', 'a token'))
2576
 
        client.add_expected_call(
2577
 
            'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2578
 
            'success', ('ok',))
2579
 
        client.add_expected_call(
2580
 
            'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2581
 
            'success', ('ok',))
2582
 
        repo.lock_write()
2583
 
        self.checkInsertEmptyStream(repo, client)
2584
 
 
2585
 
 
2586
1540
class TestRepositoryTarball(TestRemoteRepository):
2587
1541
 
2588
1542
    # This is a canned tarball reponse we can validate against
2640
1594
class _StubRealPackRepository(object):
2641
1595
 
2642
1596
    def __init__(self, calls):
2643
 
        self.calls = calls
2644
1597
        self._pack_collection = _StubPackCollection(calls)
2645
1598
 
2646
 
    def is_in_write_group(self):
2647
 
        return False
2648
 
 
2649
 
    def refresh_data(self):
2650
 
        self.calls.append(('pack collection reload_pack_names',))
2651
 
 
2652
1599
 
2653
1600
class _StubPackCollection(object):
2654
1601
 
2658
1605
    def autopack(self):
2659
1606
        self.calls.append(('pack collection autopack',))
2660
1607
 
 
1608
    def reload_pack_names(self):
 
1609
        self.calls.append(('pack collection reload_pack_names',))
 
1610
 
2661
1611
 
2662
1612
class TestRemotePackRepositoryAutoPack(TestRemoteRepository):
2663
1613
    """Tests for RemoteRepository.autopack implementation."""
2671
1621
        client.add_expected_call(
2672
1622
            'PackRepository.autopack', ('quack/',), 'success', ('ok',))
2673
1623
        repo.autopack()
2674
 
        self.assertFinished(client)
 
1624
        client.finished_test()
2675
1625
 
2676
1626
    def test_ok_with_real_repo(self):
2677
1627
        """When the server returns 'ok' and there is a _real_repository, then
2776
1726
        expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
2777
1727
        self.assertEqual(expected_error, translated_error)
2778
1728
 
2779
 
    def test_nobranch_one_arg(self):
2780
 
        bzrdir = self.make_bzrdir('')
2781
 
        translated_error = self.translateTuple(
2782
 
            ('nobranch', 'extra detail'), bzrdir=bzrdir)
2783
 
        expected_error = errors.NotBranchError(
2784
 
            path=bzrdir.root_transport.base,
2785
 
            detail='extra detail')
2786
 
        self.assertEqual(expected_error, translated_error)
2787
 
 
2788
1729
    def test_LockContention(self):
2789
1730
        translated_error = self.translateTuple(('LockContention',))
2790
1731
        expected_error = errors.LockContention('(remote lock)')
2830
1771
        expected_error = errors.ReadError(path)
2831
1772
        self.assertEqual(expected_error, translated_error)
2832
1773
 
2833
 
    def test_IncompatibleRepositories(self):
2834
 
        translated_error = self.translateTuple(('IncompatibleRepositories',
2835
 
            "repo1", "repo2", "details here"))
2836
 
        expected_error = errors.IncompatibleRepositories("repo1", "repo2",
2837
 
            "details here")
2838
 
        self.assertEqual(expected_error, translated_error)
2839
 
 
2840
1774
    def test_PermissionDenied_no_args(self):
2841
1775
        path = 'a path'
2842
1776
        translated_error = self.translateTuple(('PermissionDenied',), path=path)
2903
1837
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2904
1838
        # been muttered to the log file for developer to look at.
2905
1839
        self.assertContainsRe(
2906
 
            self.get_log(),
 
1840
            self._get_log(keep_log_file=True),
2907
1841
            "Missing key 'branch' in context")
2908
1842
 
2909
1843
    def test_path_missing(self):
2917
1851
        self.assertEqual(server_error, translated_error)
2918
1852
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2919
1853
        # been muttered to the log file for developer to look at.
2920
 
        self.assertContainsRe(self.get_log(), "Missing key 'path' in context")
 
1854
        self.assertContainsRe(
 
1855
            self._get_log(keep_log_file=True), "Missing key 'path' in context")
2921
1856
 
2922
1857
 
2923
1858
class TestStacking(tests.TestCaseWithTransport):
2932
1867
        # revision, then open it over hpss - we should be able to see that
2933
1868
        # revision.
2934
1869
        base_transport = self.get_transport()
2935
 
        base_builder = self.make_branch_builder('base', format='1.9')
 
1870
        base_builder = self.make_branch_builder('base', format='1.6')
2936
1871
        base_builder.start_series()
2937
1872
        base_revid = base_builder.build_snapshot('rev-id', None,
2938
1873
            [('add', ('', None, 'directory', None))],
2939
1874
            'message')
2940
1875
        base_builder.finish_series()
2941
 
        stacked_branch = self.make_branch('stacked', format='1.9')
 
1876
        stacked_branch = self.make_branch('stacked', format='1.6')
2942
1877
        stacked_branch.set_stacked_on_url('../base')
2943
1878
        # start a server looking at this
2944
1879
        smart_server = server.SmartTCPServer_for_testing()
2945
 
        self.start_server(smart_server)
 
1880
        smart_server.setUp()
 
1881
        self.addCleanup(smart_server.tearDown)
2946
1882
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2947
1883
        # can get its branch and repository
2948
1884
        remote_branch = remote_bzrdir.open_branch()
2951
1887
        try:
2952
1888
            # it should have an appropriate fallback repository, which should also
2953
1889
            # be a RemoteRepository
2954
 
            self.assertLength(1, remote_repo._fallback_repositories)
 
1890
            self.assertEquals(len(remote_repo._fallback_repositories), 1)
2955
1891
            self.assertIsInstance(remote_repo._fallback_repositories[0],
2956
1892
                RemoteRepository)
2957
1893
            # and it has the revision committed to the underlying repository;
2964
1900
            remote_repo.unlock()
2965
1901
 
2966
1902
    def prepare_stacked_remote_branch(self):
2967
 
        """Get stacked_upon and stacked branches with content in each."""
2968
 
        self.setup_smart_server_with_call_log()
2969
 
        tree1 = self.make_branch_and_tree('tree1', format='1.9')
 
1903
        smart_server = server.SmartTCPServer_for_testing()
 
1904
        smart_server.setUp()
 
1905
        self.addCleanup(smart_server.tearDown)
 
1906
        tree1 = self.make_branch_and_tree('tree1')
2970
1907
        tree1.commit('rev1', rev_id='rev1')
2971
 
        tree2 = tree1.branch.bzrdir.sprout('tree2', stacked=True
2972
 
            ).open_workingtree()
2973
 
        local_tree = tree2.branch.create_checkout('local')
2974
 
        local_tree.commit('local changes make me feel good.')
2975
 
        branch2 = Branch.open(self.get_url('tree2'))
 
1908
        tree2 = self.make_branch_and_tree('tree2', format='1.6')
 
1909
        tree2.branch.set_stacked_on_url(tree1.branch.base)
 
1910
        branch2 = Branch.open(smart_server.get_url() + '/tree2')
2976
1911
        branch2.lock_read()
2977
1912
        self.addCleanup(branch2.unlock)
2978
 
        return tree1.branch, branch2
 
1913
        return branch2
2979
1914
 
2980
1915
    def test_stacked_get_parent_map(self):
2981
1916
        # the public implementation of get_parent_map obeys stacking
2982
 
        _, branch = self.prepare_stacked_remote_branch()
 
1917
        branch = self.prepare_stacked_remote_branch()
2983
1918
        repo = branch.repository
2984
1919
        self.assertEqual(['rev1'], repo.get_parent_map(['rev1']).keys())
2985
1920
 
2986
1921
    def test_unstacked_get_parent_map(self):
2987
1922
        # _unstacked_provider.get_parent_map ignores stacking
2988
 
        _, branch = self.prepare_stacked_remote_branch()
 
1923
        branch = self.prepare_stacked_remote_branch()
2989
1924
        provider = branch.repository._unstacked_provider
2990
1925
        self.assertEqual([], provider.get_parent_map(['rev1']).keys())
2991
1926
 
2992
 
    def fetch_stream_to_rev_order(self, stream):
2993
 
        result = []
2994
 
        for kind, substream in stream:
2995
 
            if not kind == 'revisions':
2996
 
                list(substream)
2997
 
            else:
2998
 
                for content in substream:
2999
 
                    result.append(content.key[-1])
3000
 
        return result
3001
 
 
3002
 
    def get_ordered_revs(self, format, order, branch_factory=None):
3003
 
        """Get a list of the revisions in a stream to format format.
3004
 
 
3005
 
        :param format: The format of the target.
3006
 
        :param order: the order that target should have requested.
3007
 
        :param branch_factory: A callable to create a trunk and stacked branch
3008
 
            to fetch from. If none, self.prepare_stacked_remote_branch is used.
3009
 
        :result: The revision ids in the stream, in the order seen,
3010
 
            the topological order of revisions in the source.
3011
 
        """
3012
 
        unordered_format = bzrdir.format_registry.get(format)()
3013
 
        target_repository_format = unordered_format.repository_format
3014
 
        # Cross check
3015
 
        self.assertEqual(order, target_repository_format._fetch_order)
3016
 
        if branch_factory is None:
3017
 
            branch_factory = self.prepare_stacked_remote_branch
3018
 
        _, stacked = branch_factory()
3019
 
        source = stacked.repository._get_source(target_repository_format)
3020
 
        tip = stacked.last_revision()
3021
 
        revs = stacked.repository.get_ancestry(tip)
3022
 
        search = graph.PendingAncestryResult([tip], stacked.repository)
3023
 
        self.reset_smart_call_log()
3024
 
        stream = source.get_stream(search)
3025
 
        if None in revs:
3026
 
            revs.remove(None)
3027
 
        # We trust that if a revision is in the stream the rest of the new
3028
 
        # content for it is too, as per our main fetch tests; here we are
3029
 
        # checking that the revisions are actually included at all, and their
3030
 
        # order.
3031
 
        return self.fetch_stream_to_rev_order(stream), revs
3032
 
 
3033
 
    def test_stacked_get_stream_unordered(self):
3034
 
        # Repository._get_source.get_stream() from a stacked repository with
3035
 
        # unordered yields the full data from both stacked and stacked upon
3036
 
        # sources.
3037
 
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered')
3038
 
        self.assertEqual(set(expected_revs), set(rev_ord))
3039
 
        # Getting unordered results should have made a streaming data request
3040
 
        # from the server, then one from the backing branch.
3041
 
        self.assertLength(2, self.hpss_calls)
3042
 
 
3043
 
    def test_stacked_on_stacked_get_stream_unordered(self):
3044
 
        # Repository._get_source.get_stream() from a stacked repository which
3045
 
        # is itself stacked yields the full data from all three sources.
3046
 
        def make_stacked_stacked():
3047
 
            _, stacked = self.prepare_stacked_remote_branch()
3048
 
            tree = stacked.bzrdir.sprout('tree3', stacked=True
3049
 
                ).open_workingtree()
3050
 
            local_tree = tree.branch.create_checkout('local-tree3')
3051
 
            local_tree.commit('more local changes are better')
3052
 
            branch = Branch.open(self.get_url('tree3'))
3053
 
            branch.lock_read()
3054
 
            self.addCleanup(branch.unlock)
3055
 
            return None, branch
3056
 
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
3057
 
            branch_factory=make_stacked_stacked)
3058
 
        self.assertEqual(set(expected_revs), set(rev_ord))
3059
 
        # Getting unordered results should have made a streaming data request
3060
 
        # from the server, and one from each backing repo
3061
 
        self.assertLength(3, self.hpss_calls)
3062
 
 
3063
 
    def test_stacked_get_stream_topological(self):
3064
 
        # Repository._get_source.get_stream() from a stacked repository with
3065
 
        # topological sorting yields the full data from both stacked and
3066
 
        # stacked upon sources in topological order.
3067
 
        rev_ord, expected_revs = self.get_ordered_revs('knit', 'topological')
3068
 
        self.assertEqual(expected_revs, rev_ord)
3069
 
        # Getting topological sort requires VFS calls still - one of which is
3070
 
        # pushing up from the bound branch.
3071
 
        self.assertLength(13, self.hpss_calls)
3072
 
 
3073
 
    def test_stacked_get_stream_groupcompress(self):
3074
 
        # Repository._get_source.get_stream() from a stacked repository with
3075
 
        # groupcompress sorting yields the full data from both stacked and
3076
 
        # stacked upon sources in groupcompress order.
3077
 
        raise tests.TestSkipped('No groupcompress ordered format available')
3078
 
        rev_ord, expected_revs = self.get_ordered_revs('dev5', 'groupcompress')
3079
 
        self.assertEqual(expected_revs, reversed(rev_ord))
3080
 
        # Getting unordered results should have made a streaming data request
3081
 
        # from the backing branch, and one from the stacked on branch.
3082
 
        self.assertLength(2, self.hpss_calls)
3083
 
 
3084
 
    def test_stacked_pull_more_than_stacking_has_bug_360791(self):
3085
 
        # When pulling some fixed amount of content that is more than the
3086
 
        # source has (because some is coming from a fallback branch, no error
3087
 
        # should be received. This was reported as bug 360791.
3088
 
        # Need three branches: a trunk, a stacked branch, and a preexisting
3089
 
        # branch pulling content from stacked and trunk.
3090
 
        self.setup_smart_server_with_call_log()
3091
 
        trunk = self.make_branch_and_tree('trunk', format="1.9-rich-root")
3092
 
        r1 = trunk.commit('start')
3093
 
        stacked_branch = trunk.branch.create_clone_on_transport(
3094
 
            self.get_transport('stacked'), stacked_on=trunk.branch.base)
3095
 
        local = self.make_branch('local', format='1.9-rich-root')
3096
 
        local.repository.fetch(stacked_branch.repository,
3097
 
            stacked_branch.last_revision())
3098
 
 
3099
1927
 
3100
1928
class TestRemoteBranchEffort(tests.TestCaseWithTransport):
3101
1929
 
3104
1932
        # Create a smart server that publishes whatever the backing VFS server
3105
1933
        # does.
3106
1934
        self.smart_server = server.SmartTCPServer_for_testing()
3107
 
        self.start_server(self.smart_server, self.get_server())
 
1935
        self.smart_server.setUp(self.get_server())
 
1936
        self.addCleanup(self.smart_server.tearDown)
3108
1937
        # Log all HPSS calls into self.hpss_calls.
3109
1938
        _SmartClient.hooks.install_named_hook(
3110
1939
            'call', self.capture_hpss_call, None)