Package com.yahoo.vespa.curator.mock
Class MockCurator
java.lang.Object
com.yahoo.component.AbstractComponent
com.yahoo.vespa.curator.Curator
com.yahoo.vespa.curator.mock.MockCurator
- All Implemented Interfaces:
com.yahoo.component.Component
,com.yahoo.component.Deconstructable
,AutoCloseable
,Comparable<com.yahoo.component.Component>
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 inherited from class com.yahoo.component.AbstractComponent
isDeconstructable
-
Constructor Summary
ConstructorDescriptionCreates a mock curator with stable orderingMockCurator
(boolean stableOrdering) Creates a mock curator -
Method Summary
Modifier and TypeMethodDescriptionOptional<org.apache.curator.framework.recipes.atomic.DistributedAtomicLong>
Returns an atomic counter in this, or empty if no such counter is createdorg.apache.curator.framework.recipes.atomic.DistributedAtomicLong
createAtomicCounter
(String path) For internal use; prefer creating aCuratorCounter
createCompletionWaiter
(com.yahoo.path.Path parentPath, String waiterNode, int numMembers, String id) createDirectoryCache
(String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService) Creates a listenable cache which keeps in sync with changes to all the immediate children of a pathcreateFileCache
(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
(String path) For internal use; prefer creating aLock
Lists the entire content of this curator instance as a multiline string.getCompletionWaiter
(com.yahoo.path.Path parentPath, int numMembers, String id) void
setZooKeeperEnsembleConnectionSpec
(String ensembleSpec) Sets the ZooKeeper ensemble connection spec, which must be on the form host1:port,host2:port ...int
Returns the number of zooKeeper servers in this ensemble.Methods inherited from class com.yahoo.vespa.curator.Curator
close, create, create, create, create, createAtomically, deconstruct, delete, delete, delete, exists, framework, getChildren, getData, getData, getStat, lock, lock, sessionTimeout, set, set
Methods inherited from class com.yahoo.component.AbstractComponent
clone, compareTo, getClassName, getId, getIdString, hasInitializedId, initId, isDeconstructable, setIsDeconstructable, toString
-
Constructor Details
-
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 queried. This is not what ZooKeeper does.
-
-
Method Details
-
dumpState
Lists the entire content of this curator instance as a multiline string. Useful for debugging. -
counter
public Optional<org.apache.curator.framework.recipes.atomic.DistributedAtomicLong> counter(String path) Returns an atomic counter in this, or empty if no such counter is created -
setZooKeeperEnsembleConnectionSpec
Sets the ZooKeeper ensemble connection spec, which must be on the form host1:port,host2:port ... -
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.
-
createAtomicCounter
public org.apache.curator.framework.recipes.atomic.DistributedAtomicLong createAtomicCounter(String path) Description copied from class:Curator
For internal use; prefer creating aCuratorCounter
- Overrides:
createAtomicCounter
in classCurator
-
createMutex
Description copied from class:Curator
For internal use; prefer creating aLock
- Overrides:
createMutex
in classCurator
-
getCompletionWaiter
public Curator.CompletionWaiter getCompletionWaiter(com.yahoo.path.Path parentPath, int numMembers, String id) - Overrides:
getCompletionWaiter
in classCurator
-
createCompletionWaiter
public Curator.CompletionWaiter createCompletionWaiter(com.yahoo.path.Path parentPath, String waiterNode, int numMembers, String id) - Overrides:
createCompletionWaiter
in classCurator
-
createDirectoryCache
public Curator.DirectoryCache createDirectoryCache(String path, boolean cacheData, boolean dataIsCompressed, 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
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
-