Class LocalConnector

All Implemented Interfaces:
Connector, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, Graceful, LifeCycle

public class LocalConnector extends AbstractConnector
A local connector, mostly for testing purposes.
  HttpTester.Request request = HttpTester.newRequest();
  request.setURI("/some/resource");
  HttpTester.Response response =
      HttpTester.parseResponse(HttpTester.from(localConnector.getResponse(request.generate())));
 
  • Field Details

  • Constructor Details

  • Method Details

    • getTransport

      public Object getTransport()
      Returns:
      the underlying socket, channel, buffer etc. for the connector.
    • getResponses

      @Deprecated public String getResponses(String requests) throws Exception
      Deprecated.
      Sends requests and get responses based on thread activity. Returns all the responses received once the thread activity has returned to the level it was before the requests.

      This methods waits until the connection is closed or is idle for 5s before returning the responses.

      Use getResponse(String) for an alternative that does not wait for idle.

      Parameters:
      requests - the requests
      Returns:
      the responses
      Throws:
      Exception - if the requests fail
    • getResponses

      @Deprecated public String getResponses(String requests, long idleFor, TimeUnit units) throws Exception
      Sends requests and get responses based on thread activity. Returns all the responses received once the thread activity has returned to the level it was before the requests.

      This methods waits until the connection is closed or an idle period before returning the responses.

      Use getResponse(String) for an alternative that does not wait for idle.

      Parameters:
      requests - the requests
      idleFor - The time the response stream must be idle for before returning
      units - The units of idleFor
      Returns:
      the responses
      Throws:
      Exception - if the requests fail
    • getResponses

      @Deprecated public ByteBuffer getResponses(ByteBuffer requestsBuffer) throws Exception
      Deprecated.
      Sends requests and get's responses based on thread activity. Returns all the responses received once the thread activity has returned to the level it was before the requests.

      This methods waits until the connection is closed or is idle for 5s before returning the responses.

      Use getResponse(ByteBuffer) for an alternative that does not wait for idle.

      Parameters:
      requestsBuffer - the requests
      Returns:
      the responses
      Throws:
      Exception - if the requests fail
    • getResponses

      @Deprecated public ByteBuffer getResponses(ByteBuffer requestsBuffer, long idleFor, TimeUnit units) throws Exception
      Sends requests and get's responses based on thread activity. Returns all the responses received once the thread activity has returned to the level it was before the requests.

      This methods waits until the connection is closed or an idle period before returning the responses.

      Parameters:
      requestsBuffer - the requests
      idleFor - The time the response stream must be idle for before returning
      units - The units of idleFor
      Returns:
      the responses
      Throws:
      Exception - if the requests fail
    • executeRequest

      public LocalConnector.LocalEndPoint executeRequest(String rawRequest)
      Execute a request and return the EndPoint through which multiple responses can be received or more input provided.
      Parameters:
      rawRequest - the request
      Returns:
      the local endpoint
    • executeRequest

      private LocalConnector.LocalEndPoint executeRequest(ByteBuffer rawRequest)
    • connect

      public LocalConnector.LocalEndPoint connect()
    • accept

      protected void accept(int acceptorID) throws IOException, InterruptedException
      Specified by:
      accept in class AbstractConnector
      Throws:
      IOException
      InterruptedException
    • getResponse

      public ByteBuffer getResponse(ByteBuffer requestsBuffer) throws Exception
      Get a single response using a parser to search for the end of the message.
      Parameters:
      requestsBuffer - The request to send
      Returns:
      ByteBuffer containing response or null.
      Throws:
      Exception - If there is a problem
    • getResponse

      public ByteBuffer getResponse(ByteBuffer requestBuffer, long time, TimeUnit unit) throws Exception
      Get a single response using a parser to search for the end of the message.
      Parameters:
      requestBuffer - The request to send
      time - The time to wait
      unit - The units of the wait
      Returns:
      ByteBuffer containing response or null.
      Throws:
      Exception - If there is a problem
    • getResponse

      public ByteBuffer getResponse(ByteBuffer requestBuffer, boolean head, long time, TimeUnit unit) throws Exception
      Get a single response using a parser to search for the end of the message.
      Parameters:
      requestBuffer - The request to send
      head - True if the response is for a head request
      time - The time to wait
      unit - The units of the wait
      Returns:
      ByteBuffer containing response or null.
      Throws:
      Exception - If there is a problem
    • getResponse

      public String getResponse(String rawRequest) throws Exception
      Get a single response using a parser to search for the end of the message.
      Parameters:
      rawRequest - The request to send
      Returns:
      ByteBuffer containing response or null.
      Throws:
      Exception - If there is a problem
    • getResponse

      public String getResponse(String rawRequest, long time, TimeUnit unit) throws Exception
      Get a single response using a parser to search for the end of the message.
      Parameters:
      rawRequest - The request to send
      time - The time to wait
      unit - The units of the wait
      Returns:
      ByteBuffer containing response or null.
      Throws:
      Exception - If there is a problem
    • getResponse

      public String getResponse(String rawRequest, boolean head, long time, TimeUnit unit) throws Exception
      Get a single response using a parser to search for the end of the message.
      Parameters:
      rawRequest - The request to send
      head - True if the response is for a head request
      time - The time to wait
      unit - The units of the wait
      Returns:
      ByteBuffer containing response or null.
      Throws:
      Exception - If there is a problem