Package org.apache.pulsar.metadata.impl
Class FaultInjectionMetadataStore
java.lang.Object
org.apache.pulsar.metadata.impl.FaultInjectionMetadataStore
- All Implemented Interfaces:
AutoCloseable,MetadataStoreExtended,MetadataStore
Add possibility to inject failures during tests that interact with MetadataStore.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()deleteRecursive(String path) Delete a key-value pair and all the children nodes.Read whether a specific path exists.voidfailConditional(MetadataStoreException ex, BiPredicate<FaultInjectionMetadataStore.OperationType, String> predicate) getChildren(String path) Return all the nodes (lexicographically sorted) that are children to the specific path.<T> MetadataCache<T>getMetadataCache(com.fasterxml.jackson.core.type.TypeReference<T> typeRef, MetadataCacheConfig cacheConfig) Create a metadata cache specialized for a specific class.<T> MetadataCache<T>getMetadataCache(Class<T> clazz, MetadataCacheConfig cacheConfig) Create a metadata cache specialized for a specific class.<T> MetadataCache<T>getMetadataCache(MetadataSerde<T> serde, MetadataCacheConfig cacheConfig) Create a metadata cache that uses a particular serde object.Put a new value for a given key.Put a new value for a given key.voidregisterListener(Consumer<Notification> listener) Register a listener that will be called on changes in the underlying store.voidregisterSessionListener(Consumer<SessionEvent> listener) Register a session listener that will get notified of changes in status of the current session.voidvoidtriggerSessionEvent(SessionEvent event) voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pulsar.metadata.api.MetadataStore
getDefaultMetadataCacheConfig, getMetadataCache, getMetadataCache, getMetadataCacheMethods inherited from interface org.apache.pulsar.metadata.api.extended.MetadataStoreExtended
getMetadataEventSynchronizer
-
Constructor Details
-
FaultInjectionMetadataStore
-
-
Method Details
-
get
Description copied from interface:MetadataStoreRead the value of one key, identified by the path The async call will return a future that yields aGetResultthat will contain the value and the associatedStatobject. If the value is not found, the future will yield an emptyOptional.- Specified by:
getin interfaceMetadataStore- Parameters:
path- the path of the key to get from the store- Returns:
- a future to track the async request
-
getChildren
Description copied from interface:MetadataStoreReturn all the nodes (lexicographically sorted) that are children to the specific path. If the path itself does not exist, it will return an empty list.- Specified by:
getChildrenin interfaceMetadataStore- Parameters:
path- the path of the key to get from the store- Returns:
- a future to track the async request
-
exists
Description copied from interface:MetadataStoreRead whether a specific path exists. Note: In case of keys with multiple levels (eg: '/a/b/c'), checking the existence of a parent (eg. '/a') might not necessarily return true, unless the key had been explicitly created.- Specified by:
existsin interfaceMetadataStore- Parameters:
path- the path of the key to check on the store- Returns:
- a future to track the async request
-
put
Description copied from interface:MetadataStorePut a new value for a given key. The caller can specify an expected version to be atomically checked against the current version of the stored data. The future will return theStatobject associated with the newly inserted value.- Specified by:
putin interfaceMetadataStore- Parameters:
path- the path of the key to delete from the storevalue- the value toexpectedVersion- if present, the version will have to match with the currently stored value for the operation to succeed. Use -1 to enforce a non-existing value.- Returns:
- a future to track the async request
-
put
public CompletableFuture<Stat> put(String path, byte[] value, Optional<Long> expectedVersion, EnumSet<CreateOption> options) Description copied from interface:MetadataStoreExtendedPut a new value for a given key. The caller can specify an expected version to be atomically checked against the current version of the stored data. The future will return theStatobject associated with the newly inserted value.- Specified by:
putin interfaceMetadataStoreExtended- Parameters:
path- the path of the key to delete from the storevalue- the value toexpectedVersion- if present, the version will have to match with the currently stored value for the operation to succeed. Use -1 to enforce a non-existing value.options- a set ofCreateOptionto use if the the key-value pair is being created- Returns:
- a future to track the async request
-
delete
- Specified by:
deletein interfaceMetadataStore- Parameters:
path- the path of the key to delete from the storeexpectedVersion- if present, the version will have to match with the currently stored value for the operation to succeed- Returns:
- a future to track the async request
-
deleteRecursive
Description copied from interface:MetadataStoreDelete a key-value pair and all the children nodes. Note: the operation might not be carried in an atomic fashion. If the operation fails, the deletion of the tree might be only partial.- Specified by:
deleteRecursivein interfaceMetadataStore- Parameters:
path- the path of the key to delete from the store- Returns:
- a future to track the async request
-
registerListener
Description copied from interface:MetadataStoreRegister a listener that will be called on changes in the underlying store.- Specified by:
registerListenerin interfaceMetadataStore- Parameters:
listener- a consumer of notifications
-
getMetadataCache
Description copied from interface:MetadataStoreCreate a metadata cache specialized for a specific class.- Specified by:
getMetadataCachein interfaceMetadataStore- Parameters:
clazz- the class type to be used for serialization/deserializationcacheConfig- the cache configuration to be used- Returns:
- the metadata cache object
-
getMetadataCache
public <T> MetadataCache<T> getMetadataCache(com.fasterxml.jackson.core.type.TypeReference<T> typeRef, MetadataCacheConfig cacheConfig) Description copied from interface:MetadataStoreCreate a metadata cache specialized for a specific class.- Specified by:
getMetadataCachein interfaceMetadataStore- Parameters:
typeRef- the type ref description to be used for serialization/deserializationcacheConfig- the cache configuration to be used- Returns:
- the metadata cache object
-
getMetadataCache
public <T> MetadataCache<T> getMetadataCache(MetadataSerde<T> serde, MetadataCacheConfig cacheConfig) Description copied from interface:MetadataStoreCreate a metadata cache that uses a particular serde object.- Specified by:
getMetadataCachein interfaceMetadataStore- Parameters:
serde- the custom serialization/deserialization objectcacheConfig- the cache configuration to be used- Returns:
- the metadata cache object
-
registerSessionListener
Description copied from interface:MetadataStoreExtendedRegister a session listener that will get notified of changes in status of the current session.- Specified by:
registerSessionListenerin interfaceMetadataStoreExtended- Parameters:
listener- the session listener
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
failConditional
public void failConditional(MetadataStoreException ex, BiPredicate<FaultInjectionMetadataStore.OperationType, String> predicate) -
setAlwaysFail
-
unsetAlwaysFail
public void unsetAlwaysFail() -
triggerSessionEvent
-