qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonat...@apache.org
Subject svn commit: r752972 - in /qpid/trunk/qpid/python/examples/datatypes: ./ client.py server.py testdata.py verify
Date Thu, 12 Mar 2009 18:59:07 GMT
Author: jonathan
Date: Thu Mar 12 18:59:07 2009
New Revision: 752972

URL: http://svn.apache.org/viewvc?rev=752972&view=rev
Log:
Tests Unicode and handling of all datatypes in application
headers. Things commented out don't work yet.


Added:
    qpid/trunk/qpid/python/examples/datatypes/
    qpid/trunk/qpid/python/examples/datatypes/client.py   (with props)
    qpid/trunk/qpid/python/examples/datatypes/server.py   (with props)
    qpid/trunk/qpid/python/examples/datatypes/testdata.py
    qpid/trunk/qpid/python/examples/datatypes/verify

Added: qpid/trunk/qpid/python/examples/datatypes/client.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/examples/datatypes/client.py?rev=752972&view=auto
==============================================================================
--- qpid/trunk/qpid/python/examples/datatypes/client.py (added)
+++ qpid/trunk/qpid/python/examples/datatypes/client.py Thu Mar 12 18:59:07 2009
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+"""
+ client.py
+
+ Client for testing use of Unicode and datatypes.
+
+ Both client and server will be written in C++ and Python.
+ Tests can run clients and servers written in different
+ languages, and they can be run on 32-bit and 64-bit architectures.
+
+"""
+
+import qpid
+import sys
+import os
+from qpid.util import connect
+from qpid.connection import Connection
+from qpid.datatypes import Message, RangedSet, uuid4
+from qpid.queue import Empty
+
+import testdata
+
+#----- Initialization --------------------------------------
+
+
+#  Set parameters for login
+
+host="127.0.0.1"
+port=5672
+user="guest"
+password="guest"
+
+# If an alternate host or port has been specified, use that instead
+# (this is used in our unit tests)
+if len(sys.argv) > 1 :
+  host=sys.argv[1]
+if len(sys.argv) > 2 :
+  port=int(sys.argv[2])
+
+#  Create a connection.
+socket = connect(host, port)
+connection = Connection (sock=socket, username=user, password=password)
+connection.start()
+session = connection.session(str(uuid4()))
+
+
+#----- Main Body -- ----------------------------------------
+
+# Create a response queue for the server to send responses to. Use the
+# same string as the name of the queue and the name of the routing
+# key.
+
+reply_to = "reply_to:" + session.name
+session.queue_declare(queue=reply_to, exclusive=True)
+session.exchange_bind(exchange="amq.direct", queue=reply_to, binding_key=reply_to)
+
+# Create a local queue and subscribe it to the response queue
+
+local_queue_name = "local_queue"
+queue = session.incoming(local_queue_name)
+
+# Call message_subscribe() to tell the broker to deliver messages from
+# the server's reply_to queue to our local client queue. The server
+# will start delivering messages as soon as message credit is
+# available.
+
+session.message_subscribe(queue=reply_to, destination=local_queue_name)
+queue.start()
+
+# Set up the properties. Perhaps a few application headers?
+
+delivery_properties = session.delivery_properties(routing_key="request")
+
+message_properties = session.message_properties()
+
+message_properties.content_encoding="text/plain; charset='utf-8'"
+
+testdata.set_application_headers(message_properties)
+message_properties.reply_to = session.reply_to("amq.direct", reply_to)
+
+# deliver the message - remember to encode the Unicode string!
+request = Message(message_properties, delivery_properties, testdata.String_Greek.encode("utf8"))
+session.message_transfer(destination="amq.direct", message=request)
+
+# Now see what messages the server sent to our reply_to queue
+
+try:
+  response = queue.get(timeout=10)
+  content = response.body
+  session.message_accept(RangedSet(response.id))
+  testdata.check_message(response)
+  print "Response: " + content
+except Empty:
+  print "No more messages!"
+  exit(1)
+except:
+  print "Unexpected exception!"
+  exit(1)
+
+#----- Cleanup ------------------------------------------------
+
+# Clean up before exiting so there are no open threads.
+
+session.close(timeout=10)

Propchange: qpid/trunk/qpid/python/examples/datatypes/client.py
------------------------------------------------------------------------------
    svn:executable = *

