diff --git a/code/pymqi/__init__.py b/code/pymqi/__init__.py index fe33a10bea010a6fc5b8dbc692dc92700298db23_Y29kZS9weW1xaS9fX2luaXRfXy5weQ==..41a73ddd320988741325b7fdff1c4fd94186f805_Y29kZS9weW1xaS9fX2luaXRfXy5weQ== 100644 --- a/code/pymqi/__init__.py +++ b/code/pymqi/__init__.py @@ -1729,6 +1729,10 @@ (rv[-1] == CMQC.MQRC_TRUNCATED_MSG_FAILED and maxLength is not None) or # Other errors (rv[-1] != CMQC.MQRC_TRUNCATED_MSG_FAILED)): + if rv[-2] == CMQC.MQCC_WARNING: + m_desc.unpack(rv[1]) + get_opts.unpack(rv[2]) + raise MQMIError(rv[-2], rv[-1], message=rv[0], original_length=rv[-3]) # Message truncated, but we know its size. Do another MQGET @@ -1737,6 +1741,9 @@ if rv[-2]: raise MQMIError(rv[-2], rv[-1]) + m_desc.unpack(rv[1]) + get_opts.unpack(rv[2]) + return rv[0] def get_no_jms(self, max_length=None, *args): diff --git a/code/tests/test_base_api.py b/code/tests/test_base_api.py index fe33a10bea010a6fc5b8dbc692dc92700298db23_Y29kZS90ZXN0cy90ZXN0X2Jhc2VfYXBpLnB5..41a73ddd320988741325b7fdff1c4fd94186f805_Y29kZS90ZXN0cy90ZXN0X2Jhc2VfYXBpLnB5 100644 --- a/code/tests/test_base_api.py +++ b/code/tests/test_base_api.py @@ -51,8 +51,6 @@ def test_get_nontruncated(self): """Test nontruncated without buffer.""" - md_put = self._put_message() - gmo = pymqi.GMO() - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID + self._put_message() md_get = pymqi.MD() @@ -57,10 +55,8 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - - message = self.queue.get(None, md_get, gmo) + message = self.queue.get(None, md_get) self.assertEqual(self.message, message) def test_get_nontruncated_0(self): """Test nontruncated with zerro buffer length.""" @@ -62,10 +58,8 @@ self.assertEqual(self.message, message) def test_get_nontruncated_0(self): """Test nontruncated with zerro buffer length.""" - md_put = self._put_message() - gmo = pymqi.GMO() - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID + self._put_message() md_get = pymqi.MD() @@ -70,5 +64,3 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - try: @@ -74,5 +66,5 @@ try: - self.queue.get(0, md_get, gmo) + self.queue.get(0, md_get) except pymqi.MQMIError as ex: self.assertEqual(ex.reason, pymqi.CMQC.MQRC_TRUNCATED_MSG_FAILED) self.assertEqual(ex.original_length, # pylint: disable=no-member @@ -81,7 +73,5 @@ def test_get_nontruncated_short(self): """Test nontruncated with short buffer.""" md_put = self._put_message() - gmo = pymqi.GMO() - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID md_get = pymqi.MD() @@ -86,5 +76,3 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - try: @@ -90,5 +78,5 @@ try: - self.queue.get(self.buffer_length, md_get, gmo) + self.queue.get(self.buffer_length, md_get) except pymqi.MQMIError as ex: self.assertEqual(ex.reason, pymqi.CMQC.MQRC_TRUNCATED_MSG_FAILED) self.assertEqual(ex.original_length, # pylint: disable=no-member @@ -97,7 +85,5 @@ def test_get_nontruncated_enough(self): """Test nontruncated with big enough buffer.""" md_put = self._put_message() - gmo = pymqi.GMO() - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID md_get = pymqi.MD() @@ -102,10 +88,8 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - - message = self.queue.get(len(self.message), md_get, gmo) + message = self.queue.get(len(self.message), md_get) self.assertEqual(self.message, message) def test_get_truncated(self): """Test truncated without buffer.""" @@ -107,8 +91,8 @@ self.assertEqual(self.message, message) def test_get_truncated(self): """Test truncated without buffer.""" - md_put = self._put_message() + self._put_message() gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG @@ -113,5 +97,4 @@ gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID md_get = pymqi.MD() @@ -116,7 +99,5 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - try: self.queue.get(0, md_get, gmo) except pymqi.MQMIError as ex: @@ -127,6 +108,6 @@ def test_get_truncated_0(self): """Test truncated with zero buffer length.""" - md_put = self._put_message() + self._put_message() gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG @@ -131,5 +112,4 @@ gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID md_get = pymqi.MD() @@ -134,7 +114,5 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - try: self.queue.get(0, md_get, gmo) except pymqi.MQMIError as ex: @@ -145,6 +123,6 @@ def test_get_truncated_short(self): """Test truncated with short buffer.""" - md_put = self._put_message() + self._put_message() gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG @@ -149,5 +127,4 @@ gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID md_get = pymqi.MD() @@ -152,7 +129,5 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - try: self.queue.get(self.buffer_length, md_get, gmo) except pymqi.MQMIError as ex: @@ -164,6 +139,6 @@ def test_get_truncated_enough(self): """Test truncated with big buffer.""" - md_put = self._put_message() + self._put_message() gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG @@ -168,5 +143,4 @@ gmo = pymqi.GMO() gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG - gmo.MatchOptions = pymqi.CMQC.MQMO_MATCH_MSG_ID md_get = pymqi.MD() @@ -171,8 +145,6 @@ md_get = pymqi.MD() - md_get.MsgId = md_put.MsgId - message = self.queue.get(len(self.message), md_get, gmo) self.assertEqual(self.message, message) @@ -175,7 +147,36 @@ message = self.queue.get(len(self.message), md_get, gmo) self.assertEqual(self.message, message) + def test_get_nontruncated_big_msg(self): + """Test get nontruncated big message""" + md_put = pymqi.MD() + self.queue.put(bytes(4097), md_put) + + md_get = pymqi.MD() + message = self.queue.get(None, md_get) + + self.assertEqual(len(message), 4097) + self.assertEqual(md_put.PutDate, md_get.PutDate) + + def test_get_truncated_big_msg(self): + """Test get nontruncated big message""" + md_put = pymqi.MD() + self.queue.put(bytes(4097), md_put) + + gmo = pymqi.GMO() + gmo.Options = pymqi.CMQC.MQGMO_ACCEPT_TRUNCATED_MSG + + md_get = pymqi.MD() + try: + message = self.queue.get(None, md_get, gmo) + except pymqi.MQMIError as ex: + self.assertEqual(ex.reason, pymqi.CMQC.MQRC_TRUNCATED_MSG_ACCEPTED) + self.assertEqual(ex.original_length, # pylint: disable=no-member + 4097) + self.assertEqual(len(ex.message), 0) + self.assertEqual(md_put.PutDate, md_get.PutDate) + def test_put_string(self): md = pymqi.MD() # file coding defined (utf-8)