From 7a012008b7fff5de1a7f0d9bf96fc0c0b16a572d Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Tue, 9 Aug 2016 21:41:48 +0100 Subject: [PATCH] ARTEMIS-447: add name and version to properties in amqp open frame --- .../context/AbstractConnectionContext.java | 6 ++++++ .../tests/integration/proton/ProtonTest.java | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java index 5b5bd00c6b..b1c8bc72a5 100644 --- a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java +++ b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/AbstractConnectionContext.java @@ -16,6 +16,7 @@ */ package org.proton.plug.context; +import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -24,6 +25,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import io.netty.buffer.ByteBuf; +import org.apache.activemq.artemis.utils.VersionLoader; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.engine.Connection; import org.apache.qpid.proton.engine.Delivery; @@ -54,6 +56,7 @@ public abstract class AbstractConnectionContext extends ProtonInitializable impl protected AMQPConnectionCallback connectionCallback; private final String containerId; + private final Map connectionProperties = new HashMap<>(); private final ScheduledExecutorService scheduledPool; private final Map sessions = new ConcurrentHashMap<>(); @@ -73,6 +76,8 @@ public abstract class AbstractConnectionContext extends ProtonInitializable impl ScheduledExecutorService scheduledPool) { this.connectionCallback = connectionCallback; this.containerId = (containerId != null) ? containerId : UUID.randomUUID().toString(); + connectionProperties.put(Symbol.valueOf("product"), "apache-activemq-artemis"); + connectionProperties.put(Symbol.valueOf("version"), VersionLoader.getVersion().getFullVersion()); this.scheduledPool = scheduledPool; connectionCallback.setConnection(this); this.handler = ProtonHandler.Factory.create(dispatchExecutor); @@ -196,6 +201,7 @@ public abstract class AbstractConnectionContext extends ProtonInitializable impl synchronized (getLock()) { connection.setContext(AbstractConnectionContext.this); connection.setContainer(containerId); + connection.setProperties(connectionProperties); connection.open(); } initialise(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java index cd37bdaa50..aac15991db 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java @@ -59,6 +59,7 @@ import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.utils.ByteUtil; +import org.apache.activemq.artemis.utils.VersionLoader; import org.apache.activemq.transport.amqp.client.AmqpClient; import org.apache.activemq.transport.amqp.client.AmqpConnection; import org.apache.activemq.transport.amqp.client.AmqpMessage; @@ -66,6 +67,7 @@ import org.apache.activemq.transport.amqp.client.AmqpReceiver; import org.apache.activemq.transport.amqp.client.AmqpSender; import org.apache.activemq.transport.amqp.client.AmqpSession; import org.apache.qpid.jms.JmsConnectionFactory; +import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.AmqpValue; import org.apache.qpid.proton.amqp.messaging.Properties; import org.apache.qpid.proton.message.ProtonJMessage; @@ -210,6 +212,25 @@ public class ProtonTest extends ActiveMQTestBase { } } + @Test + public void testBrokerConnectionProperties() throws Exception { + if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol + + AmqpClient client = new AmqpClient(new URI(tcpAmqpConnectionUri), userName, password); + AmqpConnection amqpConnection = client.connect(); + try { + Map properties = amqpConnection.getEndpoint().getRemoteProperties(); + assertTrue(properties != null); + if (properties != null) { + assertTrue("apache-activemq-artemis".equals(properties.get(Symbol.valueOf("product")))); + assertTrue(VersionLoader.getVersion().getFullVersion().equals(properties.get(Symbol.valueOf("version")))); + } + } + finally { + amqpConnection.close(); + } + } + @Test public void testCreditsAreAllocatedOnlyOnceOnLinkCreate() throws Exception { if (protocol != 0 && protocol != 3) return; // Only run this test for AMQP protocol