You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2016/01/20 01:06:04 UTC

[1/2] accumulo git commit: ACCUMULO-4098 Fixed bug with ByteBuffers thats do not start at 0

Repository: accumulo
Updated Branches:
  refs/heads/1.7 a4a1d6eb3 -> c9c60d37c


ACCUMULO-4098 Fixed bug with ByteBuffers thats do not start at 0


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/a2c2d38a
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/a2c2d38a
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/a2c2d38a

Branch: refs/heads/1.7
Commit: a2c2d38aa248056c1cf592e8a2a0ada17eb518e2
Parents: 8c6866e
Author: Keith Turner <kt...@apache.org>
Authored: Tue Jan 19 15:55:34 2016 -0500
Committer: Keith Turner <kt...@apache.org>
Committed: Tue Jan 19 15:55:34 2016 -0500

----------------------------------------------------------------------
 .../core/util/UnsynchronizedBuffer.java         |  4 +-
 .../core/util/UnsynchronizedBufferTest.java     | 56 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/a2c2d38a/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java b/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
index 6947d64..f353613 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
@@ -118,8 +118,8 @@ public class UnsynchronizedBuffer {
     }
 
     public Reader(ByteBuffer buffer) {
-      if (buffer.hasArray()) {
-        offset = buffer.arrayOffset();
+      if (buffer.hasArray() && buffer.array().length == buffer.arrayOffset() + buffer.limit()) {
+        offset = buffer.arrayOffset() + buffer.position();
         data = buffer.array();
       } else {
         data = new byte[buffer.remaining()];

http://git-wip-us.apache.org/repos/asf/accumulo/blob/a2c2d38a/core/src/test/java/org/apache/accumulo/core/util/UnsynchronizedBufferTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/UnsynchronizedBufferTest.java b/core/src/test/java/org/apache/accumulo/core/util/UnsynchronizedBufferTest.java
new file mode 100644
index 0000000..6416219
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/UnsynchronizedBufferTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.accumulo.core.util;
+
+import java.nio.ByteBuffer;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.base.Charsets;
+
+public class UnsynchronizedBufferTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testByteBufferConstructor() {
+    byte[] test = "0123456789".getBytes(Charsets.UTF_8);
+
+    ByteBuffer bb1 = ByteBuffer.wrap(test);
+    UnsynchronizedBuffer.Reader ub = new UnsynchronizedBuffer.Reader(bb1);
+    byte[] buf = new byte[10];
+    ub.readBytes(buf);
+    Assert.assertEquals("0123456789", new String(buf, Charsets.UTF_8));
+
+    ByteBuffer bb2 = ByteBuffer.wrap(test, 3, 5);
+
+    ub = new UnsynchronizedBuffer.Reader(bb2);
+    buf = new byte[5];
+    // should read data from offset 3 where the byte buffer starts
+    ub.readBytes(buf);
+    Assert.assertEquals("34567", new String(buf, Charsets.UTF_8));
+
+    buf = new byte[6];
+    // the byte buffer has the extra byte, but should not be able to read it...
+    thrown.expect(ArrayIndexOutOfBoundsException.class);
+    ub.readBytes(buf);
+  }
+}


[2/2] accumulo git commit: Merge branch '1.6' into 1.7

Posted by kt...@apache.org.
Merge branch '1.6' into 1.7


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c9c60d37
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c9c60d37
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c9c60d37

Branch: refs/heads/1.7
Commit: c9c60d37c4db4362d5af5e3a22eb3f78600bafec
Parents: a4a1d6e a2c2d38
Author: Keith Turner <kt...@apache.org>
Authored: Tue Jan 19 15:59:13 2016 -0500
Committer: Keith Turner <kt...@apache.org>
Committed: Tue Jan 19 15:59:13 2016 -0500

----------------------------------------------------------------------
 .../core/util/UnsynchronizedBuffer.java         |  4 +-
 .../core/util/UnsynchronizedBufferTest.java     | 56 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9c60d37/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
index e07ee10,f353613..46167ab
--- a/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/UnsynchronizedBuffer.java
@@@ -181,15 -117,9 +181,15 @@@ public class UnsynchronizedBuffer 
        this.data = b;
      }
  
 +    /**
 +     * Creates a new reader.
 +     *
 +     * @param buffer
 +     *          byte buffer containing bytes to read
 +     */
      public Reader(ByteBuffer buffer) {
-       if (buffer.hasArray()) {
-         offset = buffer.arrayOffset();
+       if (buffer.hasArray() && buffer.array().length == buffer.arrayOffset() + buffer.limit()) {
+         offset = buffer.arrayOffset() + buffer.position();
          data = buffer.array();
        } else {
          data = new byte[buffer.remaining()];