diff options
| author | Robert Gemmell <robbie@apache.org> | 2011-08-08 22:54:37 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2011-08-08 22:54:37 +0000 |
| commit | 09d5704b80e7b7936ec913c107c4537faf643d73 (patch) | |
| tree | 63434cd7ccf8ac3085d7558632da65550b1a09de /qpid/java/broker/src/test | |
| parent | 2dda5290066f4e5b7ac07a80cbbe659b519a8200 (diff) | |
| download | qpid-python-09d5704b80e7b7936ec913c107c4537faf643d73.tar.gz | |
QPID-3385: assign IDs from a generator within the MultiVersionProtocolEngineFactory, which is shared across all protocol versions
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1155136 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
3 files changed, 151 insertions, 3 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java index 3af665141c..c058d0b0d8 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.server.protocol; -import java.security.Principal; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -28,6 +27,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import javax.security.auth.Subject; @@ -43,7 +43,6 @@ import org.apache.qpid.server.output.ProtocolOutputConverter; import org.apache.qpid.server.queue.QueueEntry; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal; -import org.apache.qpid.server.state.AMQState; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.transport.TestNetworkConnection; @@ -52,10 +51,11 @@ public class InternalTestProtocolSession extends AMQProtocolEngine implements Pr // ChannelID(LIST) -> LinkedList<Pair> final Map<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>> _channelDelivers; private AtomicInteger _deliveryCount = new AtomicInteger(0); + private static final AtomicLong ID_GENERATOR = new AtomicLong(0); public InternalTestProtocolSession(VirtualHost virtualHost) throws AMQException { - super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection()); + super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection(), ID_GENERATOR.getAndIncrement()); _channelDelivers = new HashMap<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>>(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java new file mode 100644 index 0000000000..9d76d5efca --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java @@ -0,0 +1,146 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.qpid.server.protocol; + +import java.nio.ByteBuffer; +import java.util.EnumSet; +import java.util.Set; + +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.qpid.protocol.ServerProtocolEngine; +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.util.TestApplicationRegistry; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.transport.TestNetworkConnection; + +public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase +{ + protected void setUp() throws Exception + { + super.setUp(); + + //the factory needs a registry instance + ApplicationRegistry.initialise(new TestApplicationRegistry(new ServerConfiguration(new XMLConfiguration()))); + } + + protected void tearDown() + { + //the factory opens a registry instance + ApplicationRegistry.remove(); + } + + private static final byte[] AMQP_0_8_HEADER = + new byte[] { (byte) 'A', + (byte) 'M', + (byte) 'Q', + (byte) 'P', + (byte) 1, + (byte) 1, + (byte) 8, + (byte) 0 + }; + + private static final byte[] AMQP_0_9_HEADER = + new byte[] { (byte) 'A', + (byte) 'M', + (byte) 'Q', + (byte) 'P', + (byte) 1, + (byte) 1, + (byte) 0, + (byte) 9 + }; + + private static final byte[] AMQP_0_9_1_HEADER = + new byte[] { (byte) 'A', + (byte) 'M', + (byte) 'Q', + (byte) 'P', + (byte) 0, + (byte) 0, + (byte) 9, + (byte) 1 + }; + + + private static final byte[] AMQP_0_10_HEADER = + new byte[] { (byte) 'A', + (byte) 'M', + (byte) 'Q', + (byte) 'P', + (byte) 1, + (byte) 1, + (byte) 0, + (byte) 10 + }; + + private byte[] getAmqpHeader(final AmqpProtocolVersion version) + { + switch(version) + { + case v0_8: + return AMQP_0_8_HEADER; + case v0_9: + return AMQP_0_9_HEADER; + case v0_9_1: + return AMQP_0_9_1_HEADER; + case v0_10: + return AMQP_0_10_HEADER; + default: + fail("unknown AMQP version, appropriate header must be added for new protocol version"); + return null; + } + } + + /** + * Test to verify that connections established using a MultiVersionProtocolEngine are assigned + * IDs from a common sequence, independent of the protocol version under use. + */ + public void testDifferentProtocolVersionsShareCommonIDNumberingSequence() + { + Set<AmqpProtocolVersion> versions = EnumSet.allOf(AmqpProtocolVersion.class); + + MultiVersionProtocolEngineFactory factory = + new MultiVersionProtocolEngineFactory("localhost", versions); + + //create a dummy to retrieve the 'current' ID number + long previousId = factory.newProtocolEngine(new TestNetworkConnection()).getConnectionId(); + + //create a protocol engine and send the AMQP header for all supported AMQP verisons, + //ensuring the ID assigned increases as expected + for(AmqpProtocolVersion version : versions) + { + long expectedID = previousId + 1; + byte[] header = getAmqpHeader(version); + assertNotNull("protocol header should not be null", header); + + ServerProtocolEngine engine = factory.newProtocolEngine(new TestNetworkConnection()); + assertEquals("ID did not increment as expected", expectedID, engine.getConnectionId()); + + //actually feed in the AMQP header for this protocol version, and ensure the ID remains consistent + engine.received(ByteBuffer.wrap(header)); + assertEquals("ID was not as expected following receipt of the AMQP version header", expectedID, engine.getConnectionId()); + + previousId = expectedID; + } + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java index 8fa820ad95..3c6857e8a9 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java @@ -27,6 +27,7 @@ import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.logging.NullRootMessageLogger; import org.apache.qpid.server.logging.actors.BrokerActor; import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.logging.actors.GenericActor; import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase; @@ -45,6 +46,7 @@ public class TestApplicationRegistry extends ApplicationRegistry public void initialise() throws Exception { CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger())); + GenericActor.setDefaultMessageLogger(new NullRootMessageLogger()); super.initialise(); } |
