Package org.apache.pulsar.testclient
Class PerfClientUtils
java.lang.Object
org.apache.pulsar.testclient.PerfClientUtils
Utility for test clients.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadaddShutdownHook(Runnable runnable) This is used to register a shutdown hook that will be called when the JVM exits.static voidcloseClient(PulsarClient client) This is used to close the client so that the interrupted status is cleared before closing the client.static PulsarAdminBuildercreateAdminBuilderFromArguments(PerformanceBaseArguments arguments, String adminUrl) static ClientBuilderstatic voidexit(int code) static booleanhasInterruptedException(Throwable throwable) Check if the throwable or any of its causes is an InterruptedException.static voidprintJVMInformation(org.slf4j.Logger log) Print useful JVM information, you need this information in order to be able to compare the results of executions in different environments.static voidremoveAndRunShutdownHook(Thread shutdownHookThread) This is used to remove a previously registered shutdown hook and run it immediately.static voidsetExitProcedure(Consumer<Integer> exitProcedure)
-
Constructor Details
-
PerfClientUtils
public PerfClientUtils()
-
-
Method Details
-
setExitProcedure
-
exit
public static void exit(int code) -
printJVMInformation
public static void printJVMInformation(org.slf4j.Logger log) Print useful JVM information, you need this information in order to be able to compare the results of executions in different environments.- Parameters:
log-
-
createClientBuilderFromArguments
public static ClientBuilder createClientBuilderFromArguments(PerformanceBaseArguments arguments) throws PulsarClientException.UnsupportedAuthenticationException -
createAdminBuilderFromArguments
public static PulsarAdminBuilder createAdminBuilderFromArguments(PerformanceBaseArguments arguments, String adminUrl) throws PulsarClientException.UnsupportedAuthenticationException -
addShutdownHook
This is used to register a shutdown hook that will be called when the JVM exits.- Parameters:
runnable- the runnable to run on shutdown- Returns:
- the thread that was registered as a shutdown hook
-
removeAndRunShutdownHook
This is used to remove a previously registered shutdown hook and run it immediately. This is useful at least for tests when there are multiple instances of the classes in the JVM. It will also prevent resource leaks when test code isn't relying on the JVM exit to clean up resources.- Parameters:
shutdownHookThread- the shutdown hook thread to remove and run- Throws:
InterruptedException- if the thread is interrupted while waiting for it to finish
-
closeClient
This is used to close the client so that the interrupted status is cleared before closing the client. This is needed if the thread is already interrupted before calling this method.- Parameters:
client- the client to close
-
hasInterruptedException
Check if the throwable or any of its causes is an InterruptedException.- Parameters:
throwable- the throwable to check- Returns:
- true if the throwable or any of its causes is an InterruptedException, false otherwise
-