Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added all memcached error codes to spymemcached.
Previously we only checked a subset of the error codes that memcached can send back to a client. This created an issue because if a user recieves an error code that it doesn't expect it resets the connection. This commit adds all error codes. Change-Id: I9317eccd688b6fa1e7113847cd7c7ef160a6624f Reviewed-on: http://review.couchbase.org/7006 Reviewed-by: Michael Wiederhold <mike@couchbase.com> Tested-by: Michael Wiederhold <mike@couchbase.com>
- Loading branch information
Mike Wiederhold
authored and
Michael Wiederhold
committed
Jun 21, 2011
1 parent
d6008b7
commit 6ce52d2
Showing
9 changed files
with
100 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package net.spy.memcached; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.HashMap; | ||
import java.util.Map.Entry; | ||
|
||
import net.spy.memcached.ops.GetOperation; | ||
import net.spy.memcached.ops.OperationStatus; | ||
import net.spy.memcached.protocol.binary.BinaryOperationFactory; | ||
import junit.framework.TestCase; | ||
|
||
public class ErrorCodeTest extends TestCase { | ||
|
||
public void testErrorCodes() throws Exception { | ||
HashMap<Byte, String> err_map = new HashMap<Byte, String>(); | ||
OperationFactory opFact = new BinaryOperationFactory(); | ||
|
||
err_map.put(new Byte((byte) 0x01), "NOT FOUND"); | ||
err_map.put(new Byte((byte) 0x02), "EXISTS"); | ||
err_map.put(new Byte((byte) 0x03), "2BIG"); | ||
err_map.put(new Byte((byte) 0x04), "INVAL"); | ||
err_map.put(new Byte((byte) 0x05), "NOT STORED"); | ||
err_map.put(new Byte((byte) 0x06), "DELTA BAD VAL"); | ||
err_map.put(new Byte((byte) 0x07), "NOT MY VBUCKET"); | ||
err_map.put(new Byte((byte) 0x81), "UNKNOWN COMMAND"); | ||
err_map.put(new Byte((byte) 0x82), "NO MEM"); | ||
err_map.put(new Byte((byte) 0x83), "NOT SUPPORTED"); | ||
err_map.put(new Byte((byte) 0x84), "INTERNAL ERROR"); | ||
err_map.put(new Byte((byte) 0x85), "BUSY"); | ||
err_map.put(new Byte((byte) 0x86), "TEMP FAIL"); | ||
|
||
int opaque = 0; | ||
for (final Entry<Byte, String> err : err_map.entrySet()) { | ||
byte[] b = new byte[24 + err.getValue().length()]; | ||
b[0] = (byte)0x81; | ||
b[7] = err.getKey(); | ||
b[11] = (byte) err.getValue().length(); | ||
b[15] = (byte) ++opaque; | ||
System.arraycopy(err.getValue().getBytes(), 0, b, 24, err.getValue().length()); | ||
|
||
GetOperation op=opFact.get("key", | ||
new GetOperation.Callback() { | ||
public void receivedStatus(OperationStatus s) { | ||
assert !s.isSuccess(); | ||
assert err.getValue().equals(s.getMessage()); | ||
} | ||
public void gotData(String k, int flags, byte[] data) { | ||
|
||
} | ||
public void complete() { | ||
}}); | ||
ByteBuffer bb = ByteBuffer.wrap(b); | ||
bb.flip(); | ||
op.readFromBuffer(bb); | ||
} | ||
} | ||
} |