GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A simple, asynchronous, single-threaded memcached client written in java.
Homepage: http://code.google.com/p/spymemcached/
Clone URL: git://github.com/dustin/java-memcached-client.git
More UTF-8 tests and fixes.
dustin (author)
Tue Jan 22 20:32:26 -0800 2008
commit  26fa76e245351201345a412a4c70c287c02544f8
tree    d0862096c2d35f13dae97dae4c7f86bc20c828a8
parent  e06f632e48f0a0f6a29a050dc10c3ea82e98905d
...
4
5
6
 
7
8
9
...
40
41
42
43
 
 
44
45
46
...
4
5
6
7
8
9
10
...
41
42
43
 
44
45
46
47
48
0
@@ -4,6 +4,7 @@ package net.spy.memcached.protocol.ascii;
0
 
0
 import java.nio.ByteBuffer;
0
 
0
+import net.spy.memcached.KeyUtil;
0
 import net.spy.memcached.ops.DeleteOperation;
0
 import net.spy.memcached.ops.OperationCallback;
0
 import net.spy.memcached.ops.OperationState;
0
@@ -40,7 +41,8 @@ final class DeleteOperationImpl extends OperationImpl
0
 
0
   @Override
0
   public void initialize() {
0
- ByteBuffer b=ByteBuffer.allocate(key.length() + OVERHEAD);
0
+ ByteBuffer b=ByteBuffer.allocate(
0
+ KeyUtil.getKeyBytes(key).length + OVERHEAD);
0
     setArguments(b, "delete", key, when);
0
     b.flip();
0
     setBuffer(b);
...
9
10
11
 
12
13
14
...
45
46
47
48
49
 
 
50
51
52
53
54
 
 
 
55
56
57
58
 
59
60
61
62
 
63
64
65
 
66
67
68
...
9
10
11
12
13
14
15
...
46
47
48
 
 
49
50
51
52
53
54
 
55
56
57
58
59
60
 
61
62
63
64
 
65
66
67
 
68
69
70
71
0
@@ -9,6 +9,7 @@ import java.util.HashMap;
0
 import java.util.HashSet;
0
 import java.util.Map;
0
 
0
+import net.spy.memcached.KeyUtil;
0
 import net.spy.memcached.ops.GetOperation;
0
 import net.spy.memcached.ops.OperationCallback;
0
 import net.spy.memcached.ops.OperationState;
0
@@ -45,24 +46,26 @@ class MultiGetOperationImpl extends OperationImpl implements GetOperation {
0
   @Override
0
   public void initialize() {
0
     int size=(1+keys.size()) * MIN_RECV_PACKET;
0
- for(String s : keys.values()) {
0
- size += s.length();
0
+ for(byte[] b : KeyUtil.getKeyBytes(keys.values())) {
0
+ size += b.length;
0
     }
0
     // set up the initial header stuff
0
     ByteBuffer bb=ByteBuffer.allocate(size);
0
     for(Map.Entry<Integer, String> me : keys.entrySet()) {
0
- String key=me.getValue();
0
+ final String key=me.getValue();
0
+ final byte[] keyBytes=KeyUtil.getKeyBytes(key);
0
+
0
       // Custom header
0
       bb.put(REQ_MAGIC);
0
       bb.put((byte)CMD_GETQ);
0
- bb.putShort((short)key.length());
0
+ bb.putShort((short)KeyUtil.getKeyBytes(key).length);
0
       bb.put((byte)0); // extralen
0
       bb.put((byte)0); // data type
0
       bb.putShort((short)0); // reserved
0
- bb.putInt(key.length());
0
+ bb.putInt(keyBytes.length);
0
       bb.putInt(me.getKey());
0
       // the actual key
0
- bb.put(key.getBytes());
0
+ bb.put(keyBytes);
0
     }
0
     // Add the noop
0
     bb.put(REQ_MAGIC);
...
5
6
7
 
8
9
10
...
222
223
224
225
 
 
226
227
228
...
233
234
235
236
 
237
238
239
240
 
241
242
243
...
254
255
256
257
 
258
259
260
...
5
6
7
8
9
10
11
...
223
224
225
 
226
227
228
229
230
...
235
236
237
 
238
239
240
241
 
242
243
244
245
...
256
257
258
 
259
260
261
262
0
@@ -5,6 +5,7 @@ import java.nio.ByteBuffer;
0
 import java.nio.ByteOrder;
0
 import java.util.concurrent.atomic.AtomicInteger;
0
 
0
+import net.spy.memcached.KeyUtil;
0
 import net.spy.memcached.ops.OperationCallback;
0
 import net.spy.memcached.ops.OperationErrorType;
0
 import net.spy.memcached.ops.OperationState;
0
@@ -222,7 +223,8 @@ abstract class OperationImpl extends BaseOperationImpl {
0
         assert false : "Unhandled extra header type: " + o.getClass();
0
       }
0
     }
0
- int bufSize=MIN_RECV_PACKET + key.length() + val.length;
0
+ final byte[] keyBytes=KeyUtil.getKeyBytes(key);
0
+ int bufSize=MIN_RECV_PACKET + keyBytes.length + val.length;
0
 
0
     //  # magic, opcode, keylen, extralen, datatype, [reserved],
0
     // bodylen, opaque
0
@@ -233,11 +235,11 @@ abstract class OperationImpl extends BaseOperationImpl {
0
     assert bb.order() == ByteOrder.BIG_ENDIAN;
0
     bb.put(REQ_MAGIC);
0
     bb.put((byte)cmd);
0
- bb.putShort((short)key.length());
0
+ bb.putShort((short)keyBytes.length);
0
     bb.put((byte)extraLen);
0
     bb.put((byte)0); // data type
0
     bb.putShort((short)0); // reserved
0
- bb.putInt(key.length() + val.length + extraLen);
0
+ bb.putInt(keyBytes.length + val.length + extraLen);
0
     bb.putInt(opaque);
0
 
0
     // Add the extra headers.
0
@@ -254,7 +256,7 @@ abstract class OperationImpl extends BaseOperationImpl {
0
     }
0
 
0
     // Add the normal stuff
0
- bb.put(key.getBytes());
0
+ bb.put(keyBytes);
0
     bb.put(val);
0
 
0
     bb.flip();
...
436
437
438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
440
441
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
0
@@ -436,6 +436,33 @@ public abstract class ProtocolBaseCase extends ClientBaseCase {
0
     assertEquals("output is not equal", value, output);
0
   }
0
 
0
+ public void testUTF8KeyDelete() throws Exception {
0
+ final String key = "junit.Здравствуйте." + System.currentTimeMillis();
0
+ final String value = "Skiing rocks if you can find the time to go!";
0
+
0
+ assertTrue(client.set(key, 6000, value).get());
0
+ assertTrue(client.delete(key).get());
0
+ assertNull(client.get(key));
0
+ }
0
+
0
+ public void testUTF8MultiGet() throws Exception {
0
+ final String value = "Skiing rocks if you can find the time to go!";
0
+ Collection<String> keys=new ArrayList<String>();
0
+ for(int i=0; i<50; i++) {
0
+ final String key = "junit.Здравствуйте."
0
+ + System.currentTimeMillis() + "." + i;
0
+ assertTrue(client.set(key, 6000, value).get());
0
+ keys.add(key);
0
+ }
0
+
0
+ Map<String, Object> vals = client.getBulk(keys);
0
+ assertEquals(keys.size(), vals.size());
0
+ for(Object o : vals.values()) {
0
+ assertEquals(value, o);
0
+ }
0
+ assertTrue(keys.containsAll(vals.keySet()));
0
+ }
0
+
0
   public void testUTF8Value() throws Exception {
0
     final String key = "junit.plaintext." + System.currentTimeMillis();
0
     final String value = "Здравствуйте Здравствуйте Здравствуйте "

Comments

    No one has commented yet.