Re: [PR] Add time out in assertFutureThrows [kafka]
showuon commented on code in PR #16264: URL: https://github.com/apache/kafka/pull/16264#discussion_r1635625857 ## clients/src/test/java/org/apache/kafka/test/TestUtils.java: ## @@ -556,10 +558,22 @@ public static Set generateRandomTopicPartitions(int numTopic, in * @return The caught exception cause */ public static T assertFutureThrows(Future future, Class exceptionCauseClass) { -ExecutionException exception = assertThrows(ExecutionException.class, future::get); -assertInstanceOf(exceptionCauseClass, exception.getCause(), -"Unexpected exception cause " + exception.getCause()); -return exceptionCauseClass.cast(exception.getCause()); +try { +future.get(5, TimeUnit.SECONDS); +fail("expected to throw ExecutionException..."); +} catch (TimeoutException e) { +fail("timeout waiting"); +return null; +} catch (ExecutionException e) { +ExecutionException exception = assertThrows(ExecutionException.class, future::get); +assertInstanceOf(exceptionCauseClass, exception.getCause(), +"Unexpected exception cause " + exception.getCause()); +return exceptionCauseClass.cast(exception.getCause()); +} catch (InterruptedException e) { +fail("Unexpected exception cause" + e.getCause()); +return null; +} +return null; Review Comment: 1. Please put the error message clearly. Do you think users understand what this error message mean when reading it: `expected to throw ExecutionException...`, `timeout waiting`? I wrote it like that is to let you have a start. You can check other places to learn how to put a clear error message. 2. when `fail()` method invoked, do you know what will happen? 3. The method is `assertFutureThrows`, so what should we do if no exception thrown? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add time out in assertFutureThrows [kafka]
chiacyu commented on code in PR #16264: URL: https://github.com/apache/kafka/pull/16264#discussion_r1634968366 ## clients/src/test/java/org/apache/kafka/test/TestUtils.java: ## @@ -556,10 +557,15 @@ public static Set generateRandomTopicPartitions(int numTopic, in * @return The caught exception cause */ public static T assertFutureThrows(Future future, Class exceptionCauseClass) { -ExecutionException exception = assertThrows(ExecutionException.class, future::get); -assertInstanceOf(exceptionCauseClass, exception.getCause(), -"Unexpected exception cause " + exception.getCause()); -return exceptionCauseClass.cast(exception.getCause()); +try { +future.get(5, TimeUnit.SECONDS); +ExecutionException exception = assertThrows(ExecutionException.class, future::get); +assertInstanceOf(exceptionCauseClass, exception.getCause(), +"Unexpected exception cause " + exception.getCause()); +return exceptionCauseClass.cast(exception.getCause()); +} catch (Exception ignored) { +return null; +} Review Comment: Thanks for the comments, would apply. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add time out in assertFutureThrows [kafka]
showuon commented on code in PR #16264: URL: https://github.com/apache/kafka/pull/16264#discussion_r1634018574 ## clients/src/test/java/org/apache/kafka/test/TestUtils.java: ## @@ -556,10 +557,15 @@ public static Set generateRandomTopicPartitions(int numTopic, in * @return The caught exception cause */ public static T assertFutureThrows(Future future, Class exceptionCauseClass) { -ExecutionException exception = assertThrows(ExecutionException.class, future::get); -assertInstanceOf(exceptionCauseClass, exception.getCause(), -"Unexpected exception cause " + exception.getCause()); -return exceptionCauseClass.cast(exception.getCause()); +try { +future.get(5, TimeUnit.SECONDS); +ExecutionException exception = assertThrows(ExecutionException.class, future::get); +assertInstanceOf(exceptionCauseClass, exception.getCause(), +"Unexpected exception cause " + exception.getCause()); +return exceptionCauseClass.cast(exception.getCause()); +} catch (Exception ignored) { +return null; +} Review Comment: I saw there's another `future.get` without timeout in L583. Please also fix it. Thanks. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add time out in assertFutureThrows [kafka]
showuon commented on code in PR #16264: URL: https://github.com/apache/kafka/pull/16264#discussion_r1634016604 ## clients/src/test/java/org/apache/kafka/test/TestUtils.java: ## @@ -556,10 +557,15 @@ public static Set generateRandomTopicPartitions(int numTopic, in * @return The caught exception cause */ public static T assertFutureThrows(Future future, Class exceptionCauseClass) { -ExecutionException exception = assertThrows(ExecutionException.class, future::get); -assertInstanceOf(exceptionCauseClass, exception.getCause(), -"Unexpected exception cause " + exception.getCause()); -return exceptionCauseClass.cast(exception.getCause()); +try { +future.get(5, TimeUnit.SECONDS); +ExecutionException exception = assertThrows(ExecutionException.class, future::get); +assertInstanceOf(exceptionCauseClass, exception.getCause(), +"Unexpected exception cause " + exception.getCause()); +return exceptionCauseClass.cast(exception.getCause()); +} catch (Exception ignored) { +return null; +} Review Comment: Before this change, when future.get throws "non-ExecutionException", it'll fail. But after the change, it'll pass. This changes the original semantics. I think we can use `catch` to assert what we expected. Ex: ``` try { future.get(5, sec); fail("expected to throw ExecutionException..."); } catch (TimeoutException e) { fail("timeout waiting"); } catch (ExecutionException e) { ... } catch ... ``` WDYT? ``` ## clients/src/test/java/org/apache/kafka/test/TestUtils.java: ## @@ -556,10 +557,15 @@ public static Set generateRandomTopicPartitions(int numTopic, in * @return The caught exception cause */ public static T assertFutureThrows(Future future, Class exceptionCauseClass) { -ExecutionException exception = assertThrows(ExecutionException.class, future::get); -assertInstanceOf(exceptionCauseClass, exception.getCause(), -"Unexpected exception cause " + exception.getCause()); -return exceptionCauseClass.cast(exception.getCause()); +try { +future.get(5, TimeUnit.SECONDS); +ExecutionException exception = assertThrows(ExecutionException.class, future::get); +assertInstanceOf(exceptionCauseClass, exception.getCause(), +"Unexpected exception cause " + exception.getCause()); +return exceptionCauseClass.cast(exception.getCause()); +} catch (Exception ignored) { +return null; +} Review Comment: AI saw there's another `future.get` without timeout in L583. Please also fix it. Thanks. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Add time out in assertFutureThrows [kafka]
chiacyu opened a new pull request, #16264: URL: https://github.com/apache/kafka/pull/16264 Based on [KAFKA-16918](https://issues.apache.org/jira/browse/KAFKA-16918), this pr add `future.get()` with timeout in `assertFutureThrows`. ### Committer Checklist (excluded from commit message) - [ ] Verify design and implementation - [ ] Verify test coverage and CI build status - [ ] Verify documentation (including upgrade notes) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org