Class MockOtlpReceiver

  • All Implemented Interfaces:

    
    public class MockOtlpReceiver
    
                        

    Mock OTLP gRPC receiver for testing streaming functionality.

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

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final int port
    • Constructor Summary

      Constructors 
      Constructor Description
      MockOtlpReceiver() Creates a mock OTLP receiver on a random available port.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int getPort() Gets the port this receiver is listening on.
      void start() Starts the mock receiver.
      void waitUntilReady(long timeoutMs) Waits until the server is ready to accept connections.
      void stop() Stops the mock receiver gracefully.
      String getEndpoint() Gets the endpoint string for this receiver (localhost:port).
      int getRequestCount() Gets the total number of export requests received.
      int getTotalMetricCount() Gets the total number of metrics received across all requests.
      List<String> getReceivedMetricNames() Gets all metric names received.
      List<ExportMetricsServiceRequest> getReceivedRequests() Gets all received export requests.
      void reset() Clears all received data.
      boolean hasReceivedMetric(String metricName) Checks if a specific metric type was received.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MockOtlpReceiver

        MockOtlpReceiver()
        Creates a mock OTLP receiver on a random available port.
    • Method Detail

      • getPort

         int getPort()

        Gets the port this receiver is listening on.

        Returns:

        the port number

      • start

         void start()

        Starts the mock receiver.

      • waitUntilReady

         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

         void stop()

        Stops the mock receiver gracefully.

      • getEndpoint

         String getEndpoint()

        Gets the endpoint string for this receiver (localhost:port).

        Returns:

        endpoint string

      • getRequestCount

         int getRequestCount()

        Gets the total number of export requests received.

        Returns:

        number of requests

      • getTotalMetricCount

         int getTotalMetricCount()

        Gets the total number of metrics received across all requests.

        Returns:

        total metric count

      • getReceivedRequests

         List<ExportMetricsServiceRequest> getReceivedRequests()

        Gets all received export requests.

        Returns:

        list of requests

      • reset

         void reset()

        Clears all received data.

      • hasReceivedMetric

         boolean hasReceivedMetric(String metricName)

        Checks if a specific metric type was received.

        Parameters:
        metricName - the metric name to check (e.g.
        Returns:

        true if at least one metric with that name was received