Class MockOtlpReceiver
-
- All Implemented Interfaces:
public class MockOtlpReceiverMock OTLP gRPC receiver for testing streaming functionality.
This mock server implements the OTLP MetricsService and captures all received metrics for verification in tests.
-
-
Field Summary
Fields Modifier and Type Field Description public final intport
-
Constructor Summary
Constructors Constructor Description MockOtlpReceiver()Creates a mock OTLP receiver on a random available port.
-
Method Summary
Modifier and Type Method Description intgetPort()Gets the port this receiver is listening on. voidstart()Starts the mock receiver. voidwaitUntilReady(long timeoutMs)Waits until the server is ready to accept connections. voidstop()Stops the mock receiver gracefully. StringgetEndpoint()Gets the endpoint string for this receiver (localhost:port). intgetRequestCount()Gets the total number of export requests received. intgetTotalMetricCount()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. voidreset()Clears all received data. booleanhasReceivedMetric(String metricName)Checks if a specific metric type was received. -
-
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
-
getReceivedMetricNames
List<String> getReceivedMetricNames()
Gets all metric names received.
- Returns:
list of metric names
-
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
-
-
-
-