Class ServerRule
java.lang.Object
org.junit.rules.ExternalResource
com.linecorp.armeria.testing.junit4.server.ServerRule
- All Implemented Interfaces:
TestRule
public abstract class ServerRule extends ExternalResource
A
TestRule that allows easy set-up and tear-down of a Server.-
Constructor Summary
Constructors Modifier Constructor Description protectedServerRule()Creates a new instance with auto-start enabled.protectedServerRule(boolean autoStart)Creates a new instance. -
Method Summary
Modifier and Type Method Description protected voidafter()Callsstop(), without waiting until theServeris stopped completely.protected voidbefore()Callsstart()if auto-start is enabled.protected abstract voidconfigure(com.linecorp.armeria.server.ServerBuilder sb)Configures theServerwith the givenServerBuilder.com.linecorp.armeria.client.Endpointendpoint(com.linecorp.armeria.common.SessionProtocol protocol)Returns theEndpointof the specifiedSessionProtocolfor theServer.booleanhasHttp()Returnstrueif theServeris started and it has an HTTP port open.booleanhasHttps()Returnstrueif theServeris started and it has an HTTPS port open.com.linecorp.armeria.client.EndpointhttpEndpoint()Returns the HTTPEndpointfor theServer.inthttpPort()Returns the HTTP port number of theServer.com.linecorp.armeria.client.EndpointhttpsEndpoint()Returns the HTTPSEndpointfor theServer.InetSocketAddresshttpSocketAddress()Returns the HTTPInetSocketAddressof theServer.inthttpsPort()Returns the HTTPS port number of theServer.InetSocketAddresshttpsSocketAddress()Returns the HTTPSInetSocketAddressof theServer.URIhttpsUri()Returns the HTTPSURIfor theServer.URIhttpsUri(com.linecorp.armeria.common.SerializationFormat format)Returns the HTTPSURIfor theServer.URIhttpUri()Returns the HTTPURIfor theServer.URIhttpUri(com.linecorp.armeria.common.SerializationFormat format)Returns the HTTPURIfor theServer.intport(com.linecorp.armeria.common.SessionProtocol protocol)Returns the port number of theServerfor the specifiedSessionProtocol.com.linecorp.armeria.server.Serverserver()Returns the startedServer.InetSocketAddresssocketAddress(com.linecorp.armeria.common.SessionProtocol protocol)com.linecorp.armeria.server.Serverstart()Starts theServerconfigured byconfigure(ServerBuilder).CompletableFuture<Void>stop()Stops theServerasynchronously.URIuri(com.linecorp.armeria.common.SessionProtocol protocol)URIuri(com.linecorp.armeria.common.SessionProtocol protocol, com.linecorp.armeria.common.SerializationFormat format)Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
ServerRule
protected ServerRule()Creates a new instance with auto-start enabled. -
ServerRule
protected ServerRule(boolean autoStart)Creates a new instance.- Parameters:
autoStart-trueif theServershould start automatically.falseif theServershould start when a user callsstart().
-
-
Method Details
-
before
Callsstart()if auto-start is enabled.- Overrides:
beforein classExternalResource- Throws:
Throwable
-
after
protected void after()Callsstop(), without waiting until theServeris stopped completely.- Overrides:
afterin classExternalResource
-
start
public com.linecorp.armeria.server.Server start()Starts theServerconfigured byconfigure(ServerBuilder). If theServerhas been started up already, the existingServeris returned. Note that this operation blocks until theServerfinished the start-up.- Returns:
- the started
Server
-
configure
Configures theServerwith the givenServerBuilder.- Throws:
Exception
-
stop
Stops theServerasynchronously.- Returns:
- the
CompletableFuturethat will complete when theServeris stopped.
-
server
public com.linecorp.armeria.server.Server server()Returns the startedServer.- Throws:
IllegalStateException- if theServeris not started
-
httpPort
public int httpPort()Returns the HTTP port number of theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port
-
httpsPort
public int httpsPort()Returns the HTTPS port number of theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port
-
port
public int port(com.linecorp.armeria.common.SessionProtocol protocol)Returns the port number of theServerfor the specifiedSessionProtocol.- Throws:
IllegalStateException- if theServeris not started or it did not open a port of the specified protocol.
-
hasHttp
public boolean hasHttp()Returnstrueif theServeris started and it has an HTTP port open. -
hasHttps
public boolean hasHttps()Returnstrueif theServeris started and it has an HTTPS port open. -
endpoint
public com.linecorp.armeria.client.Endpoint endpoint(com.linecorp.armeria.common.SessionProtocol protocol)Returns theEndpointof the specifiedSessionProtocolfor theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open the port for the specifiedSessionProtocol.
-
httpEndpoint
public com.linecorp.armeria.client.Endpoint httpEndpoint()Returns the HTTPEndpointfor theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port.
-
httpsEndpoint
public com.linecorp.armeria.client.Endpoint httpsEndpoint()Returns the HTTPSEndpointfor theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port.
-
uri
- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open the port for the specifiedSessionProtocol.
-
uri
public URI uri(com.linecorp.armeria.common.SessionProtocol protocol, com.linecorp.armeria.common.SerializationFormat format)- Throws:
IllegalStateException- if theServeris not started or it did not open the port for the specifiedSessionProtocol.
-
httpUri
Returns the HTTPURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port.
-
httpUri
Returns the HTTPURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port.
-
httpsUri
Returns the HTTPSURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port.
-
httpsUri
Returns the HTTPSURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port.
-
socketAddress
- Throws:
IllegalStateException- if theServeris not started or it did not open a port for the specifiedSessionProtocol.
-
httpSocketAddress
Returns the HTTPInetSocketAddressof theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port
-
httpsSocketAddress
Returns the HTTPSInetSocketAddressof theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port
-