~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Martin Pool
  • Date: 2011-03-28 01:28:09 UTC
  • mto: (5425.4.19 220464-stale-locks)
  • mto: This revision was merged to the branch mainline in revision 5970.
  • Revision ID: mbp@canonical.com-20110328012809-frw003r09tcrxkiz
Represent lock held info as an object, not just a dict

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
25
25
"""
26
26
 
27
27
import bz2
 
28
from cStringIO import StringIO
 
29
import tarfile
28
30
 
29
31
from bzrlib import (
 
32
    bencode,
30
33
    branch as _mod_branch,
31
34
    bzrdir,
32
35
    errors,
 
36
    pack,
33
37
    tests,
34
38
    transport,
35
39
    urlutils,
99
103
        # the default or a parameterized class, but rather use the
100
104
        # TestCaseWithTransport infrastructure to set up a smart server and
101
105
        # transport.
102
 
        self.overrideAttr(self, "transport_server", self.make_transport_server)
 
106
        self.transport_server = self.make_transport_server
103
107
 
104
108
    def make_transport_server(self):
105
109
        return test_server.SmartTCPServer_for_testing('-' + self.id())
932
936
        # its repository.
933
937
        self.make_tree_with_two_commits()
934
938
        rev_id_utf8 = u'\xc8'.encode('utf-8')
935
 
        self.tree.branch.set_last_revision_info(0, 'null:')
 
939
        self.tree.branch.set_revision_history([])
936
940
        self.assertEqual(
937
941
            (0, 'null:'), self.tree.branch.last_revision_info())
938
942
        # We can update the branch to a revision that is present in the
1470
1474
            request.execute('stacked', 1, (3, r3)))
1471
1475
 
1472
1476
 
1473
 
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
 
1477
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
1474
1478
 
1475
1479
    def make_two_commit_repo(self):
1476
1480
        tree = self.make_branch_and_memory_tree('.')
1482
1486
        repo = tree.branch.repository
1483
1487
        return repo, r1, r2
1484
1488
 
1485
 
 
1486
 
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1487
 
 
1488
1489
    def test_ancestry_of(self):
1489
1490
        """The search argument may be a 'ancestry-of' some heads'."""
1490
1491
        backing = self.get_transport()
1511
1512
        stream_bytes = ''.join(response.body_stream)
1512
1513
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1513
1514
 
1514
 
    def test_search_everything(self):
1515
 
        """A search of 'everything' returns a stream."""
1516
 
        backing = self.get_transport()
1517
 
        request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
1518
 
        repo, r1, r2 = self.make_two_commit_repo()
1519
 
        serialised_fetch_spec = 'everything'
1520
 
        request.execute('', repo._format.network_name())
1521
 
        response = request.do_body(serialised_fetch_spec)
1522
 
        self.assertEqual(('ok',), response.args)
1523
 
        stream_bytes = ''.join(response.body_stream)
1524
 
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1525
 
 
1526
1515
 
1527
1516
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
1528
1517
 
1922
1911
            smart_repo.SmartServerRepositoryGetRevisionGraph)
1923
1912
        self.assertHandlerEqual('Repository.get_stream',
1924
1913
            smart_repo.SmartServerRepositoryGetStream)
1925
 
        self.assertHandlerEqual('Repository.get_stream_1.19',
1926
 
            smart_repo.SmartServerRepositoryGetStream_1_19)
1927
1914
        self.assertHandlerEqual('Repository.has_revision',
1928
1915
            smart_repo.SmartServerRequestHasRevision)
1929
1916
        self.assertHandlerEqual('Repository.insert_stream',
1940
1927
            smart_repo.SmartServerRepositoryUnlock)
1941
1928
        self.assertHandlerEqual('Transport.is_readonly',
1942
1929
            smart_req.SmartServerIsReadonly)
1943
 
 
1944
 
 
1945
 
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
1946
 
    """Tests for SmartTCPServer hooks."""
1947
 
 
1948
 
    def setUp(self):
1949
 
        super(SmartTCPServerHookTests, self).setUp()
1950
 
        self.server = server.SmartTCPServer(self.get_transport())
1951
 
 
1952
 
    def test_run_server_started_hooks(self):
1953
 
        """Test the server started hooks get fired properly."""
1954
 
        started_calls = []
1955
 
        server.SmartTCPServer.hooks.install_named_hook('server_started',
1956
 
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
1957
 
            None)
1958
 
        started_ex_calls = []
1959
 
        server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
1960
 
            lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
1961
 
            None)
1962
 
        self.server._sockname = ('example.com', 42)
1963
 
        self.server.run_server_started_hooks()
1964
 
        self.assertEquals(started_calls,
1965
 
            [([self.get_transport().base], 'bzr://example.com:42/')])
1966
 
        self.assertEquals(started_ex_calls,
1967
 
            [([self.get_transport().base], self.server)])
1968
 
 
1969
 
    def test_run_server_started_hooks_ipv6(self):
1970
 
        """Test that socknames can contain 4-tuples."""
1971
 
        self.server._sockname = ('::', 42, 0, 0)
1972
 
        started_calls = []
1973
 
        server.SmartTCPServer.hooks.install_named_hook('server_started',
1974
 
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
1975
 
            None)
1976
 
        self.server.run_server_started_hooks()
1977
 
        self.assertEquals(started_calls,
1978
 
                [([self.get_transport().base], 'bzr://:::42/')])
1979
 
 
1980
 
    def test_run_server_stopped_hooks(self):
1981
 
        """Test the server stopped hooks."""
1982
 
        self.server._sockname = ('example.com', 42)
1983
 
        stopped_calls = []
1984
 
        server.SmartTCPServer.hooks.install_named_hook('server_stopped',
1985
 
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
1986
 
            None)
1987
 
        self.server.run_server_stopped_hooks()
1988
 
        self.assertEquals(stopped_calls,
1989
 
            [([self.get_transport().base], 'bzr://example.com:42/')])