public abstract class Bucket extends Object
CouchbaseBucket
see MemcachedBucket
A bucket is instantiated via CouchbaseMock.createBucket(BucketConfiguration). The number
of servers a bucket has is limited to the amount provided in the BucketConfiguration.numNodes
field.
Nodes can be removed and then re-added, but currently new nodes cannot be added once the bucket has been instantiated.| Modifier and Type | Class and Description |
|---|---|
static class |
Bucket.BucketType |
| Modifier and Type | Field and Description |
|---|---|
protected CouchbaseMock |
cluster |
protected ReentrantReadWriteLock |
configurationRwLock |
protected String |
name |
protected int |
numReplicas |
protected int |
numVBuckets |
protected String |
password |
protected String |
poolName |
protected MemcachedServer[] |
servers |
protected VBucketInfo[] |
vbInfo |
| Constructor and Description |
|---|
Bucket(CouchbaseMock cluster,
BucketConfiguration config) |
| Modifier and Type | Method and Description |
|---|---|
List<MemcachedServer> |
activeServers()
Gets the list of active nodes within the bucket.
|
void |
configReadLock()
Lock the current configuration for reading.
|
void |
configReadUnlock()
Unlock the configuration read lock.
|
static Bucket |
create(CouchbaseMock mock,
BucketConfiguration config)
Create a bucket.
|
void |
failover(int index,
boolean rebalance)
Fail over one of the bucket's nodes
|
BucketAdminServer |
getAdminServer()
Get the object used for handling configuration changes
|
CAPIServer |
getCAPIServer()
Get the
CAPIServer object used for managing views. |
CouchbaseMock |
getCluster()
Gets the parent
CouchbaseMock object |
protected Map<String,Object> |
getCommonConfig()
Returns configuration information common to both Couchbase and Memcached buckets
|
abstract Map<String,Object> |
getConfigMap()
Gets a map of the current bucket configuration which can be JSON-serialized
as a valid "Cluster configuration".
|
String |
getJSON()
Convenience method to get the JSON-encoded version of the configuration map
getConfigMap() |
Iterable<Item> |
getMasterItems(Storage.StorageType type)
Returns an iterable over all the items in this bucket
|
String |
getName()
Get the name of the bucket
|
String |
getPassword()
Get the password for this bucket.
|
MemcachedServer[] |
getServers()
Get the list of servers allocated for this bucket.
|
abstract Bucket.BucketType |
getType()
Gets the type of the bucket
|
String |
getUUID()
Gets the UUID for the bucket.
|
short |
getVbIndexForKey(String key)
Get the server index for a given key
|
VBucketInfo[] |
getVBucketInfo()
Returns the vBucket map for the given bucket.
|
void |
regenCoords() |
void |
respawn(int index)
Re-Add a previously failed-over node
|
abstract ErrorCode |
storeItem(String key,
byte[] value)
Convenience method to store an item in a bucket
|
protected final VBucketInfo[] vbInfo
protected final MemcachedServer[] servers
protected final int numVBuckets
protected final int numReplicas
protected final String poolName
protected final String name
protected final CouchbaseMock cluster
protected final String password
protected final ReentrantReadWriteLock configurationRwLock
public Bucket(CouchbaseMock cluster, BucketConfiguration config) throws IOException
IOExceptionpublic VBucketInfo[] getVBucketInfo()
CouchbaseBucketpublic MemcachedServer[] getServers()
public Iterable<Item> getMasterItems(Storage.StorageType type)
type - The storage location to fetch frompublic short getVbIndexForKey(String key)
key - The key to look uppublic static Bucket create(CouchbaseMock mock, BucketConfiguration config) throws IOException
mock - The cluster this bucket is a member ofconfig - The configuration for the bucketIOException - if an I/O error occurspublic abstract Bucket.BucketType getType()
public CAPIServer getCAPIServer()
CAPIServer object used for managing views.public BucketAdminServer getAdminServer()
public abstract Map<String,Object> getConfigMap()
/pools/default/buckets/$bucket endpoint in a Couchbase cluster.configReadLock()
before calling this method, and configReadUnlock() after calling
this method.protected Map<String,Object> getCommonConfig()
public final String getJSON()
getConfigMap()public void configReadLock()
configReadUnlock() once the lock
is no longer required.
This method is most useful to ensure that the bucket state remains the same while
reading configuration-related properties.public void configReadUnlock()
configReadLock()public abstract ErrorCode storeItem(String key, byte[] value)
key - The key of the itemvalue - The value of the itempublic void failover(int index,
boolean rebalance)
index - The index of the node to fail over. This index
is the index of the node within the servers
(or getServers() array; not the logical index
within the vBucket map!rebalance - Should we rebalance after failover
Note this will also automatically rebalance the clusterpublic void respawn(int index)
index - The index to restore. This should be an index into the
servers array.public List<MemcachedServer> activeServers()
public void regenCoords()
public String getPassword()
public String getName()
public String getUUID()
public CouchbaseMock getCluster()
CouchbaseMock objectCopyright © 2017. All rights reserved.