You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "bachmanity1 (via GitHub)" <gi...@apache.org> on 2023/09/20 05:36:23 UTC
[GitHub] [kafka] bachmanity1 opened a new pull request, #14410: KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
bachmanity1 opened a new pull request, #14410:
URL: https://github.com/apache/kafka/pull/14410
Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
### 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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "divijvaidya (via GitHub)" <gi...@apache.org>.
divijvaidya commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1366795800
##########
streams/src/test/java/org/apache/kafka/streams/state/internals/GlobalStateStoreProviderTest.java:
##########
@@ -105,28 +105,19 @@ public void before() {
Serdes.String(),
Serdes.String()).build());
- final ProcessorContextImpl mockContext = niceMock(ProcessorContextImpl.class);
- expect(mockContext.applicationId()).andStubReturn("appId");
- expect(mockContext.metrics())
- .andStubReturn(
+ final ProcessorContextImpl mockContext = mock(ProcessorContextImpl.class);
+ when(mockContext.applicationId()).thenReturn("appId");
+ when(mockContext.metrics())
+ .thenReturn(
new StreamsMetricsImpl(new Metrics(), "threadName", StreamsConfig.METRICS_LATEST, new MockTime())
);
- expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
- expect(mockContext.recordCollector()).andStubReturn(null);
Review Comment:
Why aren't we stubbing this method to return null after moving to powermock?
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1173,17 +1126,13 @@ public void shouldResetTransactionInitializedOnResetProducer() {
);
streamsProducer.initTransaction();
- reset(mockedProducer);
- mockedProducer.close();
- mockedProducer.initTransactions();
Review Comment:
Correct me if I am wrong but easymock expected `mockedProducer.initTransactions();` to occur only one time reflected by expectLastCall() but it seems like it is being called twice for us when we moved to powermock. I am curious how was it working before?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1365167771
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1098,20 +1053,16 @@ public void shouldSwallowExceptionOnEosAbortTxInvalidEpoch() {
}
private void testSwallowExceptionOnEosAbortTx(final RuntimeException exception) {
- mockedProducer.initTransactions();
- mockedProducer.beginTransaction();
- expect(mockedProducer.send(record, null)).andReturn(null);
- mockedProducer.abortTransaction();
- expectLastCall().andThrow(exception);
Review Comment:
`mockedProducer.abortTransaction` was expected to throw an exception, this doesn't appear to be the case in the new version of this test - is there a reason for this?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1369961591
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -197,8 +203,7 @@ public void before() {
);
eosBetaStreamsProducer.initTransaction();
eosBetaMockProducer = eosBetaMockClientSupplier.producers.get(0);
- expect(mockTime.nanoseconds()).andAnswer(Time.SYSTEM::nanoseconds).anyTimes();
- replay(mockTime);
+ when(mockTime.nanoseconds()).thenReturn(Time.SYSTEM.nanoseconds());
Review Comment:
I will let Ismael decide on this. For other tests which were moved to Mockito I did not change (too many) assertions because I was more focused on the migration rather than test cleanup, but there were exceptions and I don't feel too strongly about this.
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1173,17 +1126,13 @@ public void shouldResetTransactionInitializedOnResetProducer() {
);
streamsProducer.initTransaction();
- reset(mockedProducer);
- mockedProducer.close();
- mockedProducer.initTransactions();
Review Comment:
Okay, but can you at least add this explanation in a condensed form above the verify(mockedProducer, ...).initTransactions() line?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "ijuma (via GitHub)" <gi...@apache.org>.
ijuma commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1371770193
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -197,8 +203,7 @@ public void before() {
);
eosBetaStreamsProducer.initTransaction();
eosBetaMockProducer = eosBetaMockClientSupplier.producers.get(0);
- expect(mockTime.nanoseconds()).andAnswer(Time.SYSTEM::nanoseconds).anyTimes();
- replay(mockTime);
+ when(mockTime.nanoseconds()).thenReturn(Time.SYSTEM.nanoseconds());
Review Comment:
I'm fine sticking with what we have to avoid changing non essential things.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1770370478
Sorry, this fell through the cracks of my reviews, I will assign myself as a reviewer.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1366900765
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1173,17 +1126,13 @@ public void shouldResetTransactionInitializedOnResetProducer() {
);
streamsProducer.initTransaction();
- reset(mockedProducer);
- mockedProducer.close();
- mockedProducer.initTransactions();
Review Comment:
I believe the answer is that `streamsProducer.initTransaction` was called on line 1174. In EasyMock world we reset the mock and the counter went back to zero. In Mockito world we just keep incrementing the counter hence it gets bumped to 2. I am happy with either resetting the mock in Mockito world as well or writing a comment.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1372812958
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1173,17 +1126,13 @@ public void shouldResetTransactionInitializedOnResetProducer() {
);
streamsProducer.initTransaction();
- reset(mockedProducer);
- mockedProducer.close();
- mockedProducer.initTransactions();
Review Comment:
I've added a comment.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] clolov commented on a diff in pull request #14410: KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1331578412
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -53,21 +55,23 @@
import static org.apache.kafka.common.utils.Utils.mkEntry;
import static org.apache.kafka.common.utils.Utils.mkMap;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.mock;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+@SuppressWarnings("unchecked")
Review Comment:
Can you scope this suppression to just the lines/test it is suppressing?
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -244,47 +247,41 @@ public void shouldCreateProducer() {
@Test
public void shouldForwardCallToPartitionsFor() {
final List<PartitionInfo> expectedPartitionInfo = Collections.emptyList();
- expect(mockedProducer.partitionsFor("topic")).andReturn(expectedPartitionInfo);
- replay(mockedProducer);
+ when(mockedProducer.partitionsFor(topic)).thenReturn(expectedPartitionInfo);
final List<PartitionInfo> partitionInfo = streamsProducerWithMock.partitionsFor(topic);
assertThat(partitionInfo, sameInstance(expectedPartitionInfo));
- verify(mockedProducer);
+ verify(mockedProducer).partitionsFor(topic);
Review Comment:
This is not necessary, the StrictStubs make certain to check all `when`s you have used have indeed been invoked.
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -244,47 +247,41 @@ public void shouldCreateProducer() {
@Test
public void shouldForwardCallToPartitionsFor() {
final List<PartitionInfo> expectedPartitionInfo = Collections.emptyList();
- expect(mockedProducer.partitionsFor("topic")).andReturn(expectedPartitionInfo);
- replay(mockedProducer);
+ when(mockedProducer.partitionsFor(topic)).thenReturn(expectedPartitionInfo);
final List<PartitionInfo> partitionInfo = streamsProducerWithMock.partitionsFor(topic);
assertThat(partitionInfo, sameInstance(expectedPartitionInfo));
- verify(mockedProducer);
+ verify(mockedProducer).partitionsFor(topic);
}
@Test
public void shouldForwardCallToFlush() {
mockedProducer.flush();
Review Comment:
```suggestion
doNothing().when(mockedProducer).flush();
```
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -398,6 +395,8 @@ public void shouldNotSetTransactionIdIfEosDisabled() {
logContext,
mockTime
);
+
+ assertFalse(producerConfig.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG));
Review Comment:
For my understanding, how did you come with this assertion?
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/TopologyMetadataTest.java:
##########
@@ -21,7 +21,8 @@
import org.junit.Assert;
import org.junit.Test;
-import static org.easymock.EasyMock.mock;
+import static org.mockito.Mockito.mock;
+
public class TopologyMetadataTest {
Review Comment:
```suggestion
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class TopologyMetadataTest {
```
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -244,47 +247,41 @@ public void shouldCreateProducer() {
@Test
public void shouldForwardCallToPartitionsFor() {
final List<PartitionInfo> expectedPartitionInfo = Collections.emptyList();
- expect(mockedProducer.partitionsFor("topic")).andReturn(expectedPartitionInfo);
- replay(mockedProducer);
+ when(mockedProducer.partitionsFor(topic)).thenReturn(expectedPartitionInfo);
final List<PartitionInfo> partitionInfo = streamsProducerWithMock.partitionsFor(topic);
assertThat(partitionInfo, sameInstance(expectedPartitionInfo));
- verify(mockedProducer);
+ verify(mockedProducer).partitionsFor(topic);
}
@Test
public void shouldForwardCallToFlush() {
mockedProducer.flush();
- expectLastCall();
- replay(mockedProducer);
streamsProducerWithMock.flush();
- verify(mockedProducer);
+ verify(mockedProducer, times(2)).flush();
Review Comment:
This is not necessary as detailed before, I also think that you will find one of those invocations is because of line 260
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] bachmanity1 commented on pull request #14410: KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1727751490
@clolov thanks for the review! I've replied to your comments.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1754552042
@clolov @yashmayya kind reminder for 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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "ijuma (via GitHub)" <gi...@apache.org>.
ijuma commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1367722599
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -197,8 +203,7 @@ public void before() {
);
eosBetaStreamsProducer.initTransaction();
eosBetaMockProducer = eosBetaMockClientSupplier.producers.get(0);
- expect(mockTime.nanoseconds()).andAnswer(Time.SYSTEM::nanoseconds).anyTimes();
- replay(mockTime);
+ when(mockTime.nanoseconds()).thenReturn(Time.SYSTEM.nanoseconds());
Review Comment:
It's really weird to do this. Why not use Time.SYSTEM if that's what we want?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1774929254
@clolov @divijvaidya @ijuma I've addressed your questions, can you have one more look?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1780697176
> Looks good to me! @clolov do you have any other comments on this PR?
@divijvaidya
Can you not merge for now? Looks like some tests are failing.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1365320976
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1098,20 +1053,16 @@ public void shouldSwallowExceptionOnEosAbortTxInvalidEpoch() {
}
private void testSwallowExceptionOnEosAbortTx(final RuntimeException exception) {
- mockedProducer.initTransactions();
- mockedProducer.beginTransaction();
- expect(mockedProducer.send(record, null)).andReturn(null);
- mockedProducer.abortTransaction();
- expectLastCall().andThrow(exception);
Review Comment:
fixed.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "divijvaidya (via GitHub)" <gi...@apache.org>.
divijvaidya commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1782528436
Test failures are unrelated to the tests modified in this PR.
```
[Build / JDK 21 and Scala 2.13 / org.apache.kafka.common.network.SslTransportLayerTest.[3] tlsProtocol=TLSv1.3, useInlinePem=false](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.common.network/SslTransportLayerTest/Build___JDK_21_and_Scala_2_13____3__tlsProtocol_TLSv1_3__useInlinePem_false/)
[Build / JDK 21 and Scala 2.13 / integration.kafka.server.FetchFromFollowerIntegrationTest.testRackAwareRangeAssignor(String).quorum=zk](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/integration.kafka.server/FetchFromFollowerIntegrationTest/Build___JDK_21_and_Scala_2_13___testRackAwareRangeAssignor_String__quorum_zk/)
[Build / JDK 21 and Scala 2.13 / org.apache.kafka.controller.QuorumControllerTest.testFenceMultipleBrokers()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.controller/QuorumControllerTest/Build___JDK_21_and_Scala_2_13___testFenceMultipleBrokers__/)
[Build / JDK 21 and Scala 2.13 / org.apache.kafka.streams.integration.EosIntegrationTest.shouldWriteLatestOffsetsToCheckpointOnShutdown[at_least_once, processing threads = false]](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.streams.integration/EosIntegrationTest/Build___JDK_21_and_Scala_2_13___shouldWriteLatestOffsetsToCheckpointOnShutdown_at_least_once__processing_threads___false_/)
[Build / JDK 17 and Scala 2.13 / org.apache.kafka.connect.mirror.integration.MirrorConnectorsIntegrationBaseTest.testReplicateSourceDefault()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.connect.mirror.integration/MirrorConnectorsIntegrationBaseTest/Build___JDK_17_and_Scala_2_13___testReplicateSourceDefault__/)
[Build / JDK 17 and Scala 2.13 / kafka.api.DelegationTokenEndToEndAuthorizationWithOwnerTest.testProduceConsumeViaSubscribe(String).quorum=kraft](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/kafka.api/DelegationTokenEndToEndAuthorizationWithOwnerTest/Build___JDK_17_and_Scala_2_13___testProduceConsumeViaSubscribe_String__quorum_kraft/)
[Build / JDK 17 and Scala 2.13 / org.apache.kafka.streams.integration.ConsistencyVectorIntegrationTest.shouldHaveSamePositionBoundActiveAndStandBy](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.streams.integration/ConsistencyVectorIntegrationTest/Build___JDK_17_and_Scala_2_13___shouldHaveSamePositionBoundActiveAndStandBy/)
[Build / JDK 17 and Scala 2.13 / org.apache.kafka.streams.integration.NamedTopologyIntegrationTest.shouldAddAndRemoveNamedTopologiesBeforeStartingAndRouteQueriesToCorrectTopology()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.streams.integration/NamedTopologyIntegrationTest/Build___JDK_17_and_Scala_2_13___shouldAddAndRemoveNamedTopologiesBeforeStartingAndRouteQueriesToCorrectTopology__/)
[Build / JDK 17 and Scala 2.13 / org.apache.kafka.trogdor.coordinator.CoordinatorTest.testTaskRequestWithOldStartMsGetsUpdated()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.trogdor.coordinator/CoordinatorTest/Build___JDK_17_and_Scala_2_13___testTaskRequestWithOldStartMsGetsUpdated__/)
[Build / JDK 11 and Scala 2.13 / integration.kafka.server.FetchFromFollowerIntegrationTest.testRackAwareRangeAssignor(String).quorum=zk](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/integration.kafka.server/FetchFromFollowerIntegrationTest/Build___JDK_11_and_Scala_2_13___testRackAwareRangeAssignor_String__quorum_zk/)
[Build / JDK 11 and Scala 2.13 / kafka.server.DelegationTokenRequestsTest.testDelegationTokenRequests(String).quorum=kraft](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/kafka.server/DelegationTokenRequestsTest/Build___JDK_11_and_Scala_2_13___testDelegationTokenRequests_String__quorum_kraft/)
[Build / JDK 11 and Scala 2.13 / org.apache.kafka.tiered.storage.integration.TransactionsWithTieredStoreTest.testCommitTransactionTimeout(String).quorum=kraft](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.tiered.storage.integration/TransactionsWithTieredStoreTest/Build___JDK_11_and_Scala_2_13___testCommitTransactionTimeout_String__quorum_kraft/)
[Build / JDK 11 and Scala 2.13 / org.apache.kafka.streams.integration.EosIntegrationTest.shouldWriteLatestOffsetsToCheckpointOnShutdown[at_least_once, processing threads = false]](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.streams.integration/EosIntegrationTest/Build___JDK_11_and_Scala_2_13___shouldWriteLatestOffsetsToCheckpointOnShutdown_at_least_once__processing_threads___false_/)
[Build / JDK 11 and Scala 2.13 / org.apache.kafka.streams.integration.NamedTopologyIntegrationTest.shouldAddAndRemoveNamedTopologiesBeforeStartingAndRouteQueriesToCorrectTopology()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.streams.integration/NamedTopologyIntegrationTest/Build___JDK_11_and_Scala_2_13___shouldAddAndRemoveNamedTopologiesBeforeStartingAndRouteQueriesToCorrectTopology__/)
[Build / JDK 11 and Scala 2.13 / org.apache.kafka.streams.integration.RestoreIntegrationTest.shouldInvokeUserDefinedGlobalStateRestoreListener()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.streams.integration/RestoreIntegrationTest/Build___JDK_11_and_Scala_2_13___shouldInvokeUserDefinedGlobalStateRestoreListener__/)
[Build / JDK 11 and Scala 2.13 / org.apache.kafka.trogdor.coordinator.CoordinatorTest.testTaskRequestWithOldStartMsGetsUpdated()](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14410/7/testReport/junit/org.apache.kafka.trogdor.coordinator/CoordinatorTest/Build___JDK_11_and_Scala_2_13___testTaskRequestWithOldStartMsGetsUpdated__/)
```
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1368465903
##########
streams/src/test/java/org/apache/kafka/streams/state/internals/GlobalStateStoreProviderTest.java:
##########
@@ -105,28 +105,19 @@ public void before() {
Serdes.String(),
Serdes.String()).build());
- final ProcessorContextImpl mockContext = niceMock(ProcessorContextImpl.class);
- expect(mockContext.applicationId()).andStubReturn("appId");
- expect(mockContext.metrics())
- .andStubReturn(
+ final ProcessorContextImpl mockContext = mock(ProcessorContextImpl.class);
+ when(mockContext.applicationId()).thenReturn("appId");
+ when(mockContext.metrics())
+ .thenReturn(
new StreamsMetricsImpl(new Metrics(), "threadName", StreamsConfig.METRICS_LATEST, new MockTime())
);
- expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
- expect(mockContext.recordCollector()).andStubReturn(null);
Review Comment:
I haven't stubbed `mockContext.recordCollector()` method because it's never actually called. `andStubReturn` method of EasyMock doesn't verify that the method is actually called it only provides a default return value without enforcing strict behavior. Replacing `andStubReturn` with `andReturn` makes tests fail as shown below. (To verify this you have to convert `mockContext` variable to class field and call `verify(mockContext)` after 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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] bachmanity1 commented on pull request #14410: KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1727005007
@clolov @yashmayya can you please have a look?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] bachmanity1 commented on a diff in pull request #14410: KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1331642481
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -244,47 +247,41 @@ public void shouldCreateProducer() {
@Test
public void shouldForwardCallToPartitionsFor() {
final List<PartitionInfo> expectedPartitionInfo = Collections.emptyList();
- expect(mockedProducer.partitionsFor("topic")).andReturn(expectedPartitionInfo);
- replay(mockedProducer);
+ when(mockedProducer.partitionsFor(topic)).thenReturn(expectedPartitionInfo);
final List<PartitionInfo> partitionInfo = streamsProducerWithMock.partitionsFor(topic);
assertThat(partitionInfo, sameInstance(expectedPartitionInfo));
- verify(mockedProducer);
+ verify(mockedProducer).partitionsFor(topic);
}
@Test
public void shouldForwardCallToFlush() {
mockedProducer.flush();
Review Comment:
I feel like here it's more natural to use verify instead of doNothing.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1372841385
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1098,20 +1055,16 @@ public void shouldSwallowExceptionOnEosAbortTxInvalidEpoch() {
}
private void testSwallowExceptionOnEosAbortTx(final RuntimeException exception) {
- mockedProducer.initTransactions();
- mockedProducer.beginTransaction();
- expect(mockedProducer.send(record, null)).andReturn(null);
- mockedProducer.abortTransaction();
- expectLastCall().andThrow(exception);
- replay(mockedProducer);
+ doReturn(null).when(mockedProducer).send(record, null);
Review Comment:
looks like this should have been
`when(mockedProducer.send(record, null)).thenReturn(null);` not `when(mockedProducer).send(record, null).thenReturn(null);`
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "clolov (via GitHub)" <gi...@apache.org>.
clolov commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1366895932
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1098,20 +1055,16 @@ public void shouldSwallowExceptionOnEosAbortTxInvalidEpoch() {
}
private void testSwallowExceptionOnEosAbortTx(final RuntimeException exception) {
- mockedProducer.initTransactions();
- mockedProducer.beginTransaction();
- expect(mockedProducer.send(record, null)).andReturn(null);
- mockedProducer.abortTransaction();
- expectLastCall().andThrow(exception);
- replay(mockedProducer);
+ doReturn(null).when(mockedProducer).send(record, null);
Review Comment:
For consistency:
```suggestion
when(mockedProducer).send(record, null).thenReturn(null);
```
##########
streams/src/test/java/org/apache/kafka/streams/state/internals/GlobalStateStoreProviderTest.java:
##########
@@ -105,28 +105,19 @@ public void before() {
Serdes.String(),
Serdes.String()).build());
- final ProcessorContextImpl mockContext = niceMock(ProcessorContextImpl.class);
- expect(mockContext.applicationId()).andStubReturn("appId");
- expect(mockContext.metrics())
- .andStubReturn(
+ final ProcessorContextImpl mockContext = mock(ProcessorContextImpl.class);
+ when(mockContext.applicationId()).thenReturn("appId");
+ when(mockContext.metrics())
+ .thenReturn(
new StreamsMetricsImpl(new Metrics(), "threadName", StreamsConfig.METRICS_LATEST, new MockTime())
);
- expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
- expect(mockContext.recordCollector()).andStubReturn(null);
Review Comment:
As far as I know the default return value of mocks is null when the return an object. For validation's sake, however, you are right. You either need to when this or verify this.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1368465903
##########
streams/src/test/java/org/apache/kafka/streams/state/internals/GlobalStateStoreProviderTest.java:
##########
@@ -105,28 +105,19 @@ public void before() {
Serdes.String(),
Serdes.String()).build());
- final ProcessorContextImpl mockContext = niceMock(ProcessorContextImpl.class);
- expect(mockContext.applicationId()).andStubReturn("appId");
- expect(mockContext.metrics())
- .andStubReturn(
+ final ProcessorContextImpl mockContext = mock(ProcessorContextImpl.class);
+ when(mockContext.applicationId()).thenReturn("appId");
+ when(mockContext.metrics())
+ .thenReturn(
new StreamsMetricsImpl(new Metrics(), "threadName", StreamsConfig.METRICS_LATEST, new MockTime())
);
- expect(mockContext.taskId()).andStubReturn(new TaskId(0, 0));
- expect(mockContext.recordCollector()).andStubReturn(null);
Review Comment:
I haven't stubbed `mockContext.recordCollector()` method because it's never actually called. `andStubReturn` method of EasyMock doesn't verify that the method is actually called it only provides a default return value without enforcing strict behavior. Replacing `andStubReturn` with `andReturn` makes tests fail as shown below. (To verify this you have to convert `mockContext` variable to class field and call `verify(mockContext) after 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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1368477408
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -197,8 +203,7 @@ public void before() {
);
eosBetaStreamsProducer.initTransaction();
eosBetaMockProducer = eosBetaMockClientSupplier.producers.get(0);
- expect(mockTime.nanoseconds()).andAnswer(Time.SYSTEM::nanoseconds).anyTimes();
- replay(mockTime);
+ when(mockTime.nanoseconds()).thenReturn(Time.SYSTEM.nanoseconds());
Review Comment:
I think the reason is that we are stubbing `mockTime.nanoseconds()` one more time on line 1129 to return value other than just `Time.SYSTEM.nanoseconds()`.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1368375859
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -1173,17 +1126,13 @@ public void shouldResetTransactionInitializedOnResetProducer() {
);
streamsProducer.initTransaction();
- reset(mockedProducer);
- mockedProducer.close();
- mockedProducer.initTransactions();
Review Comment:
I think the goal of this test is to make sure that `resetProducer` method resets `transactionInitialized` field so that subsequent call of the `initTransactions` method can start new transaction. Easymock expects `mockedProducer.initTransactions()` only once because of the `reset()` on line 1176. As far as I know there is no equivalent of `reset()` in Mockito, so I think the best we can do is to check that `mockedProducer.initTransactions()` is called twice.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "divijvaidya (via GitHub)" <gi...@apache.org>.
divijvaidya commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1779407230
> @divijvaidya Do you have cycles to review this?
Sure, I can get to this before the end this week.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "ijuma (via GitHub)" <gi...@apache.org>.
ijuma commented on PR #14410:
URL: https://github.com/apache/kafka/pull/14410#issuecomment-1779286800
@divijvaidya Do you have cycles to review this?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest [kafka]
Posted by "divijvaidya (via GitHub)" <gi...@apache.org>.
divijvaidya merged PR #14410:
URL: https://github.com/apache/kafka/pull/14410
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] bachmanity1 commented on a diff in pull request #14410: KAFKA-14133: Replace Easymock with Mockito in StreamsProducerTest, TopologyMetadataTest & GlobalStateStoreProviderTest
Posted by "bachmanity1 (via GitHub)" <gi...@apache.org>.
bachmanity1 commented on code in PR #14410:
URL: https://github.com/apache/kafka/pull/14410#discussion_r1331617852
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java:
##########
@@ -398,6 +395,8 @@ public void shouldNotSetTransactionIdIfEosDisabled() {
logContext,
mockTime
);
+
+ assertFalse(producerConfig.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG));
Review Comment:
as the name of this test suggests when EOS guarantee is disabled StreamsProducer should not set transaction id. I thought that the previous version of this test didn't make it obvious that the transaction id is really not set, so instead of using a mock object as producer config, I'm using a real object and explicitly checking for the existence of transaction id config. I've done similar changes to the `shouldSetTransactionIdUsingTaskIdIfEosAlphaEnabled` and `shouldSetTransactionIdUsingProcessIdIfEosV2Enabled`.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org