Class ServerRule
java.lang.Object
org.junit.rules.ExternalResource
com.linecorp.armeria.testing.junit4.server.ServerRule
- All Implemented Interfaces:
TestRule
A
TestRule that allows easy set-up and tear-down of a Server.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance with auto-start enabled.protectedServerRule(boolean autoStart) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafter()Callsstop(), without waiting until theServeris stopped completely.protected voidbefore()Callsstart()if auto-start is enabled.com.linecorp.armeria.client.BlockingWebClientReturns theBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder).com.linecorp.armeria.client.BlockingWebClientblockingWebClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.protected abstract voidconfigure(com.linecorp.armeria.server.ServerBuilder sb) Configures theServerwith the givenServerBuilder.protected voidconfigureWebClient(com.linecorp.armeria.client.WebClientBuilder webClientBuilder) Configures theWebClientwith the givenWebClientBuilder.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.EndpointReturns the HTTPEndpointfor theServer.inthttpPort()Returns the HTTP port number of theServer.com.linecorp.armeria.client.EndpointReturns the HTTPSEndpointfor theServer.Returns the HTTPInetSocketAddressof theServer.intReturns the HTTPS port number of theServer.Returns the HTTPSInetSocketAddressof theServer.httpsUri()Returns the HTTPSURIfor theServer.httpsUri(com.linecorp.armeria.common.SerializationFormat format) Returns the HTTPSURIfor theServer.httpUri()Returns the HTTPURIfor theServer.httpUri(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.client.RestClientReturns theRestClientconfigured byconfigureWebClient(WebClientBuilder).com.linecorp.armeria.client.RestClientrestClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdRestClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.com.linecorp.armeria.server.Serverserver()Returns the startedServer.socketAddress(com.linecorp.armeria.common.SessionProtocol protocol) com.linecorp.armeria.server.Serverstart()Starts theServerconfigured byconfigure(ServerBuilder).stop()Stops theServerasynchronously.uri(com.linecorp.armeria.common.SessionProtocol protocol) uri(com.linecorp.armeria.common.SessionProtocol protocol, com.linecorp.armeria.common.SerializationFormat format) com.linecorp.armeria.client.WebClientReturns theWebClientconfigured byconfigureWebClient(WebClientBuilder).com.linecorp.armeria.client.WebClientReturna a newly createdWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.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
-
configureWebClient
protected void configureWebClient(com.linecorp.armeria.client.WebClientBuilder webClientBuilder) throws Exception Configures theWebClientwith the givenWebClientBuilder. You can get the configuredWebClientusingwebClient().- 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
-
webClient
public com.linecorp.armeria.client.WebClient webClient()Returns theWebClientconfigured byconfigureWebClient(WebClientBuilder). -
webClient
public com.linecorp.armeria.client.WebClient webClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returna a newly createdWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer. -
blockingWebClient
@UnstableApi public com.linecorp.armeria.client.BlockingWebClient blockingWebClient()Returns theBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder). -
blockingWebClient
@UnstableApi public com.linecorp.armeria.client.BlockingWebClient blockingWebClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer. -
restClient
@UnstableApi public com.linecorp.armeria.client.RestClient restClient()Returns theRestClientconfigured byconfigureWebClient(WebClientBuilder). -
restClient
@UnstableApi public com.linecorp.armeria.client.RestClient restClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdRestClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.
-