24
24
import org .testcontainers .containers .GenericContainer ;
25
25
import org .testcontainers .utility .MountableFile ;
26
26
27
- import java .net .HttpURLConnection ;
28
- import java .net .URI ;
29
- import java .net .http .HttpClient ;
30
- import java .net .http .HttpRequest ;
31
- import java .net .http .HttpResponse ;
32
27
import java .util .ArrayList ;
33
28
import java .util .HashMap ;
34
29
import java .util .List ;
35
30
import java .util .Map ;
36
31
37
32
import static io .strimzi .kafka .metrics .prometheus .ClientMetricsReporterConfig .ALLOWLIST_CONFIG ;
38
- import static org .junit .jupiter .api .Assertions .assertEquals ;
39
33
import static org .junit .jupiter .api .Assertions .assertFalse ;
40
34
import static org .junit .jupiter .api .Assertions .assertTrue ;
41
35
@@ -158,7 +152,7 @@ private void setupConnect(Map<String, String> overrides) {
158
152
}
159
153
160
154
@ Test
161
- public void testConnectMetrics () throws Exception {
155
+ public void testConnectMetrics () {
162
156
setupConnect (Map .of (
163
157
"consumer.metric.reporters" , ClientMetricsReporter .class .getName (),
164
158
"producer.metric.reporters" , ClientMetricsReporter .class .getName (),
@@ -175,7 +169,7 @@ public void testConnectMetrics() throws Exception {
175
169
" \" topics\" : \" " + TOPIC + "\" ,\n " +
176
170
" \" file\" : \" " + FILE + "\" \n " +
177
171
"}" ;
178
- httpPut ( "/connectors/" + SINK_CONNECTOR + "/config" , connectorConfig );
172
+ MetricsUtils . startConnector ( connect , SINK_CONNECTOR , connectorConfig );
179
173
checkMetricsExist (SINK_PATTERNS );
180
174
181
175
// Start a source connector metrics and check its metrics
@@ -185,12 +179,12 @@ public void testConnectMetrics() throws Exception {
185
179
" \" topic\" : \" " + TOPIC + "\" ,\n " +
186
180
" \" file\" : \" " + FILE + "\" \n " +
187
181
"}" ;
188
- httpPut ( "/connectors/" + SOURCE_CONNECTOR + "/config" , connectorConfig );
182
+ MetricsUtils . startConnector ( connect , SOURCE_CONNECTOR , connectorConfig );
189
183
checkMetricsExist (SOURCE_PATTERNS );
190
184
}
191
185
192
186
@ Test
193
- public void testConnectMetricsWithAllowlist () throws Exception {
187
+ public void testConnectMetricsWithAllowlist () {
194
188
setupConnect (Map .of (
195
189
"consumer.metric.reporters" , ClientMetricsReporter .class .getName (),
196
190
"producer.metric.reporters" , ClientMetricsReporter .class .getName (),
@@ -223,7 +217,7 @@ public void testConnectMetricsWithAllowlist() throws Exception {
223
217
" \" topics\" : \" " + TOPIC + "\" ,\n " +
224
218
" \" file\" : \" " + FILE + "\" \n " +
225
219
"}" ;
226
- httpPut ( "/connectors/" + SINK_CONNECTOR + "/config" , connectorConfig );
220
+ MetricsUtils . startConnector ( connect , SINK_CONNECTOR , connectorConfig );
227
221
List <String > allowedSinkPatterns = List .of (
228
222
"kafka_connect_connector_metrics_.*" + SINK_CONNECTOR_PATTERN ,
229
223
"kafka_connect_connect_worker_metrics_connector_count 1.0" ,
@@ -241,7 +235,7 @@ public void testConnectMetricsWithAllowlist() throws Exception {
241
235
" \" topic\" : \" " + TOPIC + "\" ,\n " +
242
236
" \" file\" : \" " + FILE + "\" \n " +
243
237
"}" ;
244
- httpPut ( "/connectors/" + SOURCE_CONNECTOR + "/config" , connectorConfig );
238
+ MetricsUtils . startConnector ( connect , SOURCE_CONNECTOR , connectorConfig );
245
239
List <String > allowedSourcePatterns = List .of (
246
240
"kafka_connect_connector_metrics_.*" + SOURCE_CONNECTOR_PATTERN ,
247
241
"kafka_connect_connect_worker_metrics_connector_count 2.0" ,
@@ -264,16 +258,4 @@ private void checkMetricsDontExist(List<String> patterns) {
264
258
MetricsUtils .verify (worker , patterns , PORT , metrics -> assertTrue (metrics .isEmpty ()));
265
259
}
266
260
}
267
-
268
- private void httpPut (String path , String body ) throws Exception {
269
- HttpClient httpClient = HttpClient .newHttpClient ();
270
- URI uri = new URI (connect .getRestEndpoint () + path );
271
- HttpRequest request = HttpRequest .newBuilder ()
272
- .PUT (HttpRequest .BodyPublishers .ofString (body ))
273
- .setHeader ("Content-Type" , "application/json" )
274
- .uri (uri )
275
- .build ();
276
- HttpResponse <String > response = httpClient .send (request , HttpResponse .BodyHandlers .ofString ());
277
- assertEquals (HttpURLConnection .HTTP_CREATED , response .statusCode ());
278
- }
279
261
}
0 commit comments