21
from bzrlib import bzrdir, errors
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
257
265
2, rev2, True, None, True)
270
class EmptyPushSmartEffortTests(TestCaseWithBranch):
271
"""Tests that a push of 0 revisions should make a limited number of smart
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 '
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
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)
299
def capture_hpss_call(self, params):
300
self.hpss_calls.append(params.method)
302
def test_empty_branch_api(self):
303
"""The branch_obj.push API should make a limited number of HPSS calls.
305
transport = get_transport(self.smart_server.get_url()).clone('target')
306
target = Branch.open_from_transport(transport)
307
self.empty_branch.push(target)
310
'BzrDir.open_branch',
311
'BzrDir.find_repositoryV2',
312
'Branch.get_stacked_on_url',
314
'Branch.last_revision_info',
318
def test_empty_branch_command(self):
319
"""The 'bzr push' command should make a limited number of HPSS calls.
321
cmd = builtins.cmd_push()
322
cmd.outf = tests.StringIOWrapper()
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)