Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D02FA200B7C for ; Thu, 8 Sep 2016 22:20:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CECB0160ABD; Thu, 8 Sep 2016 20:20:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EBC3E160AAD for ; Thu, 8 Sep 2016 22:19:59 +0200 (CEST) Received: (qmail 44222 invoked by uid 500); 8 Sep 2016 20:19:58 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 44188 invoked by uid 99); 8 Sep 2016 20:19:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Sep 2016 20:19:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B15B5DFBA3; Thu, 8 Sep 2016 20:19:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tabish@apache.org To: commits@activemq.apache.org Message-Id: <853dd0b3b1fa44d28c701fc2a0d1d7b7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: Allow the AMQP test client to also be configure to trace frames Date: Thu, 8 Sep 2016 20:19:54 +0000 (UTC) archived-at: Thu, 08 Sep 2016 20:20:01 -0000 Repository: activemq Updated Branches: refs/heads/master a03865560 -> 84cd81550 Allow the AMQP test client to also be configure to trace frames The test client can allow for quick tracing of the frame traffic via a call to setTraceFrames on the client or connection instance before connection to the remote. This allows for tests to easily switch on / off tracing. The log4j.properties is also updated to output frame tracing with the URI option is put on the AMQP transport or the client value is enabled. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/84cd8155 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/84cd8155 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/84cd8155 Branch: refs/heads/master Commit: 84cd815500bb486d2ab3d8724a76f0ac43dc3bf4 Parents: a038655 Author: Timothy Bish Authored: Thu Sep 8 16:19:37 2016 -0400 Committer: Timothy Bish Committed: Thu Sep 8 16:19:37 2016 -0400 ---------------------------------------------------------------------- .../transport/amqp/client/AmqpClient.java | 22 +++++++++++++- .../transport/amqp/client/AmqpConnection.java | 32 +++++++++++++++++++- .../amqp/interop/AmqpAnonymousSenderTest.java | 2 ++ .../src/test/resources/log4j.properties | 3 +- 4 files changed, 56 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/84cd8155/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpClient.java ---------------------------------------------------------------------- diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpClient.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpClient.java index 78b1aa0..8c794ea 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpClient.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpClient.java @@ -21,8 +21,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.apache.activemq.transport.amqp.client.transport.NettyTransportFactory; import org.apache.activemq.transport.amqp.client.transport.NettyTransport; +import org.apache.activemq.transport.amqp.client.transport.NettyTransportFactory; import org.apache.qpid.proton.amqp.Symbol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +40,7 @@ public class AmqpClient { private final URI remoteURI; private String authzid; private String mechanismRestriction; + private boolean traceFrames; private AmqpValidator stateInspector = new AmqpValidator(); private List offeredCapabilities = Collections.emptyList(); @@ -103,6 +104,7 @@ public class AmqpClient { connection.setOfferedCapabilities(getOfferedCapabilities()); connection.setOfferedProperties(getOfferedProperties()); connection.setStateInspector(getStateInspector()); + connection.setTraceFrames(isTraceFrames()); return connection; } @@ -218,6 +220,24 @@ public class AmqpClient { this.stateInspector = stateInspector; } + /** + * @return the traceFrames setting for the client, true indicates frame tracing is on. + */ + public boolean isTraceFrames() { + return traceFrames; + } + + /** + * Controls whether connections created from this client object will log AMQP + * frames to a trace level logger or not. + * + * @param traceFrames + * configure the trace frames option for the client created connections. + */ + public void setTraceFrames(boolean traceFrames) { + this.traceFrames = traceFrames; + } + @Override public String toString() { return "AmqpClient: " + getRemoteURI().getHost() + ":" + getRemoteURI().getPort(); http://git-wip-us.apache.org/repos/asf/activemq/blob/84cd8155/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java ---------------------------------------------------------------------- diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java index 85a1d22..1c795a8 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java @@ -1,4 +1,4 @@ -/** +/* * 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. @@ -49,6 +49,9 @@ import org.apache.qpid.proton.engine.Event.Type; import org.apache.qpid.proton.engine.Sasl; import org.apache.qpid.proton.engine.Transport; import org.apache.qpid.proton.engine.impl.CollectorImpl; +import org.apache.qpid.proton.engine.impl.ProtocolTracer; +import org.apache.qpid.proton.engine.impl.TransportImpl; +import org.apache.qpid.proton.framing.TransportFrame; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,6 +62,7 @@ import io.netty.util.ReferenceCountUtil; public class AmqpConnection extends AmqpAbstractResource implements NettyTransportListener { private static final Logger LOG = LoggerFactory.getLogger(AmqpConnection.class); + private static final Logger TRACE_FRAMES = LoggerFactory.getLogger(AmqpConnection.class.getPackage().getName() + ".FRAMES"); private static final NoOpAsyncResult NOOP_REQUEST = new NoOpAsyncResult(); @@ -101,6 +105,7 @@ public class AmqpConnection extends AmqpAbstractResource implements private long connectTimeout = DEFAULT_CONNECT_TIMEOUT; private long closeTimeout = DEFAULT_CLOSE_TIMEOUT; private long drainTimeout = DEFAULT_DRAIN_TIMEOUT; + private boolean trace; public AmqpConnection(org.apache.activemq.transport.amqp.client.transport.NettyTransport transport, String username, String password) { setEndpoint(Connection.Factory.create()); @@ -154,6 +159,7 @@ public class AmqpConnection extends AmqpAbstractResource implements sasl.client(); } authenticator = new SaslAuthenticator(sasl, username, password, authzid, mechanismRestriction); + updateTracer(); open(future); pumpToProtonTransport(future); @@ -434,6 +440,14 @@ public class AmqpConnection extends AmqpAbstractResource implements return mechanismRestriction; } + public boolean isTraceFrames() { + return trace; + } + + public void setTraceFrames(boolean trace) { + this.trace = trace; + } + //----- Internal getters used from the child AmqpResource classes --------// ScheduledExecutorService getScheduler() { @@ -698,6 +712,22 @@ public class AmqpConnection extends AmqpAbstractResource implements return containerId; } + private void updateTracer() { + if (isTraceFrames()) { + ((TransportImpl) protonTransport).setProtocolTracer(new ProtocolTracer() { + @Override + public void receivedFrame(TransportFrame transportFrame) { + TRACE_FRAMES.trace("{} | RECV: {}", getRemoteURI(), transportFrame.getBody()); + } + + @Override + public void sentFrame(TransportFrame transportFrame) { + TRACE_FRAMES.trace("{} | SENT: {}", this, transportFrame.getBody()); + } + }); + } + } + @Override public String toString() { return "AmqpConnection { " + connectionId + " }"; http://git-wip-us.apache.org/repos/asf/activemq/blob/84cd8155/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpAnonymousSenderTest.java ---------------------------------------------------------------------- diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpAnonymousSenderTest.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpAnonymousSenderTest.java index f7c4356..efba381 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpAnonymousSenderTest.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpAnonymousSenderTest.java @@ -39,6 +39,8 @@ public class AmqpAnonymousSenderTest extends AmqpClientTestSupport { public void testSendMessageOnAnonymousRelayLinkUsingMessageTo() throws Exception { AmqpClient client = createAmqpClient(); + client.setTraceFrames(false); + AmqpConnection connection = client.connect(); AmqpSession session = connection.createSession(); http://git-wip-us.apache.org/repos/asf/activemq/blob/84cd8155/activemq-amqp/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/activemq-amqp/src/test/resources/log4j.properties b/activemq-amqp/src/test/resources/log4j.properties index d25017d..64d4fb0 100755 --- a/activemq-amqp/src/test/resources/log4j.properties +++ b/activemq-amqp/src/test/resources/log4j.properties @@ -21,7 +21,8 @@ log4j.rootLogger=WARN, console, file log4j.logger.org.apache.activemq=INFO log4j.logger.org.apache.activemq.transport.amqp=DEBUG -log4j.logger.org.apache.activemq.transport.amqp.FRAMES=INFO +log4j.logger.org.apache.activemq.transport.amqp.client.FRAMES=TRACE +log4j.logger.org.apache.activemq.transport.amqp.FRAMES=TRACE log4j.logger.org.fusesource=INFO # Configure various level of detail for Qpid JMS logs.