0
+package net.spy.memcached;
0
+import java.io.IOException;
0
+import java.net.InetSocketAddress;
0
+import java.util.ArrayList;
0
+import java.util.Arrays;
0
+import java.util.Collection;
0
+import java.util.Random;
0
+import java.util.concurrent.ExecutionException;
0
+import java.util.concurrent.Future;
0
+import java.util.concurrent.TimeUnit;
0
+import java.util.concurrent.TimeoutException;
0
+ * Test queue overflow.
0
+public class QueueOverflowTest extends ClientBaseCase {
0
+ protected void initClient() throws Exception {
0
+ initClient(new DefaultConnectionFactory(5, 1024) {
0
+ public MemcachedConnection createConnection(
0
+ List<InetSocketAddress> addrs) throws IOException {
0
+ MemcachedConnection rv = super.createConnection(addrs);
0
+ rv.setGetOptimization(false);
0
+ public long getOperationTimeout() {
0
+ private void runOverflowTest(byte b[]) throws Exception {
0
+ Collection<Future<Boolean>> c=new ArrayList<Future<Boolean>>();
0
+ for(int i=0; i<1000; i++) {
0
+ c.add(client.set("k" + i, 0, b));
0
+ fail("Didn't catch an illegal state exception");
0
+ } catch(IllegalStateException e) {
0
+ for(Future<Boolean> f : c) {
0
+ f.get(1, TimeUnit.SECONDS);
0
+ } catch(TimeoutException e) {
0
+ // OK, at least we got one back.
0
+ } catch(ExecutionException e) {
0
+ // OK, at least we got one back.
0
+ assertTrue(client.set("kx", 0, "woo").get(1, TimeUnit.SECONDS));
0
+ public void testOverflowingInputQueue() throws Exception {
0
+ runOverflowTest(new byte[]{1});
0
+ public void testOverflowingWriteQueue() throws Exception {
0
+ byte[] b=new byte[8192];
0
+ Random r=new Random();
0
+ public void testOverflowingReadQueue() throws Exception {
0
+ byte[] b=new byte[8192];
0
+ Random r=new Random();
0
+ client.set("x", 0, b);
0
+ Collection<Future<Object>> c=new ArrayList<Future<Object>>();
0
+ for(int i=0; i<1000; i++) {
0
+ c.add(client.asyncGet("x"));
0
+ fail("Didn't catch an illegal state exception");
0
+ } catch(IllegalStateException e) {
0
+ for(Future<Object> f : c) {
0
+ assertTrue(Arrays.equals(b,
0
+ (byte[])f.get(5, TimeUnit.SECONDS)));
0
+ } catch(TimeoutException e) {
0
+ // OK, just want to make sure the client doesn't crash
0
+ } catch(ExecutionException e) {
0
+ // OK, at least we got one back.
0
+ assertTrue(client.set("kx", 0, "woo").get(1, TimeUnit.SECONDS));
Comments
No one has commented yet.