Re: [PR] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-14 Thread via GitHub


chia7712 merged PR #15506:
URL: https://github.com/apache/kafka/pull/15506


-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-13 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1523840166


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   LGTM 



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-13 Thread via GitHub


chia7712 commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1523669497


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   @OmniaGM @gharris1727 I'd like to ship it tomorrow if both of you have no 
objection.



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-13 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1523571839


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
I can't see why we care about the ref in some of these tests but if this is 
the intent then keeping `assertSame` is okay. My comment was more a question 
whether we need the test to be explicit or not. 



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-13 Thread via GitHub


gharris1727 commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1523535566


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   When I wrote this test originally, I did intentionally use assertSame to do 
a reference equality check.



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-13 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1522917486


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   For me it is more about the readability. When I see `assertSame` it makes me 
think we are comparing object ref while `assertEquals` for me means we just 
care about executing `equal` method. I personally would lean toward using 
`assertEquals`



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-12 Thread via GitHub


hgeraldino commented on PR #15506:
URL: https://github.com/apache/kafka/pull/15506#issuecomment-1992692291

   Thanks @OmniaGM for your review


-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-12 Thread via GitHub


hgeraldino commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1522194636


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   This is a remnant of the original implementation. As you correctly guessed, 
there is no difference in this case between using `assertEquals` and 
`assertSame`: neither the `RuntimeException` class nor any of its parents 
override the `equals()` method, so they both are effectively checking for 
reference equality (as implemented by the base `Object` class)
   
   I'm happy to change these to `assertEquals` (this is the only place where 
this is used)



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-12 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1521506327


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   While `assertSame` and `assertEquals` behave the same when the default 
equals implementation is provided (which compare references)  but I'm curious 
why are we opting in for `assertSame` over `assertEquals`. Do we need the test 
to explicitly comparing object reference or just value? 



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-12 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1521506327


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -1215,17 +1195,13 @@ public void testSuppressCloseErrors() {
 
 workerTask.initialize(TASK_CONFIG);
 workerTask.initializeAndStart();
-try {
-workerTask.execute();
-fail("workerTask.execute should have thrown an exception");
-} catch (ConnectException e) {
-assertSame("Exception from put should be the cause", putException, 
e.getCause());
-assertTrue("Exception from close should be suppressed", 
e.getSuppressed().length > 0);
-assertSame(closeException, e.getSuppressed()[0]);
-}
+
+Throwable thrownException = assertThrows(ConnectException.class, () -> 
workerTask.execute());
+assertSame("Exception from put should be the cause", putException, 
thrownException.getCause());

Review Comment:
   While `assertSame` and `assertEquals` act the same when the default equals 
implementation is provided (which compare references)  but I'm curious why are 
we opting in for `assertSame` over `assertEquals`. Do we need the test to 
explicitly comparing object reference or just value? 



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-12 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1521477925


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -580,12 +570,9 @@ public void testErrorInRebalancePartitionRevocation() {
 
 workerTask.iteration();
 verifyPollInitialAssignment();
-try {
-workerTask.iteration();
-fail("Poll should have raised the rebalance exception");
-} catch (RuntimeException e) {
-assertEquals(exception, e);
-}
+
+Throwable thrownException = assertThrows(RuntimeException.class, () -> 
workerTask.iteration());

Review Comment:
   same, so am not going to point it out for each test.



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-12 Thread via GitHub


OmniaGM commented on code in PR #15506:
URL: https://github.com/apache/kafka/pull/15506#discussion_r1521475624


##
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:
##
@@ -553,12 +547,8 @@ public void testErrorInRebalancePartitionLoss() {
 workerTask.iteration();
 verifyPollInitialAssignment();
 
-try {
-workerTask.iteration();
-fail("Poll should have raised the rebalance exception");
-} catch (RuntimeException e) {
-assertEquals(exception, e);
-}
+Throwable thrownException = assertThrows(RuntimeException.class, () -> 
workerTask.iteration());

Review Comment:
   The type of the `thrownException` should be `RuntimeException` as it has 
been casted when we called `assertThrows(RuntimeException.class, )`



-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-11 Thread via GitHub


hgeraldino commented on PR #15506:
URL: https://github.com/apache/kafka/pull/15506#issuecomment-1989568163

   Thanks @chia7712 for your review
   
   @gharris1727 does this looks good to you? It's the final PR to consider the 
`WorkerSinkTaskTest` migration done done


-- 
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] KAFKA-14683 Cleanup WorkerSinkTaskTest [kafka]

2024-03-10 Thread via GitHub


hgeraldino commented on PR #15506:
URL: https://github.com/apache/kafka/pull/15506#issuecomment-1987243289

   > @hgeraldino thank for this patch. Could you please apply `assertThrow` to 
this class? For example, the following assert can be rewritten. _origin_
   > 
   > ```java
   > try {
   > workerTask.iteration();
   > fail("Poll should have raised the rebalance exception");
   > } catch (RuntimeException e) {
   > assertEquals(exception, e);
   > }
   > ```
   > 
   > _new_
   > 
   > ```java
   > assertEquals(exception, assertThrows(RuntimeException.class, () -> 
workerTask.iteration()));
   > ```
   
   Sure thing! 
   Done


-- 
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