public final class TestTools
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
assertAfter(int delay,
int duration,
java.lang.Runnable assertions)
Runs the specified runnable until it completes successfully or until the
specified time expires.
|
static void |
assertAfter(int duration,
java.lang.Runnable assertions)
Runs the specified runnable until it completes successfully or until the
specified time expires.
|
static java.util.List<java.io.File> |
createTestFiles(java.util.List<java.lang.String> paths)
Creates a directory tree of test files.
|
static java.util.List<java.io.File> |
createTestFiles(java.util.List<java.lang.String> paths,
int minSize,
int maxSize)
Creates a directory tree of test files.
|
static void |
delay(int ms)
Suspends the current thread for a specified number of millis.
|
static int |
findAvailablePort(int defaultPort) |
static long |
now()
Returns the current time in millis since epoch.
|
static void |
print(java.lang.String msg) |
static void |
tweakBytes(java.util.Random random,
byte[] data,
int count)
Tweaks the given number of bytes in a byte array.
|
static void |
tweakBytes(java.util.Random random,
byte[] data,
int count,
int start,
int end)
Tweaks the given number of bytes in the specified range of a byte array.
|
static void |
writeRandomFile(java.io.File file,
int minSize,
int maxSize)
Writes random binary content into the specified file.
|
public static void print(java.lang.String msg)
public static void delay(int ms)
ms
- number of millispublic static long now()
public static void assertAfter(int delay, int duration, java.lang.Runnable assertions)
Assertions attempts will not be closer than 10 millis apart and no further than 50 millis.
delay
- number of millis to delay before the first attemptduration
- number of milliseconds beyond the current timeassertions
- test assertions runnablepublic static void assertAfter(int duration, java.lang.Runnable assertions)
Assertions attempts will not be closer than 10 millis apart and no further than 50 millis.
duration
- number of milliseconds beyond the current timeassertions
- test assertions runnablepublic static java.util.List<java.io.File> createTestFiles(java.util.List<java.lang.String> paths) throws java.io.IOException
paths
- list of file pathsjava.io.IOException
- if there is an issuepublic static java.util.List<java.io.File> createTestFiles(java.util.List<java.lang.String> paths, int minSize, int maxSize) throws java.io.IOException
paths
- list of file pathsminSize
- minimum file size in bytesmaxSize
- maximum file size in bytesjava.io.IOException
- if there is an issuepublic static void writeRandomFile(java.io.File file, int minSize, int maxSize) throws java.io.IOException
file
- file to write data tominSize
- minimum number of bytes to writemaxSize
- maximum number of bytes to writejava.io.IOException
- if there is an issuepublic static void tweakBytes(java.util.Random random, byte[] data, int count)
random
- random number generatordata
- byte array to be tweakedcount
- number of bytes to tweakpublic static void tweakBytes(java.util.Random random, byte[] data, int count, int start, int end)
random
- random number generatordata
- byte array to be tweakedcount
- number of bytes to tweakstart
- index at beginning of range (inclusive)end
- index at end of range (exclusive)public static int findAvailablePort(int defaultPort)