Added: qpid/trunk/qpid/python/examples/datatypes/server.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/examples/datatypes/server.py?rev=752972&view=auto
==============================================================================
--- qpid/trunk/qpid/python/examples/datatypes/server.py (added)
+++ qpid/trunk/qpid/python/examples/datatypes/server.py Thu Mar 12 18:59:07 2009
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+"""
+ server.py
+
+ Server for testing use of Unicode and datatypes.
+
+ Both client and server will be written in C++ and Python.
+ Tests can run clients and servers written in different
+ languages, and they can be run on 32-bit and 64-bit architectures.
+"""
+
+import testdata
+
+import qpid
+import sys
+import os
+from qpid.util import connect
+from qpid.connection import Connection
+from qpid.datatypes import Message, RangedSet, uuid4
+from qpid.queue import Empty
+
+#----- Functions -------------------------------------------
+def respond(session, request):
+
+    # The routing key for the response is the request's reply-to
+    # property.  The body for the response is the request's body,
+    # converted to upper case.
+
+    testdata.check_message(request)
+
+    message_properties = request.get("message_properties")
+    reply_to = message_properties.reply_to
+
+    testdata.set_application_headers(message_properties)
+
+    if reply_to == None:
+       raise Exception("This message is missing the 'reply_to' property, which is required")
  
+   
+    delivery_properties = session.delivery_properties(routing_key=reply_to["routing_key"])

+    response = Message(delivery_properties, message_properties, testdata.String_Greek.encode("utf8"))
+    print "Sending response ..."
+    session.message_transfer(destination=reply_to["exchange"], message=response)
+
+#----- Initialization --------------------------------------
+
+
+#  Set parameters for login
+
+host="127.0.0.1"
+port=5672
+user="guest"
+password="guest"
+
+# If an alternate host or port has been specified, use that instead
+# (this is used in our unit tests)
+if len(sys.argv) > 1 :
+  host=sys.argv[1]
+if len(sys.argv) > 2 :
+  port=int(sys.argv[2])
+
+socket = connect(host, port)
+connection = Connection (sock=socket, username=user, password=password)
+connection.start()
+session = connection.session(str(uuid4()))
+
+#----- Main Body -- ----------------------------------------
+
+# Create a request queue and subscribe to it
+
+session.queue_declare(queue="request", exclusive=True)
+session.exchange_bind(exchange="amq.direct", queue="request", binding_key="request")
+
+local_queue_name = "local_queue"
+
+session.message_subscribe(queue="request", destination=local_queue_name)
+
+queue = session.incoming(local_queue_name)
+queue.start()
+
+# Remind the user to start the client program
+
+print "Request server running - run your client now."
+print "(Times out after 100 seconds ...)"
+sys.stdout.flush()
+
+# Respond to each request
+
+# If we get a message, send it back to the user (as indicated in the
+# ReplyTo property)
+
+while True:
+  try:
+    request = queue.get(timeout=100)
+    session.message_accept(RangedSet(request.id))
+
+    respond(session, request)
+  except Empty:
+    print "No more messages!"
+    break;
+
+
+#----- Cleanup ------------------------------------------------
+
+# Clean up before exiting so there are no open threads.
+
+session.close(timeout=10)

Propchange: qpid/trunk/qpid/python/examples/datatypes/server.py
------------------------------------------------------------------------------
    svn:executable = *

