log.info("urec2:" + urec_2.getPayload()); log.info("urec1:" + urec_1.getPayload());
   public void testCopyAfterReceive() throws Exception   {      if (ServerManagement.isRemote())      {         return;      }            Connection conn = null;            try      {         conn = cf.createConnection();                  conn.start();                  Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);                  MessageProducer prod = sess.createProducer(queue);                  MessageConsumer cons = sess.createConsumer(queue);                  MapMessage msent = sess.createMapMessage();         msent.setString("map_entry", "map_value");                  msent.setStringProperty("property_entry", "property_value");                  prod.send(msent);                  MapMessage mrec = (MapMessage)cons.receive();                           //Underlying messages         JBossMessage usent_1 = ((MessageProxy)msent).getMessage();                  JBossMessage urec_1 = ((MessageProxy)mrec).getMessage();                  //The underlying message should be the same since we haven't changed it after sending or receiving         assertTrue(usent_1 == urec_1);                  //Now change a header in the received message         //The should cause the underlying message to be copied         mrec.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);                  JBossMessage usent_2 = ((MessageProxy)msent).getMessage();         JBossMessage urec_2 = ((MessageProxy)mrec).getMessage();                  assertTrue(usent_2 == usent_1);         assertFalse(urec_1 == urec_2);                           //But the properties shouldn't be copied since we didn't change them                  assertTrue(usent_2.getJMSProperties() == usent_1.getJMSProperties());         assertTrue(urec_2.getJMSProperties() == urec_1.getJMSProperties());         assertTrue(usent_1.getJMSProperties() == urec_1.getJMSProperties());                  //And the bodies shouldn't be copied since we didn't change it either         assertTrue(usent_2.getPayload() == usent_1.getPayload());         assertTrue(urec_2.getPayload() == urec_1.getPayload());         assertTrue(usent_1.getPayload() == urec_1.getPayload());                  //Now we change a property         mrec.clearProperties();         mrec.setIntProperty("my_int_prop", 123);                  JBossMessage usent_3 = ((MessageProxy)msent).getMessage();         JBossMessage urec_3 = ((MessageProxy)mrec).getMessage();                           //It shouldn't cause a copy of the whole message again         assertTrue(usent_3 == usent_2);         assertTrue(urec_3 == urec_2);                  //But the properties should be copied in the received message but not the sent                  Map sentProps = usent_3.getJMSProperties();         Map recProps = urec_3.getJMSProperties();                  assertTrue (sentProps == usent_1.getJMSProperties());         assertFalse (recProps == urec_1.getJMSProperties());                  //Body should be the same         assertTrue(usent_3.getPayload() == usent_1.getPayload());         assertTrue(urec_3.getPayload() == urec_1.getPayload());                  //Now we change the body         mrec.clearBody();         mrec.setString("new_map_prop", "hello");                  JBossMessage usent_4 = ((MessageProxy)msent).getMessage();         JBossMessage urec_4 = ((MessageProxy)mrec).getMessage();                  //It shouldn't cause a copy of the whole message again         assertTrue(usent_4 == usent_3);         assertTrue(urec_4 == urec_3);                  //The properties should not be copied again         assertTrue (usent_4.getJMSProperties() == sentProps);         assertTrue (urec_4.getJMSProperties() == recProps);                  //Body should be copied in the received but not the sent         assertTrue(usent_4.getPayload() == usent_1.getPayload());         assertFalse(urec_4.getPayload() == urec_1.getPayload());                             }      finally      {               if (conn != null)         {            conn.close();         }      }         }