2929import org .apache .flink .metrics .util .TestMeter ;
3030import org .apache .flink .util .PortRange ;
3131
32- import com .mashape .unirest .http .HttpResponse ;
33- import com .mashape .unirest .http .Unirest ;
34- import com .mashape .unirest .http .exceptions .UnirestException ;
3532import org .junit .jupiter .api .AfterEach ;
3633import org .junit .jupiter .api .BeforeEach ;
3734import org .junit .jupiter .api .Test ;
3835
36+ import java .io .IOException ;
37+ import java .net .URI ;
38+ import java .net .http .HttpClient ;
39+ import java .net .http .HttpRequest ;
40+ import java .net .http .HttpResponse ;
3941import java .util .Arrays ;
4042import java .util .HashMap ;
4143import java .util .Map ;
@@ -58,6 +60,7 @@ class PrometheusReporterTest {
5860 private static final String DEFAULT_LABELS = "{" + DIMENSIONS + ",}" ;
5961 private static final String SCOPE_PREFIX =
6062 PrometheusReporter .SCOPE_PREFIX + LOGICAL_SCOPE + PrometheusReporter .SCOPE_SEPARATOR ;
63+ private static final HttpClient HTTP_CLIENT = HttpClient .newHttpClient ();
6164
6265 private static final PortRangeProvider portRangeProvider = new PortRangeProvider ();
6366
@@ -85,45 +88,46 @@ void teardown() throws Exception {
8588 * {@link io.prometheus.client.Counter} may not decrease, so report {@link Counter} as {@link
8689 * io.prometheus.client.Gauge}.
8790 *
88- * @throws UnirestException Might be thrown on HTTP problems.
91+ * @throws IOException Might be thrown on I/O problems.
92+ * @throws InterruptedException Might be thrown if the thread is interrupted.
8993 */
9094 @ Test
91- void counterIsReportedAsPrometheusGauge () throws UnirestException {
95+ void counterIsReportedAsPrometheusGauge () throws IOException , InterruptedException {
9296 Counter testCounter = new SimpleCounter ();
9397 testCounter .inc (7 );
9498
9599 assertThatGaugeIsExported (testCounter , "testCounter" , "7.0" );
96100 }
97101
98102 @ Test
99- void gaugeIsReportedAsPrometheusGauge () throws UnirestException {
103+ void gaugeIsReportedAsPrometheusGauge () throws IOException , InterruptedException {
100104 Gauge <Integer > testGauge = () -> 1 ;
101105
102106 assertThatGaugeIsExported (testGauge , "testGauge" , "1.0" );
103107 }
104108
105109 @ Test
106- void nullGaugeDoesNotBreakReporter () throws UnirestException {
110+ void nullGaugeDoesNotBreakReporter () throws IOException , InterruptedException {
107111 Gauge <Integer > testGauge = () -> null ;
108112
109113 assertThatGaugeIsExported (testGauge , "testGauge" , "0.0" );
110114 }
111115
112116 @ Test
113- void meterRateIsReportedAsPrometheusGauge () throws UnirestException {
117+ void meterRateIsReportedAsPrometheusGauge () throws IOException , InterruptedException {
114118 Meter testMeter = new TestMeter ();
115119
116120 assertThatGaugeIsExported (testMeter , "testMeter" , "5.0" );
117121 }
118122
119123 private void assertThatGaugeIsExported (Metric metric , String name , String expectedValue )
120- throws UnirestException {
124+ throws IOException , InterruptedException {
121125 assertThat (addMetricAndPollResponse (metric , name ))
122126 .contains (createExpectedPollResponse (name , "" , "gauge" , expectedValue ));
123127 }
124128
125129 @ Test
126- void histogramIsReportedAsPrometheusSummary () throws UnirestException {
130+ void histogramIsReportedAsPrometheusSummary () throws IOException , InterruptedException {
127131 Histogram testHistogram = new TestHistogram ();
128132
129133 String histogramName = "testHistogram" ;
@@ -152,7 +156,8 @@ void histogramIsReportedAsPrometheusSummary() throws UnirestException {
152156 * name still exist.
153157 */
154158 @ Test
155- void metricIsRemovedWhileOtherMetricsWithSameNameExist () throws UnirestException {
159+ void metricIsRemovedWhileOtherMetricsWithSameNameExist ()
160+ throws IOException , InterruptedException {
156161 String metricName = "metric" ;
157162
158163 Counter metric1 = new SimpleCounter ();
@@ -168,7 +173,7 @@ void metricIsRemovedWhileOtherMetricsWithSameNameExist() throws UnirestException
168173 reporter .notifyOfAddedMetric (metric2 , metricName , metricGroup2 );
169174 reporter .notifyOfRemovedMetric (metric1 , metricName , metricGroup );
170175
171- String response = pollMetrics (reporter .getPort ()).getBody ();
176+ String response = pollMetrics (reporter .getPort ()).body ();
172177
173178 assertThat (response ).contains ("some_value" ).doesNotContain (labelValueThatShouldBeRemoved );
174179 }
@@ -239,13 +244,18 @@ void canStartTwoReportersWhenUsingPortRange() {
239244 }
240245
241246 private String addMetricAndPollResponse (Metric metric , String metricName )
242- throws UnirestException {
247+ throws IOException , InterruptedException {
243248 reporter .notifyOfAddedMetric (metric , metricName , metricGroup );
244- return pollMetrics (reporter .getPort ()).getBody ();
249+ return pollMetrics (reporter .getPort ()).body ();
245250 }
246251
247- static HttpResponse <String > pollMetrics (int port ) throws UnirestException {
248- return Unirest .get ("http://localhost:" + port + "/metrics" ).asString ();
252+ static HttpResponse <String > pollMetrics (int port ) throws IOException , InterruptedException {
253+ HttpRequest request =
254+ HttpRequest .newBuilder ()
255+ .uri (URI .create ("http://localhost:" + port + "/metrics" ))
256+ .GET ()
257+ .build ();
258+ return HTTP_CLIENT .send (request , HttpResponse .BodyHandlers .ofString ());
249259 }
250260
251261 private static String createExpectedPollResponse (
0 commit comments