Class MockHttpReceiver
-
- All Implemented Interfaces:
public class MockHttpReceiverMock HTTP receiver for testing streaming functionality. Uses Java's built-in HttpServer for maximum compatibility. Receives JSON metrics via HTTP POST and captures them for verification.
-
-
Field Summary
Fields Modifier and Type Field Description public final intport
-
Constructor Summary
Constructors Constructor Description MockHttpReceiver()Creates a mock HTTP 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. voidstop()Stops the mock receiver gracefully. StringgetEndpoint()Gets the endpoint string for this receiver. intgetRequestCount()Gets the total number of POST requests received. intgetTotalMetricCount()Gets the total number of metrics received across all requests. List<String>getReceivedMetricNames()Gets all metric names received. List<String>getReceivedPayloads()Gets all received JSON payloads. booleanhasReceivedMetric(String metricName)Checks if a specific metric type was received. voidreset()Clears all received data. -
-
Method Detail
-
getPort
int getPort()
Gets the port this receiver is listening on.
- Returns:
the port number
-
start
void start()
Starts the mock receiver.
-
stop
void stop()
Stops the mock receiver gracefully.
-
getEndpoint
String getEndpoint()
Gets the endpoint string for this receiver.
- Returns:
endpoint string (e.g., "http://localhost:12345/metrics")
-
getRequestCount
int getRequestCount()
Gets the total number of POST 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
-
getReceivedPayloads
List<String> getReceivedPayloads()
Gets all received JSON payloads.
- Returns:
list of JSON strings
-
hasReceivedMetric
boolean hasReceivedMetric(String metricName)
Checks if a specific metric type was received.
- Parameters:
metricName- the metric name to check- Returns:
true if at least one metric with that name was received
-
reset
void reset()
Clears all received data.
-
-
-
-