예제 #1
0
    def test_no_side_effects_from_message_marshal_error(self):
        # Verify that frame buffer is empty on entry
        self.assertEqual(b'', self.connection._frame_buffer)

        # Use Basic.Public with invalid body to trigger marshalling error
        method = spec.Basic.Publish()
        properties = spec.BasicProperties()
        # Verify that marshalling of method and header won't trigger error
        frame.Method(1, method).marshal()
        frame.Header(1, body_size=10, props=properties).marshal()
        # Create bogus body that should trigger an error during marshalling
        body = [1, 2, 3, 4]
        # Verify that frame body can be created using the bogus body, but
        # that marshalling will fail
        frame.Body(1, body)
        with self.assertRaises(TypeError):
            frame.Body(1, body).marshal()

        # Now, attempt to send the method with the bogus body
        with self.assertRaises(TypeError):
            self.connection._send_method(channel_number=1,
                                         method=method,
                                         content=(properties, body))

        # Now make sure that nothing is enqueued on frame buffer
        self.assertEqual(b'', self.connection._frame_buffer)
예제 #2
0
 def test_process_with_body_frame_partial(self):
     value = frame.Header(1, 100, spec.BasicProperties)
     self.obj.process(value)
     value = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(value)
     value = frame.Body(1, 'abc123')
     self.obj.process(value)
     self.assertEqual(self.obj._body_fragments, [value.fragment])
예제 #3
0
 def test_process_with_body_frame_six_bytes(self):
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     header_frame = frame.Header(1, 10, spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, 'abc123')
     self.obj.process(body_frame)
     self.assertEqual(self.obj._seen_so_far, 6)
예제 #4
0
 def test_process_with_full_message(self):
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     header_frame = frame.Header(1, 6, spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, 'abc123')
     response = self.obj.process(body_frame)
     self.assertEqual(response, (method_frame, header_frame, 'abc123'))
예제 #5
0
 def test_process_with_body_frame_too_big(self):
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     header_frame = frame.Header(1, 6, spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, 'abcd1234')
     self.assertRaises(exceptions.BodyTooLongError, self.obj.process,
                       body_frame)
 def test_process_with_body_frame_too_big(self):
     obj = channel.ContentFrameDispatcher()
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 6, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'abcd1234')
     self.assertRaises(exceptions.BodyTooLongError, obj.process, body_frame)
예제 #7
0
 def test_ascii_body_instance(self):
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     header_frame = frame.Header(1, 11, spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, 'foo-bar-baz')
     method_frame, header_frame, body_value = self.obj.process(body_frame)
     self.assertIsInstance(body_value, str)
 def test_process_with_body_frame_six_bytes(self):
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 10, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'abc123')
     obj.process(body_frame)
     self.assertEqual(obj._seen_so_far, 6)
 def test_process_with_full_message(self):
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 6, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'abc123')
     response = obj.process(body_frame)
     self.assertEqual(response, (method_frame, header_frame, 'abc123'))
 def test_process_with_body_frame_partial(self):
     obj = channel.ContentFrameDispatcher(False)
     value = frame.Header(1, 100, spec.BasicProperties)
     obj.process(value)
     value = frame.Method(1, spec.Basic.Deliver())
     obj.process(value)
     value = frame.Body(1, 'abc123')
     obj.process(value)
     self.assertEqual(obj._body_fragments, [value.fragment])
 def test_ascii_body_instance(self):
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 11, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'foo-bar-baz')
     method_frame, header_frame, body_value = obj.process(body_frame)
     self.assertIsInstance(body_value, str)
 def test_utf8_body_instance(self):
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 14, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'utf8_value=\xe2\x9c\x93')
     method_frame, header_frame, body_value = obj.process(body_frame)
     self.assertIsInstance(body_value, unicode)
