Class MockOtlpReceiver

java.lang.Object
jline.streaming.MockOtlpReceiver

public class MockOtlpReceiver extends Object
Mock OTLP gRPC receiver for testing streaming functionality.

This mock server implements the OTLP MetricsService and captures all received metrics for verification in tests.

  • Constructor Details

    • MockOtlpReceiver

      public MockOtlpReceiver() throws IOException
      Creates a mock OTLP receiver on a random available port.
      Throws:
      IOException - if unable to find an available port or start the server
  • Method Details

    • start

      public void start() throws IOException
      Starts the mock receiver.
      Throws:
      IOException - if the server cannot be started
    • waitUntilReady

      public void waitUntilReady(long timeoutMs)
      Waits until the server is ready to accept connections. This is important in some JVM environments (like MATLAB) where the server may not be immediately ready after start() returns.
      Parameters:
      timeoutMs - maximum time to wait in milliseconds
    • stop

      public void stop()
      Stops the mock receiver gracefully.
    • getPort

      public int getPort()
      Gets the port this receiver is listening on.
      Returns:
      the port number
    • getEndpoint

      public String getEndpoint()
      Gets the endpoint string for this receiver (localhost:port).
      Returns:
      endpoint string
    • getRequestCount

      public int getRequestCount()
      Gets the total number of export requests received.
      Returns:
      number of requests
    • getTotalMetricCount

      public int getTotalMetricCount()
      Gets the total number of metrics received across all requests.
      Returns:
      total metric count
    • getReceivedMetricNames

      public List<String> getReceivedMetricNames()
      Gets all metric names received.
      Returns:
      list of metric names
    • getReceivedRequests

      public List<io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest> getReceivedRequests()
      Gets all received export requests.
      Returns:
      list of requests
    • reset

      public void reset()
      Clears all received data.
    • hasReceivedMetric

      public boolean hasReceivedMetric(String metricName)
      Checks if a specific metric type was received.
      Parameters:
      metricName - the metric name to check (e.g., "queue_length", "throughput")
      Returns:
      true if at least one metric with that name was received