Back to index

rabbitmq-server  2.8.4
Public Member Functions | Static Public Attributes
parsing.TestParsing Class Reference
Collaboration diagram for parsing.TestParsing:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def match
def recv_atleast
def test_newline_after_nul
def test_send_without_content_type
def test_send_without_content_type_binary
def test_newline_after_nul_and_leading_nul
def test_bad_command
def test_broadcast
def test_huge_message
def test_message_with_embedded_nulls
def test_message_in_packets

Static Public Attributes

string host = '127.0.0.1'
int port = 61613

Detailed Description

Definition at line 48 of file parsing.py.


Member Function Documentation

def parsing.TestParsing.match (   self,
  pattern,
  data 
)
helper: try to match 'pattern' regexp with 'data' string.
    Fail test if they don't match.

Definition at line 53 of file parsing.py.

00053 
00054     def match(self, pattern, data):
00055         ''' helper: try to match 'pattern' regexp with 'data' string.
00056             Fail test if they don't match.
00057         '''
00058         matched = re.match(pattern, data)
00059         if matched:
00060             return matched.groups()
00061         self.assertTrue(False, 'No match:\n%r\n%r' % (pattern, data) )

Here is the caller graph for this function:

def parsing.TestParsing.recv_atleast (   self,
  bufsize 
)

Definition at line 62 of file parsing.py.

00062 
00063     def recv_atleast(self, bufsize):
00064         recvhead = []
00065         rl = bufsize
00066         while rl > 0:
00067             buf = self.cd.recv(rl)
00068             bl = len(buf)
00069             if bl==0: break
00070             recvhead.append( buf )
00071             rl -= bl
00072         return ''.join(recvhead)
00073 

Here is the call graph for this function:

Here is the caller graph for this function:

Trigger an error message. 

Definition at line 149 of file parsing.py.

00149 
00150     def test_bad_command(self):
00151         ''' Trigger an error message. '''
00152         self.cd.sendall('WRONGCOMMAND\n'
00153                         'destination:a\n'
00154                         'exchange:amq.fanout\n'
00155                         '\n\0')
00156         resp = ('ERROR\n'
00157                 'message:Bad command\n'
00158                 'content-type:text/plain\n'
00159                 'version:1.0,1.1\n'
00160                 'content-length:43\n'
00161                 '\n'
00162                 'Could not interpret command "WRONGCOMMAND"\n'
00163                 '\0')
00164         self.match(resp, self.cd.recv(4096))

Here is the call graph for this function:

Single message should be delivered to two consumers:
    amq.topic --routing_key--> first_queue --> first_connection
     \--routing_key--> second_queue--> second_connection

Definition at line 166 of file parsing.py.

00166 
00167     def test_broadcast(self):
00168         ''' Single message should be delivered to two consumers:
00169             amq.topic --routing_key--> first_queue --> first_connection
00170                      \--routing_key--> second_queue--> second_connection
00171         '''
00172         subscribe=( 'SUBSCRIBE\n'
00173                     'id: XsKNhAf\n'
00174                     'destination:/exchange/amq.topic/da9d4779\n'
00175                     '\n\0')
00176         for cd in [self.cd1, self.cd2]:
00177             cd.sendall(subscribe)
00178 
00179         time.sleep(0.1)
00180 
00181         self.sd.sendall('SEND\n'
00182                         'content-type:text/plain\n'
00183                         'destination:/exchange/amq.topic/da9d4779\n'
00184                         '\n'
00185                         'message'
00186                         '\n\0')
00187 
00188         resp=('MESSAGE\n'
00189             'content-type:text/plain\n'
00190             'subscription:(.*)\n'
00191             'destination:/topic/da9d4779\n'
00192             'message-id:(.*)\n'
00193             'content-length:8\n'
00194             '\n'
00195             'message'
00196             '\n\x00')
00197         for cd in [self.cd1, self.cd2]:
00198             self.match(resp, cd.recv(4096))
00199 

Here is the call graph for this function:

Test sending/receiving huge (16MB) message. 

Definition at line 201 of file parsing.py.

00201 
00202     def test_huge_message(self):
00203         ''' Test sending/receiving huge (16MB) message. '''
00204         subscribe=( 'SUBSCRIBE\n'
00205                     'id: xxx\n'
00206                     'destination:/exchange/amq.topic/test_huge_message\n'
00207                     '\n\0')
00208         self.cd.sendall(subscribe)
00209 
00210         message = 'x' * 1024*1024*16
00211 
00212         self.cd.sendall('SEND\n'
00213                         'destination:/exchange/amq.topic/test_huge_message\n'
00214                         'content-type:text/plain\n'
00215                         '\n'
00216                         '%s'
00217                         '\0' % message)
00218 
00219         resp=('MESSAGE\n'
00220             'content-type:text/plain\n'
00221             'subscription:(.*)\n'
00222             'destination:/topic/test_huge_message\n'
00223             'message-id:(.*)\n'
00224             'content-length:%i\n'
00225             '\n'
00226             '%s(.*)'
00227              % (len(message), message[:8000]) )
00228 
00229         recv = []
00230         s = 0
00231         while len(recv) < 1 or recv[-1][-1] != '\0':
00232             buf =  self.cd.recv(4096*16)
00233             s += len(buf)
00234             recv.append( buf )
00235         buf = ''.join(recv)
00236 
00237         # matching 100MB regexp is way too expensive.
00238         self.match(resp, buf[:8192])
00239         self.assertEqual(len(buf) > len(message), True)

