|
79 | 79 | import java.util.Properties; |
80 | 80 |
|
81 | 81 | import static org.junit.jupiter.api.Assertions.assertEquals; |
82 | | -import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
83 | 82 | import static org.junit.jupiter.api.Assertions.assertNotEquals; |
84 | | -import static org.junit.jupiter.api.Assertions.fail; |
| 83 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
85 | 84 | import static org.mockito.ArgumentMatchers.any; |
86 | 85 | import static org.mockito.ArgumentMatchers.argThat; |
87 | 86 | import static org.mockito.Mockito.mock; |
@@ -111,7 +110,7 @@ public KafkaPrincipal deserialize(byte[] bytes) throws SerializationException { |
111 | 110 | .setSecurityProtocol(SecurityProtocol.PLAINTEXT.id); |
112 | 111 |
|
113 | 112 | @Test |
114 | | - void testDescribeTopicPartitionsRequest() { |
| 113 | + void testDescribeTopicPartitionsRequest() throws Exception { |
115 | 114 | // 1. Set up authorizer |
116 | 115 | Authorizer authorizer = mock(Authorizer.class); |
117 | 116 | Plugin<Authorizer> authorizerPlugin = Plugin.wrapInstance(authorizer, null, "authorizer.class.name"); |
@@ -202,13 +201,7 @@ void testDescribeTopicPartitionsRequest() { |
202 | 201 | new DescribeTopicPartitionsRequestData.TopicRequest().setName(unauthorizedTopic) |
203 | 202 | )) |
204 | 203 | ); |
205 | | - Request request; |
206 | | - try { |
207 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
208 | | - } catch (Exception e) { |
209 | | - fail(e.getMessage()); |
210 | | - return; |
211 | | - } |
| 204 | + Request request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
212 | 205 | DescribeTopicPartitionsResponseData response = handler.handleDescribeTopicPartitionsRequest(request); |
213 | 206 | List<DescribeTopicPartitionsResponseTopic> topics = response.topics().valuesList(); |
214 | 207 | assertEquals(2, topics.size()); |
@@ -232,12 +225,7 @@ void testDescribeTopicPartitionsRequest() { |
232 | 225 | .setCursor(new DescribeTopicPartitionsRequestData.Cursor().setTopicName(authorizedTopic).setPartitionIndex(1)) |
233 | 226 | ); |
234 | 227 |
|
235 | | - try { |
236 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
237 | | - } catch (Exception e) { |
238 | | - fail(e.getMessage()); |
239 | | - return; |
240 | | - } |
| 228 | + request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
241 | 229 | response = handler.handleDescribeTopicPartitionsRequest(request); |
242 | 230 | topics = response.topics().valuesList(); |
243 | 231 | assertEquals(2, topics.size()); |
@@ -254,12 +242,7 @@ void testDescribeTopicPartitionsRequest() { |
254 | 242 |
|
255 | 243 | // 3.3 Fetch all topics |
256 | 244 | describeTopicPartitionsRequest = new DescribeTopicPartitionsRequest(new DescribeTopicPartitionsRequestData()); |
257 | | - try { |
258 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
259 | | - } catch (Exception e) { |
260 | | - fail(e.getMessage()); |
261 | | - return; |
262 | | - } |
| 245 | + request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
263 | 246 | response = handler.handleDescribeTopicPartitionsRequest(request); |
264 | 247 | topics = response.topics().valuesList(); |
265 | 248 | assertEquals(1, topics.size()); |
@@ -273,12 +256,7 @@ void testDescribeTopicPartitionsRequest() { |
273 | 256 | describeTopicPartitionsRequest = new DescribeTopicPartitionsRequest( |
274 | 257 | new DescribeTopicPartitionsRequestData().setCursor( |
275 | 258 | new DescribeTopicPartitionsRequestData.Cursor().setTopicName(authorizedTopic).setPartitionIndex(1))); |
276 | | - try { |
277 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
278 | | - } catch (Exception e) { |
279 | | - fail(e.getMessage()); |
280 | | - return; |
281 | | - } |
| 259 | + request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
282 | 260 | response = handler.handleDescribeTopicPartitionsRequest(request); |
283 | 261 | topics = response.topics().valuesList(); |
284 | 262 | assertEquals(1, topics.size()); |
@@ -292,12 +270,7 @@ void testDescribeTopicPartitionsRequest() { |
292 | 270 | describeTopicPartitionsRequest = new DescribeTopicPartitionsRequest( |
293 | 271 | new DescribeTopicPartitionsRequestData().setResponsePartitionLimit(1) |
294 | 272 | ); |
295 | | - try { |
296 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
297 | | - } catch (Exception e) { |
298 | | - fail(e.getMessage()); |
299 | | - return; |
300 | | - } |
| 273 | + request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
301 | 274 | response = handler.handleDescribeTopicPartitionsRequest(request); |
302 | 275 | topics = response.topics().valuesList(); |
303 | 276 | assertEquals(1, topics.size()); |
@@ -311,7 +284,7 @@ void testDescribeTopicPartitionsRequest() { |
311 | 284 | } |
312 | 285 |
|
313 | 286 | @Test |
314 | | - void testDescribeTopicPartitionsRequestWithEdgeCases() { |
| 287 | + void testDescribeTopicPartitionsRequestWithEdgeCases() throws Exception { |
315 | 288 | // 1. Set up authorizer |
316 | 289 | Authorizer authorizer = mock(Authorizer.class); |
317 | 290 | Plugin<Authorizer> authorizerPlugin = Plugin.wrapInstance(authorizer, null, "authorizer.class.name"); |
@@ -401,13 +374,7 @@ void testDescribeTopicPartitionsRequestWithEdgeCases() { |
401 | 374 | .setCursor(new DescribeTopicPartitionsRequestData.Cursor().setTopicName(authorizedTopic).setPartitionIndex(1)) |
402 | 375 | ); |
403 | 376 |
|
404 | | - Request request; |
405 | | - try { |
406 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
407 | | - } catch (Exception e) { |
408 | | - fail(e.getMessage()); |
409 | | - return; |
410 | | - } |
| 377 | + Request request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
411 | 378 | DescribeTopicPartitionsResponseData response = handler.handleDescribeTopicPartitionsRequest(request); |
412 | 379 | List<DescribeTopicPartitionsResponseTopic> topics = response.topics().valuesList(); |
413 | 380 | assertEquals(2, topics.size()); |
@@ -432,12 +399,7 @@ void testDescribeTopicPartitionsRequestWithEdgeCases() { |
432 | 399 | .setCursor(new DescribeTopicPartitionsRequestData.Cursor().setTopicName(authorizedTopic2).setPartitionIndex(0)) |
433 | 400 | ); |
434 | 401 |
|
435 | | - try { |
436 | | - request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
437 | | - } catch (Exception e) { |
438 | | - fail(e.getMessage()); |
439 | | - return; |
440 | | - } |
| 402 | + request = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
441 | 403 | response = handler.handleDescribeTopicPartitionsRequest(request); |
442 | 404 | topics = response.topics().valuesList(); |
443 | 405 | assertEquals(1, topics.size()); |
@@ -456,11 +418,9 @@ void testDescribeTopicPartitionsRequestWithEdgeCases() { |
456 | 418 | .setCursor(new DescribeTopicPartitionsRequestData.Cursor().setTopicName("Non-existing").setPartitionIndex(0)) |
457 | 419 | ); |
458 | 420 |
|
459 | | - try { |
460 | | - handler.handleDescribeTopicPartitionsRequest(buildRequest(describeTopicPartitionsRequest, plaintextListener)); |
461 | | - } catch (Exception e) { |
462 | | - assertInstanceOf(InvalidRequestException.class, e, e.getMessage()); |
463 | | - } |
| 421 | + Request nonExistingTopicCursorRequest = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
| 422 | + assertThrows(InvalidRequestException.class, |
| 423 | + () -> handler.handleDescribeTopicPartitionsRequest(nonExistingTopicCursorRequest)); |
464 | 424 |
|
465 | 425 | // 3.4 With cursor point to a negative partition id. Exception should be thrown if not querying all the topics. |
466 | 426 | describeTopicPartitionsRequest = new DescribeTopicPartitionsRequest(new DescribeTopicPartitionsRequestData() |
@@ -471,11 +431,9 @@ void testDescribeTopicPartitionsRequestWithEdgeCases() { |
471 | 431 | .setCursor(new DescribeTopicPartitionsRequestData.Cursor().setTopicName(authorizedTopic).setPartitionIndex(-1)) |
472 | 432 | ); |
473 | 433 |
|
474 | | - try { |
475 | | - handler.handleDescribeTopicPartitionsRequest(buildRequest(describeTopicPartitionsRequest, plaintextListener)); |
476 | | - } catch (Exception e) { |
477 | | - assertInstanceOf(InvalidRequestException.class, e, e.getMessage()); |
478 | | - } |
| 434 | + Request negativePartitionCursorRequest = buildRequest(describeTopicPartitionsRequest, plaintextListener); |
| 435 | + assertThrows(InvalidRequestException.class, |
| 436 | + () -> handler.handleDescribeTopicPartitionsRequest(negativePartitionCursorRequest)); |
479 | 437 | } |
480 | 438 |
|
481 | 439 | void updateKraftMetadataCache(KRaftMetadataCache kRaftMetadataCache, List<ApiMessage> records) { |
|