You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2018/05/19 20:12:42 UTC

[1/2] qpid-broker-j git commit: NO-JIRA: [Broker-J] Add diagnostic method to write bytes as od(1) does. Useful for analysing AMQP 1.0 buffers with Wireshark which imports that format

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 277e172e0 -> 711e00762


NO-JIRA: [Broker-J] Add diagnostic method to write bytes as od(1) does.  Useful for analysing AMQP 1.0 buffers with Wireshark which imports that format


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/7522bcf6
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/7522bcf6
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/7522bcf6

Branch: refs/heads/master
Commit: 7522bcf664d59bababaf54259ab847d5dca208db
Parents: 277e172
Author: Keith Wall <kw...@apache.org>
Authored: Sat May 19 19:37:08 2018 +0100
Committer: Keith Wall <kw...@apache.org>
Committed: Sat May 19 21:09:17 2018 +0100

----------------------------------------------------------------------
 .../org/apache/qpid/server/util/Strings.java    | 34 ++++++++++++++++++++
 .../apache/qpid/server/util/StringsTest.java    | 27 ++++++++++++++++
 2 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/7522bcf6/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java b/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
index 60edbd0..5a0953a 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
@@ -21,8 +21,11 @@
 package org.apache.qpid.server.util;
 
 import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Formatter;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -366,6 +369,37 @@ public final class Strings
         return new StringSubstitutionResolver(prefix, substitutions);
     }
 
+    /**
+     * Dumps bytes in the textual format used by UNIX od(1) in hex (x4) mode i.e. {@code od -Ax -tx1 -v}.
+     *
+     * This format is understood by Wireshark "Import from HexDump" feature so is useful for dumping buffers
+     * containing AMQP 1.0 byte-streams for diagnostic purposes.
+     *
+     * @param buf - buffer to be dumped.  Buffer will be unchanged.
+     */
+    public static String hexDump(ByteBuffer buf)
+    {
+        StringBuilder builder = new StringBuilder();
+        int count = 0;
+        for(int p = buf.position(); p < buf.position() + buf.remaining(); p++)
+        {
+            if (count % 16 == 0)
+            {
+                if (count > 0)
+                {
+                    builder.append(String.format("%n"));
+                }
+                builder.append(String.format("%07x  ", count));
+            }
+            builder.append(String.format("  %02x", buf.get(p)));
+
+            count++;
+        }
+        builder.append(String.format("%n"));
+        builder.append(String.format("%07x%n", count));
+        return builder.toString();
+    }
+
     private static class StringSubstitutionResolver implements Resolver
     {
 

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/7522bcf6/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java b/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
index 072064a..25855f9 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
@@ -20,8 +20,12 @@
  */
 package org.apache.qpid.server.util;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 
+import java.nio.ByteBuffer;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -73,4 +77,27 @@ public class StringsTest extends UnitTestBase
         assertEquals("{ \"path\" : \"C:\\\\TEMP\\\\\\\"Hello World\\\"\\foo\" }",
                             Strings.expand("{ \"path\" : \"${json:nestedTest}\\foo\" }", Strings.chain(jsonResolver, mapResolver)));
     }
+
+    @Test
+    public void hexDumpSingleByte()
+    {
+        // Known good created with echo -n A | od -Ax -tx1 -v
+        String expected = String.format("0000000    41%n" +
+                                        "0000001%n");
+
+        String actual = Strings.hexDump(ByteBuffer.wrap("A".getBytes()));
+        assertThat(actual, is(equalTo(expected)));
+    }
+
+    @Test
+    public void hexDumpManyBytes()
+    {
+        // Known good created with echo -n 12345678123456789 | od -Ax -tx1 -v
+        String expected = String.format("0000000    31  32  33  34  35  36  37  38  31  32  33  34  35  36  37  38%n" +
+                                        "0000010    39%n" +
+                                        "0000011%n");
+
+        String actual = Strings.hexDump(ByteBuffer.wrap("12345678123456789".getBytes()));
+        assertThat(actual, is(equalTo(expected)));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[2/2] qpid-broker-j git commit: QPID-8194: [Protocol Tests] [AMQP 1.0] Fix test failure

Posted by kw...@apache.org.
QPID-8194: [Protocol Tests] [AMQP 1.0] Fix test failure

InputHandler assumed that it was safe to mutate the bytes received from the wire after decoding the performatives.  This is incorrect - the payload of payload carrying frames will be corrupted.
The issue happened to appear on Windows simply owing to the relative interleving of reads/writes between the peers.


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/711e0076
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/711e0076
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/711e0076

Branch: refs/heads/master
Commit: 711e00762b3e634ada35a8a4abf9ee0e1f800a82
Parents: 7522bcf
Author: Keith Wall <kw...@apache.org>
Authored: Sat May 19 19:39:54 2018 +0100
Committer: Keith Wall <kw...@apache.org>
Committed: Sat May 19 21:10:28 2018 +0100

----------------------------------------------------------------------
 .../qpid/tests/protocol/v1_0/messaging/TransferTest.java       | 3 ---
 .../main/java/org/apache/qpid/tests/protocol/InputHandler.java | 6 ------
 2 files changed, 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/711e0076/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/messaging/TransferTest.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/messaging/TransferTest.java b/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/messaging/TransferTest.java
index 0c34381..7d1b1b6 100644
--- a/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/messaging/TransferTest.java
+++ b/systests/protocol-tests-amqp-1-0/src/test/java/org/apache/qpid/tests/protocol/v1_0/messaging/TransferTest.java
@@ -982,8 +982,6 @@ public class TransferTest extends BrokerAdminUsingTestBase
     @SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
     public void receiveMultipleDeliveries() throws Exception
     {
-        assumeFalse("QPID-8194: Tests fail whilst decoding message (uninvestigated)", SystemUtils.isWindows());
-
         int numberOfMessages = 4;
         for (int i = 0; i < numberOfMessages; i++)
         {
@@ -1046,7 +1044,6 @@ public class TransferTest extends BrokerAdminUsingTestBase
     @SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
     public void receiveMixtureOfTransactionalAndNonTransactionalDeliveries() throws Exception
     {
-        assumeFalse("QPID-8194: Tests fail whilst decoding message (uninvestigated)", SystemUtils.isWindows());
         int numberOfMessages = 4;
         for (int i = 0; i < numberOfMessages; i++)
         {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/711e0076/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/InputHandler.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/InputHandler.java b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/InputHandler.java
index 2d5fb45..5a1de51 100644
--- a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/InputHandler.java
+++ b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/InputHandler.java
@@ -70,12 +70,6 @@ public class InputHandler extends ChannelInboundHandlerAdapter
 
         LOGGER.debug("After parsing, {} byte(s) remained", _inputBuffer.remaining());
 
-        if (_inputBuffer.hasRemaining())
-        {
-            _inputBuffer.compact();
-            _inputBuffer.flip();
-        }
-
         ReferenceCountUtil.release(msg);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org