public class JunitHelper
extends org.junit.rules.ExternalResource
Modifier and Type | Class and Description |
---|---|
static class |
JunitHelper.ElasticsearchTestConfiguration
Class to help to build and stop an Elasticsearch server
|
Modifier and Type | Field and Description |
---|---|
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) |
VitamApplicationTestFactory.StartApplicationResponse<?> |
findAvailablePortSetToApplication(VitamApplicationTestFactory<?> testFactory)
Find an available port, set the Property jetty.port and call the factory to start the application in one
synchronized step.
|
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 JunitHelper.ElasticsearchTestConfiguration |
startElasticsearchForTest(org.junit.rules.TemporaryFolder tempFolder,
String clusterName)
Helper to start an Elasticsearch server (recommended version)
|
static JunitHelper.ElasticsearchTestConfiguration |
startElasticsearchForTest(org.junit.rules.TemporaryFolder tempFolder,
String clusterName,
int tcpPort,
int httpPort)
Helper to start an Elasticsearch server (unrecommended version)
|
static void |
stopElasticsearchForTest(JunitHelper.ElasticsearchTestConfiguration config)
Stop the Elasticsearch server started through start ElasticsearchForTest
|
static void |
testPrivateConstructor(Class<?> clasz)
Utility to check empty private constructor
|
static void |
unsetJettyPortSystemProperty()
Unset JettyPort System Property
|
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 VitamApplicationTestFactory.StartApplicationResponse<?> findAvailablePortSetToApplication(VitamApplicationTestFactory<?> testFactory)
testFactory
- the VitamApplicationTestFactory
to useIllegalStateException
- 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 templatepublic static final JunitHelper.ElasticsearchTestConfiguration startElasticsearchForTest(org.junit.rules.TemporaryFolder tempFolder, String clusterName, int tcpPort, int httpPort) throws VitamApplicationServerException
tempFolder
- the TemporaryFolder declared as ClassRule within the Junit classclusterName
- the cluster nametcpPort
- the given TcpPorthttpPort
- the given HttpPortVitamApplicationServerException
- if the Elasticsearch server cannot be startedpublic static final JunitHelper.ElasticsearchTestConfiguration startElasticsearchForTest(org.junit.rules.TemporaryFolder tempFolder, String clusterName) throws VitamApplicationServerException
tempFolder
- the TemporaryFolder declared as ClassRule within the Junit classclusterName
- the cluster nameVitamApplicationServerException
- if the Elasticsearch server cannot be startedpublic static final void stopElasticsearchForTest(JunitHelper.ElasticsearchTestConfiguration config)
config
- the ElasticsearchTestConfigurationCopyright © 2018 Vitam. All rights reserved.