summaryrefslogtreecommitdiff
path: root/qpid/java/common/src/test
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2014-08-16 15:21:41 +0000
committerRobert Godfrey <rgodfrey@apache.org>2014-08-16 15:21:41 +0000
commitc0e454cf882c7af8292832d6233940c56cc6a881 (patch)
tree317fcecc377ef9899cbb3760dfbf600295d6beb7 /qpid/java/common/src/test
parenta22fa634fe3a3f51d1a27078e17cba82e48fcf46 (diff)
downloadqpid-python-c0e454cf882c7af8292832d6233940c56cc6a881.tar.gz
QPID-6000 : [Java Broker] [Java Client] add the ability to configure automatic message compression
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1618375 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/test')
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/util/GZIPUtilsTest.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/util/GZIPUtilsTest.java b/qpid/java/common/src/test/java/org/apache/qpid/util/GZIPUtilsTest.java
new file mode 100644
index 0000000000..60e80da15f
--- /dev/null
+++ b/qpid/java/common/src/test/java/org/apache/qpid/util/GZIPUtilsTest.java
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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.util;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class GZIPUtilsTest extends TestCase
+{
+ public void testCompressUncompress() throws Exception
+ {
+ byte[] data = new byte[1024];
+ Arrays.fill(data, (byte)'a');
+ byte[] compressed = GZIPUtils.compressBufferToArray(ByteBuffer.wrap(data));
+ assertTrue("Compression didn't compress", compressed.length < data.length);
+ byte[] uncompressed = GZIPUtils.uncompressBufferToArray(ByteBuffer.wrap(compressed));
+ assertTrue("Compression not reversible", Arrays.equals(data,uncompressed));
+ }
+
+ public void testUncompressNonZipReturnsNull() throws Exception
+ {
+ byte[] data = new byte[1024];
+ Arrays.fill(data, (byte)'a');
+ assertNull("Non zipped data should not uncompress", GZIPUtils.uncompressBufferToArray(ByteBuffer.wrap(data)));
+ }
+
+ public void testUncompressStreamWithErrorReturnsNull() throws Exception
+ {
+ InputStream is = new InputStream()
+ {
+ @Override
+ public int read() throws IOException
+ {
+ throw new IOException();
+ }
+ };
+ assertNull("Stream error should return null", GZIPUtils.uncompressStreamToArray(is));
+ }
+
+
+ public void testUncompressNullStreamReturnsNull() throws Exception
+ {
+ assertNull("Null Stream should return null", GZIPUtils.uncompressStreamToArray(null));
+ }
+ public void testUncompressNullBufferReturnsNull() throws Exception
+ {
+ assertNull("Null buffer should return null", GZIPUtils.uncompressBufferToArray(null));
+ }
+
+ public void testCompressNullArrayReturnsNull()
+ {
+ assertNull(GZIPUtils.compressBufferToArray(null));
+ }
+
+ public void testNonHeapBuffers() throws Exception
+ {
+
+ byte[] data = new byte[1024];
+ Arrays.fill(data, (byte)'a');
+ ByteBuffer directBuffer = ByteBuffer.allocateDirect(1024);
+ directBuffer.put(data);
+ directBuffer.flip();
+
+ byte[] compressed = GZIPUtils.compressBufferToArray(directBuffer);
+
+ assertTrue("Compression didn't compress", compressed.length < data.length);
+
+ directBuffer.clear();
+ directBuffer.position(1);
+ directBuffer = directBuffer.slice();
+ directBuffer.put(compressed);
+ directBuffer.flip();
+
+ byte[] uncompressed = GZIPUtils.uncompressBufferToArray(directBuffer);
+
+ assertTrue("Compression not reversible", Arrays.equals(data,uncompressed));
+
+ }
+}