/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_knit.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-01 15:06:29 UTC
  • mto: (2172.3.1 bzr.73948)
  • mto: This revision was merged to the branch mainline in revision 2181.
  • Revision ID: v.ladeuil+lp@free.fr-20061201150629-zjd2an87u0r7nhhw
The tests that would have help avoid bug #73948 and all that mess :)

* bzrlib/transport/http/response.py:
(handle_response): Translate a 416 http error code into a bzr
exception.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPDefaultErrorHandler.http_error_default): Translate a 416 http
error code into a bzr exception.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): It could happen that pycrul
itself detect a short read.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._retry_get): New method, factorizing the retry
logic.
(HttpTransportBase.readv): We can have exception during the
initial GET worth degrading the range requirements (i.e. retrying
the GET request with either single or not ranges).

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_readv_short_read): InvalidRange can also be
raised.

* bzrlib/tests/test_http.py:
(TestRangeRequestServer.test_readv_invalid_ranges): Was named
test_readv_short_read, the new name make the intent
clearer. Depending of the code path used (urllib or pycurl), both
exceptions can be raised.

* bzrlib/tests/HttpServer.py:
(TestingHTTPRequestHandler.do_GET): If invalid ranges are
specified, returns a 416 instead of the whole file (both are valid
according to the RFC).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
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
16
 
 
17
 
"""Benchmarks for Knit performance"""
18
 
 
19
 
import os
20
 
 
21
 
from bzrlib import (
22
 
    generate_ids,
23
 
    knit,
24
 
    tests,
25
 
    )
26
 
from bzrlib.benchmarks import Benchmark
27
 
from bzrlib.tests.test_knit import CompiledKnitFeature
28
 
 
29
 
 
30
 
class BenchKnitIndex(Benchmark):
31
 
    """Benchmark Knit index performance."""
32
 
 
33
 
    def create_50k_index(self):
34
 
        """Create an knit index file with 50,000 entries.
35
 
 
36
 
        This isn't super realistic, but it *is* big :)
37
 
 
38
 
        The file 'test.kndx' will be created.
39
 
        """
40
 
        rev_id = generate_ids.gen_revision_id('long.name@this.example.com')
41
 
        versions = [(rev_id, ('fulltext',), 0, 200, [])]
42
 
        pos = 200
43
 
        alt_parent = None
44
 
        for i in xrange(49999):
45
 
            if alt_parent is not None:
46
 
                parent_ids = [rev_id, alt_parent]
47
 
            else:
48
 
                parent_ids = [rev_id]
49
 
            if i % 8 == 0:
50
 
                # The *next* entry will be a merge
51
 
                alt_parent = rev_id
52
 
            else:
53
 
                alt_parent = None
54
 
            rev_id = generate_ids.gen_revision_id('long.name@this.example.com')
55
 
            versions.append((rev_id, ('line-delta',), pos, 200, parent_ids))
56
 
            pos += 200
57
 
        t = self.get_transport()
58
 
        kndx = knit._KnitIndex(t, 'test.kndx', 'w', create=True,
59
 
                               delay_create=True)
60
 
        kndx.add_versions(versions)
61
 
 
62
 
    def setup_load_data_c(self):
63
 
        self.requireFeature(CompiledKnitFeature)
64
 
        from bzrlib._knit_load_data_pyx import _load_data_c
65
 
        self.overrideAttr(knit, '_load_data', _load_data_c)
66
 
 
67
 
    def setup_load_data_py(self):
68
 
        from bzrlib._knit_load_data_py import _load_data_py
69
 
        self.overrideAttr(knit, '_load_data', _load_data_py)
70
 
 
71
 
    def test_read_50k_index_c(self):
72
 
        self.setup_load_data_c()
73
 
        self.create_50k_index()
74
 
        t = self.get_transport()
75
 
        kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')
76
 
 
77
 
    def test_read_50k_index_c_again(self):
78
 
        self.setup_load_data_c()
79
 
        self.create_50k_index()
80
 
        t = self.get_transport()
81
 
        kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')
82
 
 
83
 
    def test_read_50k_index_py(self):
84
 
        self.create_50k_index()
85
 
        self.setup_load_data_py()
86
 
        t = self.get_transport()
87
 
        kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')
88
 
 
89
 
    def test_read_50k_index_py_again(self):
90
 
        self.create_50k_index()
91
 
        self.setup_load_data_py()
92
 
        t = self.get_transport()
93
 
        kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')