Author: cutting
Date: Wed May 23 20:42:11 2012
New Revision: 1342041
URL: http://svn.apache.org/viewvc?rev=1342041&view=rev
Log:
Revert patch for AVRO-1028 (r1340271) that breaks RPC interop tests.
Modified:
avro/trunk/BUILD.txt
avro/trunk/CHANGES.txt
avro/trunk/lang/py/setup.py
avro/trunk/lang/py/src/avro/ipc.py
avro/trunk/lang/py/test/test_ipc.py
Modified: avro/trunk/BUILD.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/BUILD.txt?rev=1342041&r1=1342040&r2=1342041&view=diff
==============================================================================
--- avro/trunk/BUILD.txt (original)
+++ avro/trunk/BUILD.txt Wed May 23 20:42:11 2012
@@ -6,7 +6,7 @@ The following packages must be installed
- Java: JDK 1.6, Maven 2 or better, protobuf-compile
- PHP: php5, phpunit, php5-gmp
- - Python: 2.5 or greater, urllib3, python-setuptools for dist target
+ - Python: 2.5 or greater, python-setuptools for dist target
- C: gcc, cmake, asciidoc, source-highlight
- C++: cmake 2.8.4 or greater, g++, flex, bison, libboost-dev
- Ruby: ruby 1.86 or greater, ruby-dev, gem, rake, echoe, yajl-ruby
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1342041&r1=1342040&r2=1342041&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed May 23 20:42:11 2012
@@ -46,9 +46,6 @@ Avro 1.7.0 (unreleased)
AVRO-1050. PHP: Optimize memory use by string append. (A B via cutting)
- AVRO-1028. Python: Fix HTTP server to handle connection resets and
- redirects. (Bo Shi via cutting)
-
AVRO-1095. C++ compiler warns about control reaching end of
doAdavance (in JsonIO.cc) which returns something other than
void. (thiru)
Modified: avro/trunk/lang/py/setup.py
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/py/setup.py?rev=1342041&r1=1342040&r2=1342041&view=diff
==============================================================================
--- avro/trunk/lang/py/setup.py (original)
+++ avro/trunk/lang/py/setup.py Wed May 23 20:42:11 2012
@@ -21,7 +21,7 @@ except ImportError:
from distutils.core import setup
from sys import version_info
-install_requires = ['python-snappy', 'urllib3']
+install_requires = ['python-snappy']
if version_info[:2] <= (2, 5):
install_requires.append('simplejson >= 2.0.9')
Modified: avro/trunk/lang/py/src/avro/ipc.py
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/py/src/avro/ipc.py?rev=1342041&r1=1342040&r2=1342041&view=diff
==============================================================================
--- avro/trunk/lang/py/src/avro/ipc.py (original)
+++ avro/trunk/lang/py/src/avro/ipc.py Wed May 23 20:42:11 2012
@@ -16,8 +16,7 @@
"""
Support for inter-process calls.
"""
-import uuid
-from urllib3.connectionpool import HTTPConnectionPool
+import httplib
try:
from cStringIO import StringIO
except ImportError:
@@ -440,57 +439,45 @@ class HTTPTransceiver(object):
A simple HTTP-based transceiver implementation.
Useful for clients but not for servers
"""
- def __init__(self, host, port, req_resource='/', remote_name=None,
- timeout=None, redirect=True, max_pool_size=1, block=1):
- """
- The following parameters set behavior for the underlying connection pool
- for this transceiver.
-
- :param redirect:
- Automatically handle redirects (status codes 301, 302, 303, 307), each
- redirect counts as a retry.
-
- :param timeout:
- Socket timeout for each individual connection, can be a float. None
- disables timeout.
-
- :param maxsize:
- Number of connections to save that can be reused. More than 1 is useful
- in multithreaded situations. If ``block`` is set to false, more
- connections will be created but they will not be saved once they've been
- used.
-
- :param block:
- If set to True, no more than ``maxsize`` connections will be used at a
- time. When no free connections are available, the call will block until a
- connection has been released. This is a useful side effect for particular
- multithreaded situations where one does not want to use more than maxsize
- connections per host to prevent flooding.
- """
+ def __init__(self, host, port, req_resource='/'):
self.req_resource = req_resource
- self._remote_name = remote_name or uuid.uuid4()
- self._pool = HTTPConnectionPool(host, port=port, timeout=timeout,
- maxsize=max_pool_size, block=block)
- self._redirect = redirect
+ self.conn = httplib.HTTPConnection(host, port)
+ self.conn.connect()
# read-only properties
- pool = property(lambda self: self._pool)
- remote_name = property(lambda self: self._remote_name)
- redirect = property(lambda self: self._redirect)
+ sock = property(lambda self: self.conn.sock)
+ remote_name = property(lambda self: self.sock.getsockname())
+
+ # read/write properties
+ def set_conn(self, new_conn):
+ self._conn = new_conn
+ conn = property(lambda self: self._conn, set_conn)
+ req_resource = '/'
def transceive(self, request):
+ self.write_framed_message(request)
+ result = self.read_framed_message()
+ return result
+
+ def read_framed_message(self):
+ response = self.conn.getresponse()
+ response_reader = FramedReader(response)
+ framed_message = response_reader.read_framed_message()
+ response.read() # ensure we're ready for subsequent requests
+ return framed_message
+
+ def write_framed_message(self, message):
req_method = 'POST'
req_headers = {'Content-Type': 'avro/binary'}
req_body_buffer = FramedWriter(StringIO())
- req_body_buffer.write_framed_message(request)
- response = self.pool.urlopen(req_method, self.req_resource,
- body=req_body_buffer.writer.getvalue(),
- headers=req_headers,
- redirect=self.redirect)
+ req_body_buffer.write_framed_message(message)
+ req_body = req_body_buffer.writer.getvalue()
- return FramedReader(StringIO(response.data)).read_framed_message()
+ self.conn.request(req_method, self.req_resource, req_body, req_headers)
+ def close(self):
+ self.conn.close()
#
# Server Implementations (none yet)
Modified: avro/trunk/lang/py/test/test_ipc.py
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/py/test/test_ipc.py?rev=1342041&r1=1342040&r2=1342041&view=diff
==============================================================================
--- avro/trunk/lang/py/test/test_ipc.py (original)
+++ avro/trunk/lang/py/test/test_ipc.py Wed May 23 20:42:11 2012
@@ -17,62 +17,18 @@
There are currently no IPC tests within python, in part because there are no
servers yet available.
"""
-import time
import unittest
-from multiprocessing import Process
# This test does import this code, to make sure it at least passes
# compilation.
-from avro import ipc, txipc
-from twisted.web import server
-from twisted.internet import reactor
-from txsample_http_server import MailResponder, MAIL_PROTOCOL
-
-
-def test_twisted_server():
- root = server.Site(txipc.AvroResponderResource(MailResponder()))
- reactor.listenTCP(9097, root)
- reactor.run()
-
-
-class TestIPCClient(unittest.TestCase):
- def setUp(self):
- self.testserver = Process(target=test_twisted_server)
- self.testserver.start()
- # Is there a better way to wait until the server is ready to accept
- # connections?
- time.sleep(1)
-
- def tearDown(self):
- self.testserver.terminate()
-
- def test_reconnect(self):
- message = {
- 'to': '[email protected]',
- 'from': '[email protected]',
- 'body': 'hello world',
- }
-
- client = ipc.HTTPTransceiver('localhost', 9097)
- requestor = ipc.Requestor(MAIL_PROTOCOL, client)
-
- expected = u'Sent message to [email protected] from [email protected] with body
hello world'
- params = {'message': message}
- for msg_count in range(1):
- self.assertEqual(expected, requestor.request('send', params))
- self.tearDown()
- self.setUp()
- time.sleep(1)
- for msg_count in range(2):
- self.assertEqual(expected, requestor.request('send', params))
-
+from avro import ipc
class TestIPC(unittest.TestCase):
def test_placeholder(self):
pass
def test_server_with_path(self):
- client_with_custom_path = ipc.HTTPTransceiver('dummyserver.net', 80,
req_resource='/service/article')
+ client_with_custom_path = ipc.HTTPTransceiver('dummyserver.net', 80,
'/service/article')
self.assertEqual('/service/article', client_with_custom_path.req_resource)
client_with_default_path = ipc.HTTPTransceiver('dummyserver.net', 80)