public class JunitHelper
extends org.junit.rules.ExternalResource
Modifier and Type | Field and Description |
---|---|
static int |
MIN_PORT |
static String |
PARAMETER_JETTY_SERVER_PORT_ADMIN |
Modifier and Type | Method and Description |
---|---|
static void |
awaitFullGc()
For benchmark: clean the used memory using a full GC.
Usage:
JunitHelper.awaitFullGc();
long firstAvailableMemory = Runtime.getRuntime().freeMemory();
...
|
static long |
consumeInputStream(InputStream inputStream)
Read and close the inputStream using buffer read (read(buffer))
|
static long |
consumeInputStreamPerByte(InputStream inputStream)
Read and close the inputStream one byte at a time (read())
|
int |
findAvailablePort() |
int |
findAvailablePort(String environmentVariable) |
static JunitHelper |
getInstance() |
boolean |
isListeningOn(int port) |
boolean |
isListeningOn(String host,
int port) |
void |
releasePort(int port)
Remove the used port
|
static void |
setJettyPortSystemProperty(String environmentVariable,
int port)
Set JettyPort System Property
|
static void |
testPrivateConstructor(Class<?> clasz)
Utility to check empty private constructor
|
static void |
unsetJettyPortSystemProperty()
Unset JettyPort System Property
|
public static final int MIN_PORT
public static final String PARAMETER_JETTY_SERVER_PORT_ADMIN
public static final JunitHelper getInstance()
public final int findAvailablePort()
IllegalStateException
- if no port availablepublic final int findAvailablePort(String environmentVariable)
environmentVariable
- if not null, set the port nomber in the system environmentIllegalStateException
- if no port availablepublic final void releasePort(int port)
port
- to releasepublic final boolean isListeningOn(int port)
port
- the port to check on localhostIllegalArgumentException
- if the port is not between 1 and 65535public final boolean isListeningOn(String host, int port)
host
- the host to checkport
- the port to check on hostIllegalArgumentException
- if the port is not between 1 and 65535public static final long consumeInputStream(InputStream inputStream)
inputStream
- to read and closepublic static final long consumeInputStreamPerByte(InputStream inputStream)
inputStream
- to read and closepublic static final void awaitFullGc()
public static final void setJettyPortSystemProperty(String environmentVariable, int port)
environmentVariable
- port
- set to jetty serverpublic static final void unsetJettyPortSystemProperty()
public static final void testPrivateConstructor(Class<?> clasz)
clasz
- class templateCopyright © 2019 Vitam. All rights reserved.