~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_push.py

Merge with get_file_sha1

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
 
21
 
from bzrlib import bzrdir, errors
 
21
from bzrlib import (
 
22
    branch,
 
23
    builtins,
 
24
    bzrdir,
 
25
    debug,
 
26
    errors,
 
27
    tests,
 
28
    )
22
29
from bzrlib.branch import Branch
23
30
from bzrlib.bzrdir import BzrDir
24
31
from bzrlib.memorytree import MemoryTree
25
 
from bzrlib.remote import RemoteBranch
26
32
from bzrlib.revision import NULL_REVISION
 
33
from bzrlib.smart import client, server
27
34
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
35
from bzrlib.transport import get_transport
28
36
from bzrlib.transport.local import LocalURLServer
29
37
 
30
38
 
257
265
             2, rev2, True, None, True)
258
266
            ],
259
267
            self.hook_calls)
 
268
 
 
269
 
 
270
class EmptyPushSmartEffortTests(TestCaseWithBranch):
 
271
    """Tests that a push of 0 revisions should make a limited number of smart
 
272
    protocol RPCs.
 
273
    """
 
274
 
 
275
    def setUp(self):
 
276
        # Skip some scenarios that don't apply to these tests.
 
277
        if (self.transport_server is not None and
 
278
            issubclass(self.transport_server, server.SmartTCPServer)):
 
279
            raise tests.TestNotApplicable(
 
280
                'Does not apply when remote backing branch is also '
 
281
                'a smart branch')
 
282
        if isinstance(self.branch_format, branch.BzrBranchFormat4):
 
283
            raise tests.TestNotApplicable(
 
284
                'Branch format 4 is not usable via HPSS.')
 
285
        super(EmptyPushSmartEffortTests, self).setUp()
 
286
        # Create a smart server that publishes whatever the backing VFS server
 
287
        # does.
 
288
        self.smart_server = server.SmartTCPServer_for_testing()
 
289
        self.smart_server.setUp(self.get_server())
 
290
        self.addCleanup(self.smart_server.tearDown)
 
291
        # Make two empty branches, 'empty' and 'target'.
 
292
        self.empty_branch = self.make_branch('empty')
 
293
        self.make_branch('target')
 
294
        # Log all HPSS calls into self.hpss_calls.
 
295
        client._SmartClient.hooks.install_named_hook(
 
296
            'call', self.capture_hpss_call, None)
 
297
        self.hpss_calls = []
 
298
 
 
299
    def capture_hpss_call(self, params):
 
300
        self.hpss_calls.append(params.method)
 
301
 
 
302
    def test_empty_branch_api(self):
 
303
        """The branch_obj.push API should make a limited number of HPSS calls.
 
304
        """
 
305
        transport = get_transport(self.smart_server.get_url()).clone('target')
 
306
        target = Branch.open_from_transport(transport)
 
307
        self.empty_branch.push(target)
 
308
        self.assertEqual(
 
309
            ['BzrDir.open',
 
310
             'BzrDir.open_branch',
 
311
             'BzrDir.find_repositoryV2',
 
312
             'Branch.get_stacked_on_url',
 
313
             'Branch.lock_write',
 
314
             'Branch.last_revision_info',
 
315
             'Branch.unlock'],
 
316
            self.hpss_calls)
 
317
 
 
318
    def test_empty_branch_command(self):
 
319
        """The 'bzr push' command should make a limited number of HPSS calls.
 
320
        """
 
321
        cmd = builtins.cmd_push()
 
322
        cmd.outf = tests.StringIOWrapper()
 
323
        cmd.run(
 
324
            directory=self.get_url() + 'empty',
 
325
            location=self.smart_server.get_url() + 'target')
 
326
        # HPSS calls as of 2008/09/22:
 
327
        # [BzrDir.open, BzrDir.open_branch, BzrDir.find_repositoryV2,
 
328
        # Branch.get_stacked_on_url, get, get, Branch.lock_write,
 
329
        # Branch.last_revision_info, Branch.unlock]
 
330
        self.assertTrue(len(self.hpss_calls) <= 9, self.hpss_calls)
 
331
 
 
332