Class MockApmServer

java.lang.Object
org.elasticsearch.gradle.testclusters.MockApmServer

public class MockApmServer extends Object
This is a server which just accepts lines of JSON code and if the JSON is valid and the root node is "transaction", then adds that JSON object to a transaction list which is accessible externally to the class.

The Elastic agent sends lines of JSON code, and so this mock server can be used as a basic APM server for testing.

The HTTP server used is the JDK embedded com.sun.net.httpserver

  • Constructor Details

    • MockApmServer

      public MockApmServer(int port)
  • Method Details

    • main

      public static void main(String[] args) throws IOException, InterruptedException
      Simple main that starts a mock APM server and prints the port it is running on. This is not needed for testing, it is just a convenient template for trying things out if you want play around.
      Throws:
      IOException
      InterruptedException
    • start

      public int start() throws IOException
      Start the Mock APM server. Just returns empty JSON structures for every incoming message
      Returns:
      - the port the Mock APM server started on
      Throws:
      IOException
    • getPort

      public int getPort()
    • stop

      public void stop()
      Stop the server gracefully if possible