Rev 2588: * The ``SmartServer`` hooks API has changed for the ``server_started`` and in http://people.ubuntu.com/~robertc/baz2.0/external_url
Robert Collins
robertc at robertcollins.net
Thu Jul 5 03:38:50 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/external_url
------------------------------------------------------------
revno: 2588
revision-id: robertc at robertcollins.net-20070705023829-5l21034oalccsz7h
parent: robertc at robertcollins.net-20070705010911-q93psu3cxxhn8isr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: external_url
timestamp: Thu 2007-07-05 12:38:29 +1000
message:
* The ``SmartServer`` hooks API has changed for the ``server_started`` and
``server_stopped`` hooks. The first parameter is now an iterable of
backing URLs rather than a single URL. This is to reflect that many
URLs may map to the external URL of the server. E.g. the server interally
may have a chrooted URL but also the local file:// URL will be at the
same location. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/smart/server.py server.py-20061110062051-chzu10y32vx8gvur-1
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
=== modified file 'NEWS'
--- a/NEWS 2007-07-05 01:09:11 +0000
+++ b/NEWS 2007-07-05 02:38:29 +0000
@@ -124,6 +124,13 @@
* ``LockDir.wait`` removed. (Martin Pool)
+ * The ``SmartServer`` hooks API has changed for the ``server_started`` and
+ ``server_stopped`` hooks. The first parameter is now an iterable of
+ backing URLs rather than a single URL. This is to reflect that many
+ URLs may map to the external URL of the server. E.g. the server interally
+ may have a chrooted URL but also the local file:// URL will be at the
+ same location. (Robert Collins)
+
INTERNALS:
* New SMTPConnection class to unify email handling. (Adeodato Simó)
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py 2007-04-20 05:11:46 +0000
+++ b/bzrlib/smart/server.py 2007-07-05 02:38:29 +0000
@@ -22,6 +22,7 @@
from bzrlib.hooks import Hooks
from bzrlib import (
+ errors,
trace,
transport,
)
@@ -65,8 +66,27 @@
def serve(self):
self._should_terminate = False
+ # for hooks we are letting code know that a server has started (and
+ # later stopped).
+ # There are three interesting urls:
+ # The URL the server can be contacted on.
+ # The URL that a commit done on the same machine as the server will
+ # have within the servers space.
+ # The URL that will be given to other hooks in the same process -
+ # The URL of the backing transport itself.
+ # We need all three because:
+ # * other machines see the first
+ # * local commits on this machine should be able to be mapped to
+ # this server
+ # * commits the server does itself need to be mapped across to this
+ # server.
+ backing_urls = [self.backing_transport.base]
+ try:
+ backing_urls.append(self.backing_transport.external_url())
+ except errors.InProcessTransport:
+ pass
for hook in SmartTCPServer.hooks['server_started']:
- hook(self.backing_transport.base, self.get_url())
+ hook(backing_urls, self.get_url())
self._started.set()
try:
try:
@@ -100,7 +120,7 @@
# ignore errors on close
pass
for hook in SmartTCPServer.hooks['server_stopped']:
- hook(self.backing_transport.base, self.get_url())
+ hook(backing_urls, self.get_url())
def get_url(self):
"""Return the url of the server"""
@@ -163,11 +183,11 @@
Hooks.__init__(self)
# Introduced in 0.16:
# invoked whenever the server starts serving a directory.
- # The api signature is (backing url, public url).
+ # The api signature is (backing urls, public url).
self['server_started'] = []
# Introduced in 0.16:
# invoked whenever the server stops serving a directory.
- # The api signature is (backing url, public url).
+ # The api signature is (backing urls, public url).
self['server_stopped'] = []
SmartTCPServer.hooks = SmartServerHooks()
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2007-04-27 02:19:11 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2007-07-05 02:38:29 +0000
@@ -860,12 +860,15 @@
the server is obtained by calling self.setUpServer(readonly=False).
"""
- def setUpServer(self, readonly=False):
+ def setUpServer(self, readonly=False, backing_transport=None):
"""Setup the server.
:param readonly: Create a readonly server.
"""
- self.backing_transport = memory.MemoryTransport()
+ if not backing_transport:
+ self.backing_transport = memory.MemoryTransport()
+ else:
+ self.backing_transport = backing_transport
if readonly:
self.real_backing_transport = self.backing_transport
self.backing_transport = get_transport("readonly+" + self.backing_transport.abspath('.'))
@@ -998,29 +1001,66 @@
class TestServerHooks(SmartTCPTests):
- def capture_server_call(self, backing_url, public_url):
+ def capture_server_call(self, backing_urls, public_url):
"""Record a server_started|stopped hook firing."""
- self.hook_calls.append((backing_url, public_url))
-
- def test_server_started_hook(self):
- """The server_started hook fires when the server is started."""
- self.hook_calls = []
- server.SmartTCPServer.hooks.install_hook('server_started',
- self.capture_server_call)
- self.setUpServer()
- # at this point, the server will be starting a thread up.
- # there is no indicator at the moment, so bodge it by doing a request.
- self.transport.has('.')
- self.assertEqual([(self.backing_transport.base, self.transport.base)],
- self.hook_calls)
-
- def test_server_stopped_hook_simple(self):
- """The server_stopped hook fires when the server is stopped."""
- self.hook_calls = []
- server.SmartTCPServer.hooks.install_hook('server_stopped',
- self.capture_server_call)
- self.setUpServer()
- result = [(self.backing_transport.base, self.transport.base)]
+ self.hook_calls.append((backing_urls, public_url))
+
+ def test_server_started_hook_memory(self):
+ """The server_started hook fires when the server is started."""
+ self.hook_calls = []
+ server.SmartTCPServer.hooks.install_hook('server_started',
+ self.capture_server_call)
+ self.setUpServer()
+ # at this point, the server will be starting a thread up.
+ # there is no indicator at the moment, so bodge it by doing a request.
+ self.transport.has('.')
+ # The default test server uses MemoryTransport and that has no external
+ # url:
+ self.assertEqual([([self.backing_transport.base], self.transport.base)],
+ self.hook_calls)
+
+ def test_server_started_hook_file(self):
+ """The server_started hook fires when the server is started."""
+ self.hook_calls = []
+ server.SmartTCPServer.hooks.install_hook('server_started',
+ self.capture_server_call)
+ self.setUpServer(backing_transport=get_transport("."))
+ # at this point, the server will be starting a thread up.
+ # there is no indicator at the moment, so bodge it by doing a request.
+ self.transport.has('.')
+ # The default test server uses MemoryTransport and that has no external
+ # url:
+ self.assertEqual([([
+ self.backing_transport.base, self.backing_transport.external_url()],
+ self.transport.base)],
+ self.hook_calls)
+
+ def test_server_stopped_hook_simple_memory(self):
+ """The server_stopped hook fires when the server is stopped."""
+ self.hook_calls = []
+ server.SmartTCPServer.hooks.install_hook('server_stopped',
+ self.capture_server_call)
+ self.setUpServer()
+ result = [([self.backing_transport.base], self.transport.base)]
+ # check the stopping message isn't emitted up front.
+ self.assertEqual([], self.hook_calls)
+ # nor after a single message
+ self.transport.has('.')
+ self.assertEqual([], self.hook_calls)
+ # clean up the server
+ self.tearDownServer()
+ # now it should have fired.
+ self.assertEqual(result, self.hook_calls)
+
+ def test_server_stopped_hook_simple_file(self):
+ """The server_stopped hook fires when the server is stopped."""
+ self.hook_calls = []
+ server.SmartTCPServer.hooks.install_hook('server_stopped',
+ self.capture_server_call)
+ self.setUpServer(backing_transport=get_transport("."))
+ result = [(
+ [self.backing_transport.base, self.backing_transport.external_url()]
+ , self.transport.base)]
# check the stopping message isn't emitted up front.
self.assertEqual([], self.hook_calls)
# nor after a single message
More information about the bazaar-commits
mailing list