Skip to content

Commit

Permalink
SPY-187: Expose a few more attributes of MemcachedClient
Browse files Browse the repository at this point in the history
Motivation
----------
Extending MemcachedClient to access some of its protected attributes is
not always desirable as it makes harder writing mocks for unit testing.

Modifications
-------------
MemcachedClient now exposes operationTimeout,
mconn, tcService and executorService.

Result
------
One does not have to extend MemcachedClient any more to write custom
commands.

Change-Id: I81932da64d4492512dcf1a11fe1161203fa70c5e
Reviewed-on: http://review.couchbase.org/51546
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
  • Loading branch information
fabienrenaud authored and Michael Nitschinger committed Jun 11, 2015
1 parent ce08f50 commit 41cf86b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
70 changes: 43 additions & 27 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,6 @@

package net.spy.memcached;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.AuthThreadMonitor;
import net.spy.memcached.compat.SpyObject;
Expand All @@ -74,12 +48,37 @@
import net.spy.memcached.ops.StoreOperation;
import net.spy.memcached.ops.StoreType;
import net.spy.memcached.ops.TimedOutOperationStatus;
import net.spy.memcached.protocol.ascii.AsciiOperationFactory;
import net.spy.memcached.protocol.binary.BinaryOperationFactory;
import net.spy.memcached.transcoders.TranscodeService;
import net.spy.memcached.transcoders.Transcoder;
import net.spy.memcached.util.StringUtils;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

/**
* Client to a memcached server.
*
Expand Down Expand Up @@ -2628,8 +2627,25 @@ public void connectionLost(SocketAddress sa) {
// Don't care.
}

public long getOperationTimeout() {
return operationTimeout;
}

public MemcachedConnection getConnection() {
return mconn;
}

public TranscodeService getTranscoderService() {
return tcService;
}

public ExecutorService getExecutorService() {
return executorService;
}

@Override
public String toString() {
return connFactory.toString();
}
}

9 changes: 5 additions & 4 deletions src/main/java/net/spy/memcached/MemcachedClientIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

package net.spy.memcached;

import net.spy.memcached.internal.BulkFuture;
import net.spy.memcached.internal.OperationFuture;
import net.spy.memcached.transcoders.Transcoder;

import java.net.SocketAddress;
import java.util.Collection;
import java.util.Iterator;
Expand All @@ -32,10 +36,6 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import net.spy.memcached.internal.BulkFuture;
import net.spy.memcached.internal.OperationFuture;
import net.spy.memcached.transcoders.Transcoder;

/**
* This interface is provided as a helper for testing clients of the
* MemcachedClient.
Expand Down Expand Up @@ -240,4 +240,5 @@ CountDownLatch broadcastOp(final BroadcastOpFactory of,
* @return the union of all SASL mechanisms supported by the servers.
*/
Set<String> listSaslMechanisms();

}

0 comments on commit 41cf86b

Please sign in to comment.