예제 #13
0
 def test_reset_header_frame(self):
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     header_frame = frame.Header(1, 10, spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, 'abc123')
     self.obj.process(body_frame)
     self.obj._reset()
     self.assertEqual(self.obj._header_frame, None)
 def test_binary_non_unicode_value(self):
     expectation =('a', 0.8)
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 20, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, marshal.dumps(expectation))
     method_frame, header_frame, body_value = obj.process(body_frame)
     self.assertEqual(marshal.loads(body_value), expectation)
 def test_utf8_body_value(self):
     expectation = u'utf8_value=✓'
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 14, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'utf8_value=\xe2\x9c\x93')
     method_frame, header_frame, body_value = obj.process(body_frame)
     self.assertEqual(body_value, expectation)
 def test_reset_method_frame(self):
     obj = channel.ContentFrameDispatcher(False)
     method_frame = frame.Method(1, spec.Basic.Deliver())
     obj.process(method_frame)
     header_frame = frame.Header(1, 10, spec.BasicProperties)
     obj.process(header_frame)
     body_frame = frame.Body(1, 'abc123')
     obj.process(body_frame)
     obj._reset()
     self.assertEqual(obj._method_frame, None)
예제 #17
0
 def test_ascii_body_value(self):
     expectation = 'foo-bar-baz'
     self.obj = channel.ContentFrameDispatcher()
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     header_frame = frame.Header(1, 11, spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, 'foo-bar-baz')
     method_frame, header_frame, body_value = self.obj.process(body_frame)
     self.assertEqual(body_value, expectation)
     self.assertIsInstance(body_value, str)
예제 #18
0
 def test_binary_non_unicode_value(self):
     expectation = ('a', 0.8)
     self.obj = channel.ContentFrameAssembler()
     method_frame = frame.Method(1, spec.Basic.Deliver())
     self.obj.process(method_frame)
     marshalled_body = marshal.dumps(expectation)
     header_frame = frame.Header(1, len(marshalled_body),
                                 spec.BasicProperties)
     self.obj.process(header_frame)
     body_frame = frame.Body(1, marshalled_body)
     method_frame, header_frame, body_value = self.obj.process(body_frame)
     self.assertEqual(marshal.loads(body_value), expectation)
예제 #19
0
 def _send_message(self, channel_number, method, content=None):
     length = len(content[1])
     self.connection.send_frame(
         frame.Method(channel_number, method).marshal())
     self.connection.send_frame(
         frame.Header(channel_number, length, content[0]))
     if content[1]:
         body_max_length = (self.connection.frame_max -
                            spec.FRAME_HEADER_SIZE - spec.FRAME_END_SIZE)
         chunks = int(math.ceil(float(length) / body_max_length))
         for chunk in xrange(0, chunks):
             start = chunk * body_max_length
             end = start + body_max_length
             if end > length:
                 end = length
             self.connection.send_frame(
                 frame.Body(channel_number, content[1][start:end]))
예제 #20
0
파일: connection.py 프로젝트: smglab/pika
    def _send_method(self, channel_number, method_frame, content=None):
        """Constructs a RPC method frame and then sends it to the broker.

        :param int channel_number: The channel number for the frame
        :param pika.object.Method method_frame: The method frame to send
        :param tuple content: If set, is a content frame, is tuple of
                              properties and body.

        """
        LOGGER.debug('Sending on channel %i: %r', channel_number, method_frame)
        self._send_frame(frame.Method(channel_number, method_frame))
        if isinstance(content, tuple):
            self._send_frame(frame.Header(channel_number,
                                          len(content[1]),
                                           content[0]))
            if content[1]:
                body_buf = simplebuffer.SimpleBuffer(content[1])
                while body_buf:
                    piece_len = min(len(body_buf), self._body_max_length)
                    piece = body_buf.read_and_consume(piece_len)
                    self._send_frame(frame.Body(channel_number, piece))
 def test_process_with_content_header(self):
     value = frame.Header(1, 100, spec.BasicProperties)
     obj = channel.ContentFrameDispatcher(False)
     obj.process(value)
     self.assertEqual(obj._header_frame, value)
예제 #22
0
 def headers_marshal_test(self):
     header = frame.Header(1, 100, spec.BasicProperties(delivery_mode=2))
     self.assertEqual(header.marshal(), self.CONTENT_HEADER)
예제 #23
0
 def test_process_with_content_header(self):
     value = frame.Header(1, 100, spec.BasicProperties)
     self.obj.process(value)
     self.assertEqual(self.obj._header_frame, value)