Permalink
Browse files

Use vbuckets only for Couchbase nodes

Change-Id: I1981c6b670f9e168341b39e83bda0931f715ee76
Reviewed-on: http://review.couchbase.org/11738
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Matt Ingenthron <matt@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
1 parent c9d444c commit eb2f9a18660e784ec7858e43045fb5de4d27c7d8 @avsej avsej committed with ingenthr Dec 19, 2011
@@ -57,8 +57,16 @@ public Bucket(String name, String hostname, int port, int numNodes, int bucketSt
this.password = password;
datastore = new DataStore(numVBuckets);
servers = new MemcachedServer[numNodes];
+ BucketType type;
+ if (this.getClass() == MemcacheBucket.class) {
+ type = BucketType.MEMCACHE;
+ } else if (this.getClass() == CouchbaseBucket.class) {
+ type = BucketType.COUCHBASE;
+ } else {
+ throw new FileNotFoundException("I don't know about this type...");
+ }
for (int ii = 0; ii < servers.length; ii++) {
- servers[ii] = new MemcachedServer(hostname, (bucketStartPort == 0 ? 0 : bucketStartPort + ii), datastore, cluster);
+ servers[ii] = new MemcachedServer(type, hostname, (bucketStartPort == 0 ? 0 : bucketStartPort + ii), datastore, cluster);
}
rebalance();
}
@@ -18,6 +18,7 @@
import org.couchbase.mock.memcached.protocol.ErrorCode;
import java.security.AccessControlException;
import java.util.Map;
+import org.couchbase.mock.Bucket.BucketType;
/**
* A small little datastore.. Please note that since this is a dummy
@@ -47,7 +48,7 @@ public VBucket getVBucket(short vbucket) {
}
private Map<String, Item> getMap(MemcachedServer server, short vbucket) throws AccessControlException {
- if (vbucket >= vBucketMap.length) {
+ if (vbucket >= vBucketMap.length && server.getType() == BucketType.COUCHBASE) {
// Illegal vbucket.. just report as no access..
throw new AccessControlException("Illegal vbucket");
}
@@ -37,13 +37,12 @@
import java.security.AccessControlException;
import java.util.HashMap;
-import java.util.concurrent.CountDownLatch;
import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
import net.sf.json.JSONObject;
import org.couchbase.mock.Bucket;
+import org.couchbase.mock.Bucket.BucketType;
import org.couchbase.mock.CouchbaseMock;
/**
@@ -62,19 +61,22 @@
private final int port;
private CommandExecutor[] executors = new CommandExecutor[0xff];
private final CouchbaseMock cluster;
+ private final BucketType type;
private boolean active = true;
/**
* Create a new new memcached server.
*
+ * @param type
* @param hostname The hostname to bind to (null == any)
* @param port The port this server should listen to (0 to choose an
* ephemeral port)
* @param datastore
* @param cluster
* @throws IOException If we fail to create the server socket
*/
- public MemcachedServer(String hostname, int port, DataStore datastore, CouchbaseMock cluster) throws IOException {
+ public MemcachedServer(BucketType type, String hostname, int port, DataStore datastore, CouchbaseMock cluster) throws IOException {
+ this.type = type;
this.cluster = cluster;
this.datastore = datastore;
@@ -298,7 +300,7 @@ public void startup() {
public static void main(String[] args) {
try {
DataStore ds = new DataStore(1024);
- MemcachedServer server = new MemcachedServer(null, 11211, ds, null);
+ MemcachedServer server = new MemcachedServer(BucketType.COUCHBASE, null, 11211, ds, null);
for (int ii = 0; ii < 1024; ++ii) {
ds.setOwnership(ii, server);
}
@@ -314,4 +316,11 @@ public static void main(String[] args) {
public boolean isActive() {
return active;
}
+
+ /**
+ * @return the type
+ */
+ public BucketType getType() {
+ return type;
+ }
}
@@ -19,6 +19,7 @@
import java.security.AccessControlException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.couchbase.mock.Bucket.BucketType;
/**
*
@@ -40,7 +41,7 @@ public synchronized void setOwner(MemcachedServer server) {
}
public synchronized Map<String, Item> getMap(MemcachedServer server) {
- if (server != owner) {
+ if (server.getType() == BucketType.COUCHBASE && server != owner) {
throw new AccessControlException("Not my VBucket");
}
return map;
@@ -27,9 +27,6 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.TestCase;
@@ -104,7 +101,7 @@ public void testHandleHttpRequest() throws IOException {
}
public void testAdministratorCouldAccessProtectedBuckets() throws IOException {
- System.out.println("testHandleHttpRequest");
+ System.out.println("testAdministratorCouldAccessProtectedBuckets");
URL url = new URL("http://localhost:" + instance.getHttpPort() + "/pools/default/buckets/protected");
HttpURLConnection conn = null;
@@ -119,7 +116,7 @@ public void testAdministratorCouldAccessProtectedBuckets() throws IOException {
}
public void testDefaultBucketShouldBeAccessibleForEveryone() throws IOException {
- System.out.println("testHandleHttpRequest");
+ System.out.println("testDefaultBucketShouldBeAccessibleForEveryone");
URL url = new URL("http://localhost:" + instance.getHttpPort() + "/pools/default/buckets/default");
HttpURLConnection conn = null;
@@ -230,26 +227,26 @@ public void testHandleHttpRequestUnkownFile() throws IOException {
}
}
- public void testHarakirMonitorInvalidHost() throws IOException {
- System.out.println("testHarakirMonitorInvalidHost");
+ public void testHarakiriMonitorInvalidHost() throws IOException {
+ System.out.println("testHarakiriMonitorInvalidHost");
try {
CouchbaseMock.HarakiriMonitor m = new CouchbaseMock.HarakiriMonitor("ItWouldSuckIfYouHadAHostNamedThis", 0, port, false, null);
fail("I was not expecting to be able to connect to: \"ItWouldSuckIfYouHadAHostNamedThis:0\"");
} catch (Throwable t) {
}
}
- public void testHarakirMonitorInvalidPort() throws IOException {
- System.out.println("testHarakirMonitorInvalidPort");
+ public void testHarakiriMonitorInvalidPort() throws IOException {
+ System.out.println("testHarakiriMonitorInvalidPort");
try {
CouchbaseMock.HarakiriMonitor m = new CouchbaseMock.HarakiriMonitor(null, 0, port, false, null);
fail("I was not expecting to be able to connect to port 0");
} catch (Throwable t) {
}
}
- public void testHarakirMonitor() throws IOException {
- System.out.println("testHarakirMonitor");
+ public void testHarakiriMonitor() throws IOException {
+ System.out.println("testHarakiriMonitor");
ServerSocket server = new ServerSocket(0);
CouchbaseMock.HarakiriMonitor m;
m = new CouchbaseMock.HarakiriMonitor(null, server.getLocalPort(), port, false, null);

0 comments on commit eb2f9a1

Please sign in to comment.