From 03485e0e416d74c74c305bfbcb0864628c8075fe Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Wed, 9 Nov 2011 08:59:26 +0000 Subject: QPID-3519: refactor consumer argument handling Applied patch from Oleksandr Rudyy and myself. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1199664 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/client/AMQSession.java | 20 +------- .../org/apache/qpid/client/AMQSession_0_10.java | 4 +- .../org/apache/qpid/client/AMQSession_0_8.java | 17 +------ .../apache/qpid/client/BasicMessageConsumer.java | 19 +++++++- .../qpid/client/BasicMessageConsumer_0_10.java | 4 +- .../qpid/client/BasicMessageConsumer_0_8.java | 16 ++++++- .../apache/qpid/client/AMQSession_0_10Test.java | 17 ++++--- .../java/org/apache/qpid/framing/FieldTable.java | 9 ++-- .../qpid/framing/PropertyFieldTableTest.java | 54 +++++++++++++++++----- 9 files changed, 94 insertions(+), 66 deletions(-) (limited to 'java') diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index 4c4d2c75b1..ef44221ec1 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -92,7 +92,6 @@ import org.apache.qpid.common.AMQPFilterTypes; import org.apache.qpid.filter.MessageFilter; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.framing.FieldTableFactory; import org.apache.qpid.framing.MethodRegistry; import org.apache.qpid.jms.Session; import org.apache.qpid.protocol.AMQConstant; @@ -2011,28 +2010,11 @@ public abstract class AMQSession extends Closeable implements Messa protected BasicMessageConsumer(int channelId, AMQConnection connection, AMQDestination destination, String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory, AMQSession session, AMQProtocolHandler protocolHandler, - FieldTable arguments, int prefetchHigh, int prefetchLow, + FieldTable rawSelector, int prefetchHigh, int prefetchLow, boolean exclusive, int acknowledgeMode, boolean browseOnly, boolean autoClose) throws JMSException { _channelId = channelId; @@ -160,7 +161,6 @@ public abstract class BasicMessageConsumer extends Closeable implements Messa _messageFactory = messageFactory; _session = session; _protocolHandler = protocolHandler; - _arguments = arguments; _prefetchHigh = prefetchHigh; _prefetchLow = prefetchLow; _exclusive = exclusive; @@ -196,6 +196,21 @@ public abstract class BasicMessageConsumer extends Closeable implements Messa { _acknowledgeMode = acknowledgeMode; } + + final FieldTable ft = FieldTableFactory.newFieldTable(); + // rawSelector is used by HeadersExchange and is not a JMS Selector + if (rawSelector != null) + { + ft.addAll(rawSelector); + } + + // We must always send the selector argument even if empty, so that we can tell when a selector is removed from a + // durable topic subscription that the broker arguments don't match any more. This is because it is not otherwise + // possible to determine when querying the broker whether there are no arguments or just a non-matching selector + // argument, as specifying null for the arguments when querying means they should not be checked at all + ft.put(AMQPFilterTypes.JMS_SELECTOR.getValue(), messageSelector == null ? "" : messageSelector); + + _arguments = ft; } public AMQDestination getDestination() diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java index ae2068b75b..47c20b683c 100644 --- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java @@ -72,12 +72,12 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer session, AMQProtocolHandler protocolHandler, - FieldTable arguments, int prefetchHigh, int prefetchLow, + FieldTable rawSelector, int prefetchHigh, int prefetchLow, boolean exclusive, int acknowledgeMode, boolean browseOnly, boolean autoClose) throws JMSException { super(channelId, connection, destination, messageSelector, noLocal, messageFactory, session, protocolHandler, - arguments, prefetchHigh, prefetchLow, exclusive, acknowledgeMode, browseOnly, autoClose); + rawSelector, prefetchHigh, prefetchLow, exclusive, acknowledgeMode, browseOnly, autoClose); _0_10session = (AMQSession_0_10) session; _preAcquire = evaluatePreAcquire(browseOnly, destination); diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java index cc061e35cb..cf1d7cedeb 100644 --- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java +++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java @@ -27,6 +27,7 @@ import org.apache.qpid.AMQException; import org.apache.qpid.client.failover.FailoverException; import org.apache.qpid.client.message.*; import org.apache.qpid.client.protocol.AMQProtocolHandler; +import org.apache.qpid.common.AMQPFilterTypes; import org.apache.qpid.framing.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,12 +38,23 @@ public class BasicMessageConsumer_0_8 extends BasicMessageConsumer convertToMap(final FieldTable fieldTable) diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java index bb4c9c3884..bd189feb1c 100644 --- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java +++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java @@ -20,17 +20,19 @@ */ package org.apache.qpid.framing; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + import junit.framework.Assert; import junit.framework.TestCase; -import org.apache.qpid.AMQInvalidArgumentException; import org.apache.qpid.AMQPInvalidClassException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.*; - public class PropertyFieldTableTest extends TestCase { private static final Logger _logger = LoggerFactory.getLogger(PropertyFieldTableTest.class); @@ -106,7 +108,7 @@ public class PropertyFieldTableTest extends TestCase table1.setByte("value", Byte.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - // Tets lookups we shouldn't get anything back for other gets + // Tests lookups we shouldn't get anything back for other gets // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(Byte.MAX_VALUE, (byte) table1.getByte("value")); @@ -139,7 +141,7 @@ public class PropertyFieldTableTest extends TestCase table1.setShort("value", Short.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - // Tets lookups we shouldn't get anything back for other gets + // Tests lookups we shouldn't get anything back for other gets // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); @@ -172,7 +174,7 @@ public class PropertyFieldTableTest extends TestCase table1.setChar("value", 'c'); Assert.assertTrue(table1.propertyExists("value")); - // Tets lookups we shouldn't get anything back for other gets + // Tests lookups we shouldn't get anything back for other gets // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); @@ -206,7 +208,7 @@ public class PropertyFieldTableTest extends TestCase table1.setDouble("value", Double.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - // Tets lookups we shouldn't get anything back for other gets + // Tests lookups we shouldn't get anything back for other gets // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); @@ -241,7 +243,7 @@ public class PropertyFieldTableTest extends TestCase table1.setFloat("value", Float.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - // Tets lookups we shouldn't get anything back for other gets + // Tests lookups we shouldn't get anything back for other gets // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); @@ -404,7 +406,7 @@ public class PropertyFieldTableTest extends TestCase table1.setString("value", "Hello"); Assert.assertTrue(table1.propertyExists("value")); - // Tets lookups we shouldn't get anything back for other gets + // Test lookups we shouldn't get anything back for other gets // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); @@ -569,7 +571,7 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals("Hello", table.getObject("object-string")); } - public void testwriteBuffer() throws IOException + public void testWriteBuffer() throws IOException { byte[] bytes = { 99, 98, 97, 96, 95 }; @@ -950,6 +952,36 @@ public class PropertyFieldTableTest extends TestCase } + public void testAddAll() + { + final FieldTable table1 = new FieldTable(); + table1.setInteger("int1", 1); + table1.setInteger("int2", 2); + assertEquals("Unexpected number of entries in table1", 2, table1.size()); + + final FieldTable table2 = new FieldTable(); + table2.setInteger("int3", 3); + table2.setInteger("int4", 4); + assertEquals("Unexpected number of entries in table2", 2, table2.size()); + + table1.addAll(table2); + assertEquals("Unexpected number of entries in table1 after addAll", 4, table1.size()); + assertEquals(Integer.valueOf(3), table1.getInteger("int3")); + } + + public void testAddAllWithEmptyFieldTable() + { + final FieldTable table1 = new FieldTable(); + table1.setInteger("int1", 1); + table1.setInteger("int2", 2); + assertEquals("Unexpected number of entries in table1", 2, table1.size()); + + final FieldTable emptyFieldTable = new FieldTable(); + + table1.addAll(emptyFieldTable); + assertEquals("Unexpected number of entries in table1 after addAll", 2, table1.size()); + } + private void assertBytesEqual(byte[] expected, byte[] actual) { Assert.assertEquals(expected.length, actual.length); -- cgit v1.2.1