Added: qpid/trunk/qpid/python/examples/datatypes/testdata.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/examples/datatypes/testdata.py?rev=752972&view=auto
==============================================================================
--- qpid/trunk/qpid/python/examples/datatypes/testdata.py (added)
+++ qpid/trunk/qpid/python/examples/datatypes/testdata.py Thu Mar 12 18:59:07 2009
@@ -0,0 +1,180 @@
+# -*- encoding: utf-8 -*-
+
+from qpid.datatypes import uuid4, timestamp
+
+#----- Some variables to test boundary conditions on various data types
+
+void = None
+boolean_true = True
+boolean_false = False
+Uint8_0 = 0
+Uint8_max = 255
+Uint16_0 = 0
+Uint16_max = 65535
+Uint32_0 = 0
+Uint32_max = 4294967295
+Uint64_0 = 0
+Uint64_max = 18446744073709551615
+Int8_min = -128
+Int8_0 = 0
+Int8_max = 127
+Int16_min = -32768
+Int16_0 = 0
+Int16_max = 32767
+Int32_min = -2147483648
+Int32_0 = 0
+Int32_max = 2147483647
+Int64_min = -9223372036854775808
+Int64_0 = 0
+Int64_max = 9223372036854775807
+
+Float_pi = 3.14159265
+Float_neg = -1E4
+Float_big = 1267.43233E12
+Float_small = 12.78e-12
+Float_neg0 = -0
+Float_pos0 = 0
+Float_INF = float('inf')
+Float_Negative_INF = float('-inf')
+
+Double_pi = 3.1415926535897932384626433832795
+Double_neg = -1E4
+Double_big = 1267.43233E12
+Double_small = 12.78e-2
+Double_neg0 = -0
+Double_pos0 = 0
+Double_INF = float('inf')
+Double_Negative_INF = float('-inf')
+
+char_1byte = u'0024' # $
+char_2byte = u'00A2' # ¢
+char_3byte = u'20AC' # €
+char_4byte = u'10ABCD'
+
+timestamp = timestamp()
+
+UUID = uuid4()
+
+String_Greek = u"ἐξίσταντο δὲ πάντες
καὶ διηπόρουν, ἄλλος πρὸς
ἄλλον λέγοντες, Τί θέλει
τοῦτο εἶναι;"
+
+String_Empty = ""
+
+#----- A few functions ----------------------------------------------------------
+
+def near_enough(float1, float2, delta):
+  return abs(float1-float2) < delta
+
+def set_application_headers(message_properties):
+
+  message_properties.application_headers = {}
+  message_properties.application_headers["void"] = None
+  message_properties.application_headers["boolean_true"] =  boolean_true
+  message_properties.application_headers["boolean_false"] = boolean_false
+  message_properties.application_headers["Uint8_0"] = Uint8_0
+  message_properties.application_headers["Uint8_max"] = Uint8_max
+  message_properties.application_headers["Uint16_0"] = Uint16_0
+  message_properties.application_headers["Uint16_max"] = Uint16_max
+  message_properties.application_headers["Uint32_0"] = Uint32_0
+  message_properties.application_headers["Uint32_max"] = Uint32_max
+  message_properties.application_headers["Uint64_0"] = Uint64_0
+#  message_properties.application_headers["Uint64_max"] = Uint64_max
+  message_properties.application_headers["Int8_min"] = Int8_min
+  message_properties.application_headers["Int8_0"] = Int8_0
+  message_properties.application_headers["Int8_max"] = Int8_max
+  message_properties.application_headers["Int16_min"] = Int16_min
+  message_properties.application_headers["Int16_0"] = Int16_0
+  message_properties.application_headers["Int16_max"] = Int16_max
+  message_properties.application_headers["Int32_min"] = Int32_min
+  message_properties.application_headers["Int32_0"] = Int32_0
+  message_properties.application_headers["Int32_max"] = Int32_max
+  message_properties.application_headers["Int64_min"] = Int64_min
+  message_properties.application_headers["Int64_0"] = Int64_0
+  message_properties.application_headers["Int64_max"] = Int64_max
+ 
+  message_properties.application_headers["Float_pi"] = Float_pi
+  message_properties.application_headers["Float_neg"] = Float_neg
+  message_properties.application_headers["Float_big"] = Float_big
+  message_properties.application_headers["Float_small"] = Float_small
+  message_properties.application_headers["Float_neg0"] = Float_neg0
+  message_properties.application_headers["Float_pos0"] = Float_pos0
+  message_properties.application_headers["Float_INF"] = Float_INF
+  message_properties.application_headers["Float_Negative_INF"] = Float_Negative_INF
+
+  message_properties.application_headers["Double_pi"] = Double_pi
+  message_properties.application_headers["Double_neg"] = Double_neg
+  message_properties.application_headers["Double_big"] = Double_big
+  message_properties.application_headers["Double_small"] = Double_small
+  message_properties.application_headers["Double_neg0"] = Double_neg0
+  message_properties.application_headers["Double_pos0"] = Double_pos0
+  message_properties.application_headers["Double_INF"] = Double_INF
+  message_properties.application_headers["Double_Negative_INF"] = Double_Negative_INF
+
+  message_properties.application_headers["char_1byte"] = char_1byte
+  message_properties.application_headers["char_2byte"] = char_2byte
+  message_properties.application_headers["char_3byte"] = char_3byte
+  message_properties.application_headers["char_4byte"] = char_4byte
+
+  message_properties.application_headers["timestamp"] = timestamp
+  message_properties.application_headers["UUID"] = uuid4() 
+  message_properties.application_headers["String_Greek"] = String_Greek 
+  message_properties.application_headers["String_Empty"] = String_Empty
+
+def check_message(message):
+
+#  message_properties = message.message_properties()
+  message_properties = message.get("message_properties")
+  assert message_properties.application_headers["void"] == None
+  assert message_properties.application_headers["boolean_true"] == boolean_true
+  assert message_properties.application_headers["boolean_false"] == boolean_false
+  assert message_properties.application_headers["Uint8_0"] == Uint8_0
+  assert message_properties.application_headers["Uint8_max"] == Uint8_max
+  assert message_properties.application_headers["Uint16_0"] == Uint16_0
+  assert message_properties.application_headers["Uint16_max"] == Uint16_max
+  assert message_properties.application_headers["Uint32_0"] == Uint32_0
+  assert message_properties.application_headers["Uint32_max"] == Uint32_max
+  assert message_properties.application_headers["Uint64_0"] == Uint64_0
+#  assert message_properties.application_headers["Uint64_max"] == Uint64_max
+  assert message_properties.application_headers["Int8_min"] == Int8_min
+  assert message_properties.application_headers["Int8_0"] == Int8_0
+  assert message_properties.application_headers["Int8_max"] == Int8_max
+  assert message_properties.application_headers["Int16_min"] == Int16_min
+  assert message_properties.application_headers["Int16_0"] == Int16_0
+  assert message_properties.application_headers["Int16_max"] == Int16_max
+  assert message_properties.application_headers["Int32_min"] == Int32_min
+  assert message_properties.application_headers["Int32_0"] == Int32_0
+  assert message_properties.application_headers["Int32_max"] == Int32_max
+  assert message_properties.application_headers["Int64_min"] == Int64_min
+  assert message_properties.application_headers["Int64_0"] == Int64_0
+  assert message_properties.application_headers["Int64_max"] == Int64_max
+  
+# Change floating point comparisons to allow inexactness
+
+  assert near_enough(message_properties.application_headers["Float_pi"], Float_pi, 0.00001)
+  assert near_enough(message_properties.application_headers["Float_neg"], Float_neg, 0.00001)
+  assert near_enough(message_properties.application_headers["Float_big"], Float_big, Float_big/1000000)
+  assert near_enough(message_properties.application_headers["Float_small"], Float_small,
0.00001)
+  assert message_properties.application_headers["Float_neg0"] == Float_neg0
+  assert message_properties.application_headers["Float_pos0"] == Float_pos0
+  assert message_properties.application_headers["Float_INF"] == Float_INF
+  assert message_properties.application_headers["Float_Negative_INF"] == Float_Negative_INF
+
+  assert near_enough(message_properties.application_headers["Double_pi"], Double_pi, 0.00001)
+  assert near_enough(message_properties.application_headers["Double_neg"], Double_neg, 0.00001)
+  assert near_enough(message_properties.application_headers["Double_big"], Double_big, Double_big/1000000)
+  assert near_enough(message_properties.application_headers["Double_small"], Double_small,
0.00001)
+  assert message_properties.application_headers["Double_neg0"] == Double_neg0
+  assert message_properties.application_headers["Double_pos0"] == Double_pos0
+  assert message_properties.application_headers["Double_INF"] == Double_INF
+  assert message_properties.application_headers["Double_Negative_INF"] == Double_Negative_INF
+
+  assert message_properties.application_headers["char_1byte"] == char_1byte
+  assert message_properties.application_headers["char_2byte"] == char_2byte
+  assert message_properties.application_headers["char_3byte"] == char_3byte
+  assert message_properties.application_headers["char_4byte"] == char_4byte
+
+#  assert message_properties.application_headers["timestamp"] == timestamp
+#  assert message_properties.application_headers["UUID"] == UUID
+  assert message_properties.application_headers["String_Greek"] == String_Greek
+  assert message_properties.application_headers["String_Empty"] == String_Empty
+
+

Added: qpid/trunk/qpid/python/examples/datatypes/verify
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/examples/datatypes/verify?rev=752972&view=auto
==============================================================================
--- qpid/trunk/qpid/python/examples/datatypes/verify (added)
+++ qpid/trunk/qpid/python/examples/datatypes/verify Thu Mar 12 18:59:07 2009
@@ -0,0 +1,24 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify 
+background "Request server running" ./server.py
+clients ./client.py
+kill %% 			# Must kill the server.
+outputs "./client.py.out" " server.py.out"



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message