Package jline.streaming
Class MockOtlpReceiver
java.lang.Object
jline.streaming.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the endpoint string for this receiver (localhost:port).intgetPort()Gets the port this receiver is listening on.Gets all metric names received.List<io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest> Gets all received export requests.intGets the total number of export requests received.intGets the total number of metrics received across all requests.booleanhasReceivedMetric(String metricName) Checks if a specific metric type was received.voidreset()Clears all received data.voidstart()Starts the mock receiver.voidstop()Stops the mock receiver gracefully.voidwaitUntilReady(long timeoutMs) Waits until the server is ready to accept connections.
-
Constructor Details
-
MockOtlpReceiver
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
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
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
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
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
-