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
,VespaCurator
,AutoCloseable
,Comparable<com.yahoo.component.Component>
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
-
-
Constructor Summary
Constructors Constructor Description MockCurator()
Creates a mock curator with stable orderingMockCurator(boolean stableOrdering)
Creates a mock curator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<org.apache.curator.framework.recipes.atomic.DistributedAtomicLong>
counter(String path)
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
Curator.CompletionWaiter
createCompletionWaiter(com.yahoo.path.Path parentPath, String waiterNode, int numMembers, String id)
Curator.DirectoryCache
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 pathCurator.FileCache
createFileCache(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
String
dumpState()
Lists the entire content of this curator instance as a multiline string.Curator.CompletionWaiter
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 ...String
zooKeeperEnsembleConnectionSpec()
int
zooKeeperEnsembleCount()
Returns the number of zooKeeper servers in this ensemble.-
Methods inherited from class com.yahoo.vespa.curator.Curator
close, create, create, create, createAtomically, deconstruct, delete, exists, framework, 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 String 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
public void setZooKeeperEnsembleConnectionSpec(String ensembleSpec)
Sets the ZooKeeper ensemble connection spec, which must be on the form host1:port,host2:port ...
-
zooKeeperEnsembleConnectionSpec
public 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.
-
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
public org.apache.curator.framework.recipes.locks.InterProcessLock createMutex(String path)
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
public Curator.FileCache createFileCache(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
-
-