Package io.apicurio.registry.utils.tests
Class TestUtils
- java.lang.Object
-
- io.apicurio.registry.utils.tests.TestUtils
-
public class TestUtils extends Object
- Author:
- Ales Justin, Jakub Stejskal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TestUtils.RunnableExc
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertClientError(String expectedErrorName, int expectedCode, TestUtils.RunnableExc runnable, boolean retry, Function<Exception,Integer> errorCodeExtractor)
static void
assertClientError(String expectedErrorName, int expectedCode, TestUtils.RunnableExc runnable, Function<Exception,Integer> errorCodeExtractor)
static String
generateArtifactId()
static String
generateGroupId()
static String
generateSubject()
static String
generateTopic()
static String
generateTopic(String prefix)
static String
getRegistryApiUrl()
static String
getRegistryBaseUrl()
static String
getRegistryHost()
static int
getRegistryPort()
static String
getRegistryUIUrl()
static String
getRegistryV1ApiUrl()
static String
getRegistryV2ApiUrl()
static boolean
isExternalRegistry()
static boolean
isReachable()
Method which try connection to registries.static boolean
isReachable(String host, int port, String component)
Generic check if an endpoint is network reachablestatic boolean
isReady(boolean logResponse)
Checks the readniess endpoint of the registrystatic boolean
isReady(String baseUrl, String healthUrl, boolean logResponse, String component)
Generic check of the /health/ready endpointstatic void
retry(TestUtils.RunnableExc runnable)
static void
retry(TestUtils.RunnableExc runnable, String name, int maxRetries)
static <T> T
retry(Callable<T> callable)
static <T> T
retry(Callable<T> callable, String name, int maxRetries)
static long
waitFor(String description, long pollIntervalMs, long timeoutMs, BooleanSupplier ready)
Poll the givenready
function everypollIntervalMs
milliseconds until it returns true, or throw a TimeoutException if it doesn't returns true withintimeoutMs
milliseconds.static long
waitFor(String description, long pollIntervalMs, long timeoutMs, BooleanSupplier ready, Runnable onTimeout)
static void
waitForSchema(Predicate<Long> schemaFinder, byte[] bytes)
static void
waitForSchema(Predicate<Long> schemaFinder, byte[] bytes, Function<ByteBuffer,Long> globalIdExtractor)
static void
waitForSchemaCustom(Predicate<Long> schemaFinder, byte[] bytes, Function<byte[],Long> globalIdExtractor)
static void
writeFile(String filePath, String text)
Method to create and write String content file.static void
writeFile(Path filePath, String text)
-
-
-
Method Detail
-
isExternalRegistry
public static boolean isExternalRegistry()
-
getRegistryHost
public static String getRegistryHost()
-
getRegistryPort
public static int getRegistryPort()
-
getRegistryUIUrl
public static String getRegistryUIUrl()
-
getRegistryApiUrl
public static String getRegistryApiUrl()
-
getRegistryV1ApiUrl
public static String getRegistryV1ApiUrl()
-
getRegistryV2ApiUrl
public static String getRegistryV2ApiUrl()
-
getRegistryBaseUrl
public static String getRegistryBaseUrl()
-
isReachable
public static boolean isReachable()
Method which try connection to registries. It's used as a initial check for registries availability.- Returns:
- true if registries are ready for use, false in other cases
-
isReachable
public static boolean isReachable(String host, int port, String component)
Generic check if an endpoint is network reachable- Parameters:
host
-port
-component
-- Returns:
- true if it's possible to open a network connection to the endpoint
-
isReady
public static boolean isReady(boolean logResponse)
Checks the readniess endpoint of the registry- Returns:
- true if registry readiness endpoint replies sucessfully
-
isReady
public static boolean isReady(String baseUrl, String healthUrl, boolean logResponse, String component)
Generic check of the /health/ready endpoint- Parameters:
baseUrl
-logResponse
-component
-- Returns:
- true if the readiness endpoint replies successfully
-
waitFor
public static long waitFor(String description, long pollIntervalMs, long timeoutMs, BooleanSupplier ready) throws TimeoutException
Poll the givenready
function everypollIntervalMs
milliseconds until it returns true, or throw a TimeoutException if it doesn't returns true withintimeoutMs
milliseconds. (helpful if you have several calls which need to share a common timeout)- Returns:
- The remaining time left until timeout occurs
- Throws:
TimeoutException
-
waitFor
public static long waitFor(String description, long pollIntervalMs, long timeoutMs, BooleanSupplier ready, Runnable onTimeout) throws TimeoutException
- Throws:
TimeoutException
-
writeFile
public static void writeFile(String filePath, String text)
Method to create and write String content file.- Parameters:
filePath
- path to filetext
- content
-
generateTopic
public static String generateTopic()
-
generateSubject
public static String generateSubject()
-
generateArtifactId
public static String generateArtifactId()
-
generateGroupId
public static String generateGroupId()
-
retry
public static void retry(TestUtils.RunnableExc runnable) throws Exception
- Throws:
Exception
-
retry
public static void retry(TestUtils.RunnableExc runnable, String name, int maxRetries) throws Exception
- Throws:
Exception
-
retry
public static <T> T retry(Callable<T> callable, String name, int maxRetries) throws Exception
- Throws:
Exception
-
assertClientError
public static void assertClientError(String expectedErrorName, int expectedCode, TestUtils.RunnableExc runnable, Function<Exception,Integer> errorCodeExtractor) throws Exception
- Throws:
Exception
-
assertClientError
public static void assertClientError(String expectedErrorName, int expectedCode, TestUtils.RunnableExc runnable, boolean retry, Function<Exception,Integer> errorCodeExtractor) throws Exception
- Throws:
Exception
-
waitForSchema
public static void waitForSchema(Predicate<Long> schemaFinder, byte[] bytes) throws Exception
- Throws:
Exception
-
waitForSchema
public static void waitForSchema(Predicate<Long> schemaFinder, byte[] bytes, Function<ByteBuffer,Long> globalIdExtractor) throws Exception
- Throws:
Exception
-
-