Here is the call graph for this function:

Test sending/receiving message in packets. 

Definition at line 295 of file parsing.py.

00295 
00296     def test_message_in_packets(self):
00297         ''' Test sending/receiving message in packets. '''
00298         base_dest='topic/test_embed_nulls_message\n'
00299         dest='destination:/exchange/amq.' + base_dest
00300         resp_dest='destination:/'+ base_dest
00301         subscribe=( 'SUBSCRIBE\n'
00302                     'id:xxx\n'
00303                     +dest+
00304                     '\n\0')
00305         self.cd.sendall(subscribe)
00306 
00307         boilerplate = '0123456789'*1024 # large enough boilerplate
00308 
00309         message = boilerplate[:1024 + 512 + 256 + 32]
00310         msg_len = len(message)
00311 
00312         msg_to_send = ('SEND\n'
00313                        +dest+
00314                        'content-type:text/plain\n'
00315                        '\n'
00316                        '%s'
00317                        '\0' % (message) )
00318         packet_size = 191
00319         part_index = 0
00320         msg_to_send_len = len(msg_to_send)
00321         while part_index < msg_to_send_len:
00322             part = msg_to_send[part_index:part_index+packet_size]
00323             time.sleep(0.1)
00324             self.cd.sendall(part)
00325             part_index += packet_size
00326 
00327         headresp=('MESSAGE\n'           # 8
00328             'content-type:text/plain\n' # 24
00329             'subscription:(.*)\n'       # 14 + subscription
00330             +resp_dest+                 # 44
00331             'message-id:(.*)\n'         # 12 + message-id
00332             'content-length:%i\n'       # 16 + 4==len('1024')
00333             '\n'                        # 1
00334             '(.*)$'                     # prefix of body+null (potentially)
00335              % len(message) )
00336         headlen = 8 + 24 + 14 + (3) + 44 + 12 + (48) + 16 + (4) + 1 + (1)
00337 
00338         headbuf = self.recv_atleast(headlen)
00339         self.assertFalse(len(headbuf) == 0)
00340 
00341         (sub, msg_id, bodyprefix) = self.match(headresp, headbuf)
00342         bodyresp=( '%s\0' % message )
00343         bodylen = len(bodyresp);
00344 
00345         bodybuf = ''.join([bodyprefix,
00346                            self.recv_atleast(bodylen - len(bodyprefix))])
00347 
00348         self.assertEqual(len(bodybuf), msg_len+1,
00349             "body received not the same length as message sent")
00350         self.assertEqual(bodybuf, bodyresp,
00351             "   body ('%s')\nincorrectly returned as ('%s')"
00352             % (bodyresp, bodybuf))

Here is the call graph for this function:

Test sending/receiving message with embedded nulls. 

Definition at line 241 of file parsing.py.

00241 
00242     def test_message_with_embedded_nulls(self):
00243         ''' Test sending/receiving message with embedded nulls. '''
00244         dest='destination:/exchange/amq.topic/test_embed_nulls_message\n'
00245         resp_dest='destination:/topic/test_embed_nulls_message\n'
00246         subscribe=( 'SUBSCRIBE\n'
00247                     'id:xxx\n'
00248                     +dest+
00249                     '\n\0')
00250         self.cd.sendall(subscribe)
00251 
00252         boilerplate = '0123456789'*1024 # large enough boilerplate
00253         message = '01'
00254         oldi = 2
00255         for i in [5, 90, 256-1, 384-1, 512, 1024, 1024+256+64+32]:
00256             message = message + '\0' + boilerplate[oldi+1:i]
00257             oldi = i
00258         msg_len = len(message)
00259 
00260         self.cd.sendall('SEND\n'
00261                         +dest+
00262                         'content-type:text/plain\n'
00263                         'content-length:%i\n'
00264                         '\n'
00265                         '%s'
00266                         '\0' % (len(message), message) )
00267 
00268         headresp=('MESSAGE\n'            # 8
00269             'content-type:text/plain\n'  # 24
00270             'subscription:(.*)\n'        # 14 + subscription
00271             +resp_dest+                  # 44
00272             'message-id:(.*)\n'          # 12 + message-id
00273             'content-length:%i\n'        # 16 + 4==len('1024')
00274             '\n'                         # 1
00275             '(.*)$'                      # prefix of body+null (potentially)
00276              % len(message) )
00277         headlen = 8 + 24 + 14 + (3) + 44 + 12 + (48) + 16 + (4) + 1 + (1)
00278 
00279         headbuf = self.recv_atleast(headlen)
00280         self.assertFalse(len(headbuf) == 0)
00281 
00282         (sub, msg_id, bodyprefix) = self.match(headresp, headbuf)
00283         bodyresp=( '%s\0' % message )
00284         bodylen = len(bodyresp);
00285 
00286         bodybuf = ''.join([bodyprefix,
00287                            self.recv_atleast(bodylen - len(bodyprefix))])
00288 
00289         self.assertEqual(len(bodybuf), msg_len+1,
00290             "body received not the same length as message sent")
00291         self.assertEqual(bodybuf, bodyresp,
00292             "   body (...'%s')\nincorrectly returned as (...'%s')"
00293             % (bodyresp[-10:], bodybuf[-10:]))

