Browse files

Fix delete command

Change-Id: I92f622669d2b2cb09ec04818a904c0e5079595d9
Reviewed-on: http://review.couchbase.org/11975
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent d195b98 commit 9e5a0834d79ea26f50546bc59f9bc07975fe5315 @avsej avsej committed with trondn Dec 30, 2011
Showing with 6 additions and 8 deletions.
  1. +6 −8 src/main/java/org/couchbase/mock/memcached/DataStore.java
View
14 src/main/java/org/couchbase/mock/memcached/DataStore.java
@@ -103,17 +103,15 @@ public ErrorCode set(MemcachedServer server, short vBucketId, Item item) {
ErrorCode delete(MemcachedServer server, short vBucketId, String key, long cas) {
// I don't give a shit about atomicy right now..
Map<String, Item> map = getMap(server, vBucketId);
- if (cas == 0) {
- map.remove(key);
- return ErrorCode.SUCCESS;
- } else {
- Item i = map.get(key);
- if (i.getCas() != cas) {
- return ErrorCode.KEY_EEXISTS;
- }
+ Item i = map.get(key);
+ if (i == null) {
+ return ErrorCode.KEY_ENOENT;
+ }
+ if (cas == 0 || cas == i.getCas()) {
map.remove(key);
return ErrorCode.SUCCESS;
}
+ return ErrorCode.KEY_EEXISTS;
}
Item get(MemcachedServer server, short vBucketId, String key) {

0 comments on commit 9e5a083

Please sign in to comment.