/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_sftp.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
from bzrlib.benchmarks import Benchmark
 
4
from bzrlib import bzrdir
 
5
from bzrlib.tests import test_sftp_transport
 
6
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
7
import bzrlib.transport.http
 
8
from bzrlib.workingtree import WorkingTree
 
9
 
 
10
try:
 
11
    import paramiko
 
12
    paramiko_loaded = True
 
13
except ImportError:
 
14
    paramiko_loaded = False
 
15
 
 
16
 
 
17
class SFTPBenchmark(Benchmark):
 
18
    """Benchmark branch, push and pull across a local sftp connection."""
 
19
 
 
20
    def setUp(self):
 
21
        super(SFTPBenchmark, self).setUp()
 
22
        if not paramiko_loaded:
 
23
            raise TestSkipped('you must have paramiko to run this test')
 
24
        test_sftp_transport.set_test_transport_to_sftp(self) 
 
25
         
 
26
    def test_branch(self):
 
27
        os.mkdir("a")
 
28
        tree, files = self.create_with_commits(100, 100, "a")
 
29
        self.time(bzrdir.BzrDir.open(self.get_url('a')).sprout, "b")
 
30
 
 
31
    def test_pull_1(self):
 
32
        os.mkdir("a")
 
33
        tree, files = self.create_with_commits(100, 100, "a")
 
34
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
35
        b2 = tree.bzrdir.sprout("b") # branch
 
36
        # change a few files and commit
 
37
        self.commit_some_revisions(tree, files, 1, 20)
 
38
        self.time(b2.open_branch().pull, rbzrdir.open_branch())
 
39
        
 
40
    def test_pull_100(self):
 
41
        os.mkdir("a")
 
42
        tree, files = self.create_with_commits(100, 100, "a")
 
43
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
44
        b2 = tree.bzrdir.sprout("b") # branch
 
45
        # change a few files and commit
 
46
        self.commit_some_revisions(tree, files, 100, 20)
 
47
        self.time(b2.open_branch().pull, rbzrdir.open_branch())
 
48
 
 
49
    def create_commit_and_push(self, num_push_revisions):
 
50
        os.mkdir("a")
 
51
        tree, files = self.create_with_commits(100, 100, "a")
 
52
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
53
        b2 = rbzrdir.sprout("b") # branch
 
54
        wtree = b2.open_workingtree()
 
55
        # change a few files and commit
 
56
        self.commit_some_revisions(
 
57
            wtree, ["b/%i" for i in range(100)], 
 
58
            num_commits=num_push_revisions,
 
59
            changes_per_commit=20)
 
60
        self.time(rbzrdir.open_branch().pull, wtree.branch)
 
61
 
 
62
    def test_push_1(self):
 
63
        self.create_commit_and_push(1)
 
64
 
 
65
    def test_push_10(self):
 
66
        self.create_commit_and_push(10)
 
67
 
 
68
    def test_push_100(self):
 
69
        self.create_commit_and_push(100)
 
70
 
 
71
 
 
72
class SFTPSlowSocketBenchmark(SFTPBenchmark):
 
73
    def setUp(self):
 
74
        super(SFTPSlowSocketBenchmark, self).setUp()
 
75
        self.get_server().add_latency = 0.03
 
76