TestUtils Class
- java.
lang. Object - com.
azure. core. test. utils. TestUtils
- com.
public final class TestUtils
Contains utility methods used for testing.
Method Summary
Methods inherited from java.lang.Object
Method Details
assertArraysEqual
public static void assertArraysEqual(byte[] expected, byte[] actual)
Asserts that two arrays are equal.
This method is similar to JUnit's Assertions#assertArrayEquals(byte[], byte[]) except that it takes advantage of hardware intrinsics offered by the JDK to optimize comparing the byte arrays.
If the arrays aren't equal this will call Assertions#assertArrayEquals(byte[], byte[]) to take advantage of the better error message, but this is the exceptional case and worth the double comparison performance hit.
Parameters:
assertArraysEqual
public static void assertArraysEqual(byte[] expected, int expectedOffset, byte[] actual, int actualOffset, int length)
Asserts that two arrays are equal.
This method is similar to JUnit's Assertions#assertArrayEquals(byte[], byte[]) except that it takes advantage of hardware intrinsics offered by the JDK to optimize comparing the byte arrays and allows for comparing subsections of the arrays.
If the arrays aren't equal this will copy the array ranges and call Assertions#assertArrayEquals(byte[], byte[]) to take advantage of the better error message, but this is the exceptional case and worth the double comparison performance hit.
Parameters:
assertByteBuffersEqual
public static void assertByteBuffersEqual(ByteBuffer expected, ByteBuffer actual)
Asserts that two ByteBuffers are equal.
This method is similar to JUnit's Assertions#assertArrayEquals(byte[], byte[]) except that it takes advantage of hardware intrinsics offered by the JDK to optimize comparing the ByteBuffers.
If the ByteBuffers aren't equal this will copy the ByteBuffer contents into byte arrays and call Assertions#assertArrayEquals(byte[], byte[]) to take advantage of the better error message, but this is the exceptional case and worth the double comparison performance hit.
Parameters:
getFaultInjectingHttpClient
public static HttpClient getFaultInjectingHttpClient(HttpClient clientToWrap, boolean useHttps)
Wraps an HttpClient to make calls to HTTP fault injector to test random network failures.
Using the HttpClient returned by this method requires all setup required by HTTP fault injector to be configured. useHttps
determines whether requests are forwarded to HTTP fault injector using HTTPS or HTTP, using HTTP doesn't require the self-signed certificate used by HTTP fault injector to be trusted by the JVM making it easier to prototype tests using HTTP fault injector. Merge ready tests should always use HTTPS.
The HttpClient returned will use the default successful and failure response percentages. 75% of request will succeed, 24% of requests will fail with a partial body returned, and 1% of requests will never return a response. It is recommended for tests using HTTP fault injector to set HttpClientOptions#setResponseTimeout(Duration) and HttpClientOptions#setReadTimeout(Duration), or the equivalent methods directly in the HTTP client builder being used, as the default timeouts are 60 seconds and with responses failing randomly reducing the timeout will let the tests run faster while still generally testing the same.
Parameters:
Returns:
getFaultInjectingHttpClient
public static HttpClient getFaultInjectingHttpClient(HttpClient clientToWrap, boolean useHttps, int successRate, int partialRate, int failureRate)
Wraps an HttpClient to make calls to HTTP fault injector to test random network failures.
Using the HttpClient returned by this method requires all setup required by HTTP fault injector to be configured. useHttps
determines whether requests are forwarded to HTTP fault injector using HTTPS or HTTP, using HTTP doesn't require the self-signed certificate used by HTTP fault injector to be trusted by the JVM making it easier to prototype tests using HTTP fault injector. Merge ready tests should always use HTTPS.
The HttpClient returned will use the specified successful and failure response percentages. The combination of successRate
, partialRate
, and failureRate
must equal 100, if not an IllegalArgumentException will be thrown. An IllegalArgumentException will also be thrown if any of the values are negative. It is recommended for tests using HTTP fault injector to set HttpClientOptions#setResponseTimeout(Duration) and HttpClientOptions#setReadTimeout(Duration), or the equivalent methods directly in the HTTP client builder being used, as the default timeouts are 60 seconds and with responses failing randomly reducing the timeout will let the tests run faster while still generally testing the same.
Parameters:
Returns:
getRecordFolder
public static File getRecordFolder()
Get the File pointing to the folder where session records live.
Returns:
getRepoRootResolveUntil
public static Path getRepoRootResolveUntil(Path testClassPath, String resolveFolder)
Locates the root of the current repo until the provided folder's parent.
Parameters:
Returns:
toURI
public static URI toURI(URL url)
Returns a URI equivalent to this URL.
Parameters:
Returns: