Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed parsing of delete tap packet

We weren't taking the revid into account

Change-Id: Ice82717ada14c7e85b6191470d7174189f878073
Reviewed-on: http://review.couchbase.org/17640
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information...
commit 5d84027b6025a8f4e431b42c240321346a70e13f 1 parent 40f700f
Mike Wiederhold mikewied authored
6 src/main/java/net/spy/memcached/tapmessage/ResponseMessage.java
View
@@ -100,10 +100,11 @@ public ResponseMessage(byte[] b) {
itemflags = 0;
itemexpiry = 0;
vbucketstate = 0;
+ revid = new byte[engineprivate];
+ System.arraycopy(b, 32, revid, 0, engineprivate);
key = new byte[keylength];
- System.arraycopy(b, ITEM_FLAGS_OFFSET, key, 0, keylength);
+ System.arraycopy(b, 32 + engineprivate, key, 0, keylength);
value = new byte[0];
- revid = new byte[0];
} else if (opcode.equals(TapOpcode.VBUCKETSET)) {
itemflags = 0;
itemexpiry = 0;
@@ -279,6 +280,7 @@ public ByteBuffer getBytes() {
bb.put(key);
bb.put(value);
} else if (opcode.equals(TapOpcode.DELETE)) {
+ bb.put(revid);
bb.put(key);
} else if (opcode.equals(TapOpcode.VBUCKETSET)) {
bb.putInt(vbucketstate);
82 src/test/java/net/spy/memcached/tapmessage/TapDeleteTest.java
View
@@ -0,0 +1,82 @@
+package net.spy.memcached.tapmessage;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TapDeleteTest extends ResponseMessageBaseCase {
+ @Before
+ @Override
+ public void setUp() {
+ expectedFlags = new LinkedList<TapResponseFlag>();
+ expectedFlags.add(TapResponseFlag.TAP_FLAG_NETWORK_BYTE_ORDER);
+
+ // see:
+ // raw.github.com/
+ // membase/memcached/branch-20/include/memcached/protocol_binary.h
+ // bin request header + tap delete + a key
+ ByteBuffer binReqTapMutation = ByteBuffer.allocate(24+16+1+8);
+
+ // bin request, tap mutation
+ binReqTapMutation.put(0, (byte)0x80).put(1, (byte)0x42);
+ binReqTapMutation.put(3, (byte)0x01); // key length
+ binReqTapMutation.put(5, (byte)0x06); // datatype
+ binReqTapMutation.put(11, (byte)0x0d); // body length
+ binReqTapMutation.put(25, (byte)0x04); // rev id length
+ binReqTapMutation.put(27, (byte)0x04); // TAP_FLAG_NETWORK_BYTE_ORDER; fixed
+
+ // rev id
+ binReqTapMutation.put(32, (byte)'a');
+ binReqTapMutation.put(33, (byte)'b');
+ binReqTapMutation.put(34, (byte)'c');
+ binReqTapMutation.put(35, (byte)'d');
+ // key
+ binReqTapMutation.put(36, (byte)'a');
+
+
+ responsebytes = binReqTapMutation.array();
+
+ instance = new ResponseMessage(responsebytes);
+ }
+
+ @Test
+ public void testGetEnginePrivate() {
+ long expResult = 4L;
+ long result = instance.getEnginePrivate();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testGetItemFlags() {
+ int expResult = (int)0x0000;
+ int result = instance.getItemFlags();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testGetValue() {
+ byte[] expResult = new byte[0];
+ byte[] result = instance.getValue();
+ assertArrayEquals(expResult, result);
+ }
+
+ @Test
+ public void testRevID() {
+ byte[] result = instance.getRevID();
+ assertEquals('a', result[0]);
+ assertEquals('b', result[1]);
+ assertEquals('c', result[2]);
+ assertEquals('d', result[3]);
+ }
+
+ @Test
+ public void testGetBytes() {
+ byte[] result = instance.getBytes().array();
+ assertEquals('a', result[result.length-1]);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.