Here is the call graph for this function:

Definition at line 75 of file parsing.py.

00075 
00076     def test_newline_after_nul(self):
00077         self.cd.sendall('\n'
00078                         'SUBSCRIBE\n'
00079                         'destination:/exchange/amq.fanout\n'
00080                         '\n\x00\n'
00081                         'SEND\n'
00082                         'content-type:text/plain\n'
00083                         'destination:/exchange/amq.fanout\n\n'
00084                         'hello\n\x00\n')
00085         resp = ('MESSAGE\n'
00086                 'content-type:text/plain\n'
00087                 'destination:/exchange/amq.fanout\n'
00088                 'message-id:Q_/exchange/amq.fanout@@session-(.*)\n'
00089                 'content-length:6\n'
00090                 '\n'
00091                 'hello\n\0')
00092         self.match(resp, self.cd.recv(4096))

Here is the call graph for this function:

Definition at line 130 of file parsing.py.

00130 
00131     def test_newline_after_nul_and_leading_nul(self):
00132         self.cd.sendall('\n'
00133                         '\x00SUBSCRIBE\n'
00134                         'destination:/exchange/amq.fanout\n'
00135                         '\n\x00\n'
00136                         '\x00SEND\n'
00137                         'destination:/exchange/amq.fanout\n'
00138                         'content-type:text/plain\n'
00139                         '\nhello\n\x00\n')
00140         resp = ('MESSAGE\n'
00141                 'content-type:text/plain\n'
00142                 'destination:/exchange/amq.fanout\n'
00143                 'message-id:Q_/exchange/amq.fanout@@session-(.*)\n'
00144                 'content-length:6\n'
00145                 '\n'
00146                 'hello\n\0')
00147         self.match(resp, self.cd.recv(4096))

Here is the call graph for this function:

Definition at line 94 of file parsing.py.

00094 
00095     def test_send_without_content_type(self):
00096         self.cd.sendall('\n'
00097                         'SUBSCRIBE\n'
00098                         'destination:/exchange/amq.fanout\n'
00099                         '\n\x00\n'
00100                         'SEND\n'
00101                         'destination:/exchange/amq.fanout\n\n'
00102                         'hello\n\x00')
00103         resp = ('MESSAGE\n'
00104                 'destination:/exchange/amq.fanout\n'
00105                 'message-id:Q_/exchange/amq.fanout@@session-(.*)\n'
00106                 'content-length:6\n'
00107                 '\n'
00108                 'hello\n\0')
00109         self.match(resp, self.cd.recv(4096))

Here is the call graph for this function:

Definition at line 111 of file parsing.py.

00111 
00112     def test_send_without_content_type_binary(self):
00113         msg = u'\u0ca0\ufffd\x00\n\x01hello\x00'.encode('utf-8')
00114         self.cd.sendall('\n'
00115                         'SUBSCRIBE\n'
00116                         'destination:/exchange/amq.fanout\n'
00117                         '\n\x00\n'
00118                         'SEND\n'
00119                         'destination:/exchange/amq.fanout\n'
00120                         'content-length:'+str(len(msg))+'\n\n'
00121                         + msg + '\x00')
00122         resp = ('MESSAGE\n'
00123                 'destination:/exchange/amq.fanout\n'
00124                 'message-id:Q_/exchange/amq.fanout@@session-(.*)\n'
00125                 'content-length:'+str(len(msg))+'\n'
00126                 '\n'
00127                 + msg + '\0')
00128         self.match(resp, self.cd.recv(4096))

Here is the call graph for this function:


Member Data Documentation

string parsing.TestParsing.host = '127.0.0.1' [static]

Definition at line 49 of file parsing.py.

int parsing.TestParsing.port = 61613 [static]

Definition at line 50 of file parsing.py.


The documentation for this class was generated from the following file: