propertiesPreserved(true, true);
}
private void propertiesPreserved(final boolean persistent, final boolean messageIDInHeader) throws Exception
{
JMSBridgeImpl bridge = null;
Connection connSource = null;
Connection connTarget = null;
try
{
final int NUM_MESSAGES = 10;
bridge = new JMSBridgeImpl(cff0,
cff1,
sourceQueueFactory,
targetQueueFactory,
null,
null,
null,
null,
null,
5000,
10,
QualityOfServiceMode.AT_MOST_ONCE,
1,
-1,
null,
null,
messageIDInHeader);
bridge.setTransactionManager(newTransactionManager());
bridge.start();
connSource = cf0.createConnection();
connTarget = cf1.createConnection();
JMSBridgeTest.log.trace("Sending " + NUM_MESSAGES + " messages");
Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessTarget.createConsumer(targetQueue);
connTarget.start();
MessageProducer prod = sessSource.createProducer(sourceQueue);
prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
TextMessage tm = sessSource.createTextMessage("blahmessage");
prod.setPriority(7);
prod.setTimeToLive(1 * 60 * 60 * 1000);
prod.send(tm);
long expiration = tm.getJMSExpiration();
Assert.assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
tm.getJMSDeliveryMode());
tm = (TextMessage)cons.receive(1000);
Assert.assertNotNull(tm);
Assert.assertEquals("blahmessage", tm.getText());
Assert.assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
tm.getJMSDeliveryMode());
Assert.assertEquals(7, tm.getJMSPriority());
Assert.assertTrue(Math.abs(expiration - tm.getJMSExpiration()) < 100);
Message m = cons.receive(5000);
Assert.assertNull(m);
// Now do one with expiration = 0
tm = sessSource.createTextMessage("blahmessage2");
prod.setPriority(7);
prod.setTimeToLive(0);
prod.send(tm);
Assert.assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
tm.getJMSDeliveryMode());
tm = (TextMessage)cons.receive(1000);
Assert.assertNotNull(tm);
Assert.assertEquals("blahmessage2", tm.getText());
Assert.assertEquals(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT,
tm.getJMSDeliveryMode());
Assert.assertEquals(7, tm.getJMSPriority());
Assert.assertEquals(0, tm.getJMSExpiration());
m = cons.receive(5000);
Assert.assertNull(m);
tm = sessSource.createTextMessage("blahmessage3");
final boolean myBool = false;
final byte myByte = (byte)23;
final double myDouble = 17625765d;
final float myFloat = 87127.23f;
final int myInt = 123;
final long myLong = 81728712;
final short myShort = (short)88;
final String myString = "ojweodewj";
final String myJMSX = "aardvark";
tm.setBooleanProperty("mybool", myBool);
tm.setByteProperty("mybyte", myByte);
tm.setDoubleProperty("mydouble", myDouble);
tm.setFloatProperty("myfloat", myFloat);
tm.setIntProperty("myint", myInt);
tm.setLongProperty("mylong", myLong);
tm.setShortProperty("myshort", myShort);
tm.setStringProperty("mystring", myString);
tm.setStringProperty("JMSXMyNaughtyJMSXProperty", myJMSX);
prod.send(tm);
tm = (TextMessage)cons.receive(5000);
Assert.assertNotNull(tm);
Assert.assertEquals("blahmessage3", tm.getText());
Assert.assertEquals(myBool, tm.getBooleanProperty("mybool"));
Assert.assertEquals(myByte, tm.getByteProperty("mybyte"));
Assert.assertEquals(myDouble, tm.getDoubleProperty("mydouble"));
Assert.assertEquals(myFloat, tm.getFloatProperty("myfloat"));
Assert.assertEquals(myInt, tm.getIntProperty("myint"));
Assert.assertEquals(myLong, tm.getLongProperty("mylong"));
Assert.assertEquals(myShort, tm.getShortProperty("myshort"));
Assert.assertEquals(myString, tm.getStringProperty("mystring"));
Assert.assertEquals(myJMSX, tm.getStringProperty("JMSXMyNaughtyJMSXProperty"));
m = cons.receive(5000);
}
finally
{
if (bridge != null)
{
bridge.stop();
}
if (connSource != null)
{
connSource.close();