Package com.yahoo.vespa.curator.mock
Class MockCurator
- java.lang.Object
-
- com.yahoo.vespa.curator.Curator
-
- com.yahoo.vespa.curator.mock.MockCurator
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class MockCurator extends Curator
A non thread safe mock of the curator API. The methods are implemented lazily, due to laziness. You may trigger an UnsupportedOperationException, and in some cases a NullPointerException in using this, which means additional functionality is needed. Due to the "fluent API" style of Curator managing to break JavaDoc at a fundamental level, there is no documentation on the contract of each method. The behavior here is deduced by observing what using code exists and peeking at the Curator code. It may be incorrect in some corner cases.
Contains some code from PathUtils in ZooKeeper, licensed under the Apache 2.0 license.
- Author:
- bratseth
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.yahoo.vespa.curator.Curator
Curator.CompletionWaiter, Curator.DirectoryCache, Curator.FileCache
-
-
Field Summary
Fields Modifier and Type Field Description boolean
throwExceptionOnLock
boolean
timeoutOnLock
-
Fields inherited from class com.yahoo.vespa.curator.Curator
retryPolicy
-
-
Constructor Summary
Constructors Constructor Description MockCurator()
Creates a mock curator with stable orderingMockCurator(boolean stableOrdering)
Creates a mock curator
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<org.apache.curator.framework.recipes.atomic.DistributedAtomicLong>
counter(java.lang.String path)
Returns an atomic counter in this, or empty if no such counter is createdorg.apache.curator.framework.recipes.atomic.DistributedAtomicLong
createAtomicCounter(java.lang.String path)
For internal use; prefer creating aCuratorCounter
Curator.CompletionWaiter
createCompletionWaiter(com.yahoo.path.Path parentPath, java.lang.String waiterNode, int numMembers, java.lang.String id)
Curator.DirectoryCache
createDirectoryCache(java.lang.String path, boolean cacheData, boolean dataIsCompressed, java.util.concurrent.ExecutorService executorService)
Creates a listenable cache which keeps in sync with changes to all the immediate children of a pathCurator.FileCache
createFileCache(java.lang.String path, boolean dataIsCompressed)
Creates a listenable cache which keeps in sync with changes to a given nodeorg.apache.curator.framework.recipes.locks.InterProcessLock
createMutex(java.lang.String path)
Create a mutex which ensures exclusive access within this single vmjava.lang.String
dumpState()
Lists the entire content of this curator instance as a multiline string.org.apache.curator.framework.CuratorFramework
framework()
Returns a started curator frameworkCurator.CompletionWaiter
getCompletionWaiter(com.yahoo.path.Path parentPath, int numMembers, java.lang.String id)
void
setZooKeeperEnsembleConnectionSpec(java.lang.String ensembleSpec)
Sets the ZooKeeper ensemble connection spec, which must be on the form host1:port,host2:port ...MockCurator
timeoutBarrierOnEnter(boolean shouldTimeout)
static java.lang.String
validatePath(java.lang.String path)
Validates a path using the same rules as ZooKeeperjava.lang.String
zooKeeperEnsembleConnectionSpec()
int
zooKeeperEnsembleCount()
Returns the number of zooKeeper servers in this ensemble.-
Methods inherited from class com.yahoo.vespa.curator.Curator
close, connectionSpec, create, create, create, createAtomically, delete, exists, getChildren, getData, getStat, lock, set
-
-
-
-
Constructor Detail
-
MockCurator
@Inject public MockCurator()
Creates a mock curator with stable ordering
-
MockCurator
public MockCurator(boolean stableOrdering)
Creates a mock curator- Parameters:
stableOrdering
- if true children of a node are returned in the same order each time they are queries. This is not what ZooKeeper does.
-
-
Method Detail
-
dumpState
public java.lang.String dumpState()
Lists the entire content of this curator instance as a multiline string. Useful for debugging.
-
framework
public org.apache.curator.framework.CuratorFramework framework()
Returns a started curator framework
-
counter
public java.util.Optional<org.apache.curator.framework.recipes.atomic.DistributedAtomicLong> counter(java.lang.String path)
Returns an atomic counter in this, or empty if no such counter is created
-
setZooKeeperEnsembleConnectionSpec
public void setZooKeeperEnsembleConnectionSpec(java.lang.String ensembleSpec)
Sets the ZooKeeper ensemble connection spec, which must be on the form host1:port,host2:port ...
-
zooKeeperEnsembleConnectionSpec
public java.lang.String zooKeeperEnsembleConnectionSpec()
- Overrides:
zooKeeperEnsembleConnectionSpec
in classCurator
- Returns:
- The non-null connect string containing all ZooKeeper servers in the ensemble. WARNING: This may be different from the servers this Curator may connect to. TODO: Move method out of this class.
-
validatePath
public static java.lang.String validatePath(java.lang.String path) throws java.lang.IllegalArgumentException
Validates a path using the same rules as ZooKeeper- Throws:
java.lang.IllegalArgumentException
-
createAtomicCounter
public org.apache.curator.framework.recipes.atomic.DistributedAtomicLong createAtomicCounter(java.lang.String path)
Description copied from class:Curator
For internal use; prefer creating aCuratorCounter
- Overrides:
createAtomicCounter
in classCurator
-
createMutex
public org.apache.curator.framework.recipes.locks.InterProcessLock createMutex(java.lang.String path)
Create a mutex which ensures exclusive access within this single vm- Overrides:
createMutex
in classCurator
-
timeoutBarrierOnEnter
public MockCurator timeoutBarrierOnEnter(boolean shouldTimeout)
-
getCompletionWaiter
public Curator.CompletionWaiter getCompletionWaiter(com.yahoo.path.Path parentPath, int numMembers, java.lang.String id)
- Overrides:
getCompletionWaiter
in classCurator
-
createCompletionWaiter
public Curator.CompletionWaiter createCompletionWaiter(com.yahoo.path.Path parentPath, java.lang.String waiterNode, int numMembers, java.lang.String id)
- Overrides:
createCompletionWaiter
in classCurator
-
createDirectoryCache
public Curator.DirectoryCache createDirectoryCache(java.lang.String path, boolean cacheData, boolean dataIsCompressed, java.util.concurrent.ExecutorService executorService)
Description copied from class:Curator
Creates a listenable cache which keeps in sync with changes to all the immediate children of a path- Overrides:
createDirectoryCache
in classCurator
-
createFileCache
public Curator.FileCache createFileCache(java.lang.String path, boolean dataIsCompressed)
Description copied from class:Curator
Creates a listenable cache which keeps in sync with changes to a given node- Overrides:
createFileCache
in classCurator
-
zooKeeperEnsembleCount
public int zooKeeperEnsembleCount()
Description copied from class:Curator
Returns the number of zooKeeper servers in this ensemble. WARNING: This may be different from the number of servers this Curator may connect to. TODO: Move method out of this class.- Overrides:
zooKeeperEnsembleCount
in classCurator
-
-