You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/08/02 16:56:48 UTC
[GitHub] [kafka] divijvaidya opened a new pull request, #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
divijvaidya opened a new pull request, #12473:
URL: https://github.com/apache/kafka/pull/12473
This PR is created on top of abandoned PR https://github.com/apache/kafka/pull/11137. I have added the previous author's comment in this PR for attribution. I have also addressed the pending comments from @mimaison in this PR.
## Notes to help the reviewer:
- When we run the tests using @RunWith(MockitoJUnitRunner.StrictStubs.class) Mockito performs a verify() for all stubs that are mentioned, hence, there is no need to explicitly verify the stubs (unless you want to verify the number of times etc.). Note that this does not work for static mocks.
## Testing
`./gradlew connect:runtime:unitTest --tests AbstractHerderTest` is successful.
--
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] mimaison commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
mimaison commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r946860309
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
Review Comment:
I think we can also remove the `TASK_CONFIGS` constant above
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -556,28 +473,24 @@ public void testConfigValidationTransformsExtendResults() {
assertEquals("transforms.xformB.type", infos.get("transforms.xformB.type").configValue().name());
assertFalse(infos.get("transforms.xformB.type").configValue().errors().isEmpty());
- verifyAll();
+ verify(plugins, times(2)).transformations();
+ verify(plugins).newConnector(connectorClass.getName());
+ verify(plugins).compareAndSwapLoaders(insConnector);
}
- @Test()
+ @Test
public void testConfigValidationPredicatesExtendResults() {
- AbstractHerder herder = createConfigValidationHerder(SampleSourceConnector.class, noneConnectorClientConfigOverridePolicy);
+ final Class<? extends Connector> connectorClass = SampleSourceConnector.class;
+ AbstractHerder herder = createConfigValidationHerder(connectorClass, noneConnectorClientConfigOverridePolicy);
// 2 transform aliases defined -> 2 plugin lookups
- Set<PluginDesc<Transformation<?>>> transformations = new HashSet<>();
- transformations.add(transformationPluginDesc());
- EasyMock.expect(plugins.transformations()).andReturn(transformations).times(1);
-
- Set<PluginDesc<Predicate<?>>> predicates = new HashSet<>();
- predicates.add(predicatePluginDesc());
- EasyMock.expect(plugins.predicates()).andReturn(predicates).times(2);
-
- replayAll();
+ when(plugins.transformations()).thenReturn(Collections.singleton(transformationPluginDesc()));
+ when(plugins.predicates()).thenReturn(Collections.singleton(predicatePluginDesc()));
// Define 2 transformations. One has a class defined and so can get embedded configs, the other is missing
Review Comment:
I guess it should be `Define 2 predicates`?
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -412,38 +334,32 @@ public void testBuildRestartPlanForNoRestart() {
assertFalse(restartPlan.shouldRestartConnector());
assertFalse(restartPlan.shouldRestartTasks());
assertTrue(restartPlan.taskIdsToRestart().isEmpty());
-
- PowerMock.verifyAll();
}
@Test
public void testConfigValidationEmptyConfig() {
AbstractHerder herder = createConfigValidationHerder(SampleSourceConnector.class, noneConnectorClientConfigOverridePolicy, 0);
- replayAll();
assertThrows(BadRequestException.class, () -> herder.validateConnectorConfig(Collections.emptyMap(), false));
+ verify(worker, times(2)).configTransformer();
Review Comment:
I wonder if it makes more sense to check for `verify(transformer).transform(Collections.emptyMap());` instead. The fact we call `configTransformer()` twice is kind of an implementation detail.
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -236,31 +200,21 @@ public void connectorStatus() {
assertEquals(0, taskState.id());
assertEquals("UNASSIGNED", taskState.state());
assertEquals(workerId, taskState.workerId());
-
- PowerMock.verifyAll();
}
@Test
- public void taskStatus() {
+ public void testTaskStatus() {
ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
Review Comment:
We can use the `connector` variable instead of the literal here
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
+ @Mock private WorkerConfigTransformer transformer;
+ @Mock private ConfigBackingStore configStore;
+ @Mock private StatusBackingStore statusStore;
+ @Mock private ClassLoader classLoader;
@Mock private Plugins plugins;
+ private ClassLoader loader;
+ private Connector insConnector;
Review Comment:
Is there a reason it's called `insConnector`? I wonder if renaming the other `connector` to something like `connName` would make more sense. WDYT?
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -556,28 +473,24 @@ public void testConfigValidationTransformsExtendResults() {
assertEquals("transforms.xformB.type", infos.get("transforms.xformB.type").configValue().name());
assertFalse(infos.get("transforms.xformB.type").configValue().errors().isEmpty());
- verifyAll();
+ verify(plugins, times(2)).transformations();
+ verify(plugins).newConnector(connectorClass.getName());
+ verify(plugins).compareAndSwapLoaders(insConnector);
}
- @Test()
+ @Test
public void testConfigValidationPredicatesExtendResults() {
- AbstractHerder herder = createConfigValidationHerder(SampleSourceConnector.class, noneConnectorClientConfigOverridePolicy);
+ final Class<? extends Connector> connectorClass = SampleSourceConnector.class;
+ AbstractHerder herder = createConfigValidationHerder(connectorClass, noneConnectorClientConfigOverridePolicy);
// 2 transform aliases defined -> 2 plugin lookups
- Set<PluginDesc<Transformation<?>>> transformations = new HashSet<>();
- transformations.add(transformationPluginDesc());
- EasyMock.expect(plugins.transformations()).andReturn(transformations).times(1);
-
- Set<PluginDesc<Predicate<?>>> predicates = new HashSet<>();
- predicates.add(predicatePluginDesc());
- EasyMock.expect(plugins.predicates()).andReturn(predicates).times(2);
-
- replayAll();
+ when(plugins.transformations()).thenReturn(Collections.singleton(transformationPluginDesc()));
Review Comment:
Not sure if these comments still make sense
--
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] mimaison commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
mimaison commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952775683
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
Review Comment:
My bad, somehow IDEA marked it as unused but as you said it is used!
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
Review Comment:
My bad, somehow IDEA marked it as unused but, as you said, it 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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r936496903
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +141,51 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
- @Mock private Plugins plugins;
+ private final Worker worker = mock(Worker.class);
+ private final WorkerConfigTransformer transformer = mock(WorkerConfigTransformer.class);
+ private final Plugins plugins = mock(Plugins.class);
+ private final ClassLoader classLoader = mock(ClassLoader.class);
+ private final ConfigBackingStore configStore = mock(ConfigBackingStore.class);
+ private final StatusBackingStore statusStore = mock(StatusBackingStore.class);
+ private ClassLoader loader;
+ private Connector insConnector;
- @Test
- public void testConnectors() {
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(
- Worker.class,
- String.class,
- String.class,
- StatusBackingStore.class,
- ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class
- )
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
-
- EasyMock.expect(herder.generation()).andStubReturn(generation);
- EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
- EasyMock.expect(configStore.snapshot()).andReturn(SNAPSHOT);
- replayAll();
- assertEquals(Collections.singleton(CONN1), new HashSet<>(herder.connectors()));
- PowerMock.verifyAll();
+ @Before
+ public void before() {
+ loader = Utils.getContextOrKafkaClassLoader();
+ }
+
+ @After
+ public void tearDown() {
+ if (loader != null) Plugins.compareAndSwapLoaders(loader);
}
@Test
- public void testConnectorStatus() {
- ConnectorTaskId taskId = new ConnectorTaskId(connector, 0);
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(
- Worker.class,
- String.class,
- String.class,
- StatusBackingStore.class,
- ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class
- )
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
-
- EasyMock.expect(herder.generation()).andStubReturn(generation);
- EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
- EasyMock.expect(statusStore.get(connector))
- .andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
- EasyMock.expect(statusStore.getAll(connector))
- .andReturn(Collections.singletonList(
- new TaskStatus(taskId, AbstractStatus.State.UNASSIGNED, workerId, generation)));
-
- replayAll();
- ConnectorStateInfo csi = herder.connectorStatus(connector);
- PowerMock.verifyAll();
+ public void testConnectors() {
+ AbstractHerder herder = mock(AbstractHerder.class, withSettings()
+ .useConstructor(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
+ .defaultAnswer(CALLS_REAL_METHODS));
+
+ when(configStore.snapshot()).thenReturn(SNAPSHOT);
+ assertEquals(Collections.singleton(CONN1), new HashSet<>(herder.connectors()));
}
@Test
public void connectorStatus() {
Review Comment:
done in the latest revision.
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952566247
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -412,38 +334,32 @@ public void testBuildRestartPlanForNoRestart() {
assertFalse(restartPlan.shouldRestartConnector());
assertFalse(restartPlan.shouldRestartTasks());
assertTrue(restartPlan.taskIdsToRestart().isEmpty());
-
- PowerMock.verifyAll();
}
@Test
public void testConfigValidationEmptyConfig() {
AbstractHerder herder = createConfigValidationHerder(SampleSourceConnector.class, noneConnectorClientConfigOverridePolicy, 0);
- replayAll();
assertThrows(BadRequestException.class, () -> herder.validateConnectorConfig(Collections.emptyMap(), false));
+ verify(worker, times(2)).configTransformer();
Review Comment:
Changed as suggested in upcoming commit.
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r936497559
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -236,31 +198,23 @@ public void connectorStatus() {
assertEquals(0, taskState.id());
assertEquals("UNASSIGNED", taskState.state());
assertEquals(workerId, taskState.workerId());
-
- PowerMock.verifyAll();
}
@Test
public void taskStatus() {
ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
String workerId = "workerId";
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class)
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
+ AbstractHerder herder = mock(AbstractHerder.class, withSettings()
+ .useConstructor(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
+ .defaultAnswer(CALLS_REAL_METHODS));
- EasyMock.expect(herder.generation()).andStubReturn(5);
+ when(herder.generation()).thenReturn(5);
Review Comment:
Removed in the latest revision
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952631224
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -556,28 +473,24 @@ public void testConfigValidationTransformsExtendResults() {
assertEquals("transforms.xformB.type", infos.get("transforms.xformB.type").configValue().name());
assertFalse(infos.get("transforms.xformB.type").configValue().errors().isEmpty());
- verifyAll();
+ verify(plugins, times(2)).transformations();
+ verify(plugins).newConnector(connectorClass.getName());
+ verify(plugins).compareAndSwapLoaders(insConnector);
}
- @Test()
+ @Test
public void testConfigValidationPredicatesExtendResults() {
- AbstractHerder herder = createConfigValidationHerder(SampleSourceConnector.class, noneConnectorClientConfigOverridePolicy);
+ final Class<? extends Connector> connectorClass = SampleSourceConnector.class;
+ AbstractHerder herder = createConfigValidationHerder(connectorClass, noneConnectorClientConfigOverridePolicy);
// 2 transform aliases defined -> 2 plugin lookups
- Set<PluginDesc<Transformation<?>>> transformations = new HashSet<>();
- transformations.add(transformationPluginDesc());
- EasyMock.expect(plugins.transformations()).andReturn(transformations).times(1);
-
- Set<PluginDesc<Predicate<?>>> predicates = new HashSet<>();
- predicates.add(predicatePluginDesc());
- EasyMock.expect(plugins.predicates()).andReturn(predicates).times(2);
-
- replayAll();
+ when(plugins.transformations()).thenReturn(Collections.singleton(transformationPluginDesc()));
Review Comment:
Removed this comment, rest of the comments should still be valid.
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952781430
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
Review Comment:
Thank you for clarifying. In that case, the PR is ready for your review. I have addressed rest of 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
[GitHub] [kafka] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952546082
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -236,31 +200,21 @@ public void connectorStatus() {
assertEquals(0, taskState.id());
assertEquals("UNASSIGNED", taskState.state());
assertEquals(workerId, taskState.workerId());
-
- PowerMock.verifyAll();
}
@Test
- public void taskStatus() {
+ public void testTaskStatus() {
ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
Review Comment:
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mimaison merged pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
mimaison merged PR #12473:
URL: https://github.com/apache/kafka/pull/12473
--
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] ijuma commented on pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
ijuma commented on PR #12473:
URL: https://github.com/apache/kafka/pull/12473#issuecomment-1210701003
@mimaison @C0urante Can one of you please review this and get it over the 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
[GitHub] [kafka] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952561099
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
+ @Mock private WorkerConfigTransformer transformer;
+ @Mock private ConfigBackingStore configStore;
+ @Mock private StatusBackingStore statusStore;
+ @Mock private ClassLoader classLoader;
@Mock private Plugins plugins;
+ private ClassLoader loader;
+ private Connector insConnector;
Review Comment:
The naming is an artifact of the commits I merged from previous commits which I took over. But you are right. I have renamed these variables.
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952614033
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +142,52 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
+ @Mock private Worker worker;
Review Comment:
I did not understand the reason for your suggestion. `TASK_CONFIGS` is being used to create a `ClusterConfigState` containing tasks which are used in `testConnectors()` and `testReverseTransformConfigs()` tests.
Could you please help me understand the rationale here?
--
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] divijvaidya commented on pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on PR #12473:
URL: https://github.com/apache/kafka/pull/12473#issuecomment-1204943631
@C0urante this is ready for your review when you get some time. Thank you!
--
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] yashmayya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
yashmayya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r936007323
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +141,51 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
- @Mock private Plugins plugins;
+ private final Worker worker = mock(Worker.class);
+ private final WorkerConfigTransformer transformer = mock(WorkerConfigTransformer.class);
+ private final Plugins plugins = mock(Plugins.class);
+ private final ClassLoader classLoader = mock(ClassLoader.class);
+ private final ConfigBackingStore configStore = mock(ConfigBackingStore.class);
+ private final StatusBackingStore statusStore = mock(StatusBackingStore.class);
+ private ClassLoader loader;
+ private Connector insConnector;
- @Test
- public void testConnectors() {
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(
- Worker.class,
- String.class,
- String.class,
- StatusBackingStore.class,
- ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class
- )
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
-
- EasyMock.expect(herder.generation()).andStubReturn(generation);
- EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
- EasyMock.expect(configStore.snapshot()).andReturn(SNAPSHOT);
- replayAll();
- assertEquals(Collections.singleton(CONN1), new HashSet<>(herder.connectors()));
- PowerMock.verifyAll();
+ @Before
+ public void before() {
+ loader = Utils.getContextOrKafkaClassLoader();
+ }
+
+ @After
+ public void tearDown() {
+ if (loader != null) Plugins.compareAndSwapLoaders(loader);
}
@Test
- public void testConnectorStatus() {
- ConnectorTaskId taskId = new ConnectorTaskId(connector, 0);
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(
- Worker.class,
- String.class,
- String.class,
- StatusBackingStore.class,
- ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class
- )
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
-
- EasyMock.expect(herder.generation()).andStubReturn(generation);
- EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
- EasyMock.expect(statusStore.get(connector))
- .andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
- EasyMock.expect(statusStore.getAll(connector))
- .andReturn(Collections.singletonList(
- new TaskStatus(taskId, AbstractStatus.State.UNASSIGNED, workerId, generation)));
-
- replayAll();
- ConnectorStateInfo csi = herder.connectorStatus(connector);
- PowerMock.verifyAll();
+ public void testConnectors() {
+ AbstractHerder herder = mock(AbstractHerder.class, withSettings()
+ .useConstructor(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
+ .defaultAnswer(CALLS_REAL_METHODS));
+
+ when(configStore.snapshot()).thenReturn(SNAPSHOT);
+ assertEquals(Collections.singleton(CONN1), new HashSet<>(herder.connectors()));
}
@Test
public void connectorStatus() {
Review Comment:
Let's rename this to `testConnectorStatus()` to be consistent (and `taskStatus` to `testTaskStatus`)?
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -236,31 +198,23 @@ public void connectorStatus() {
assertEquals(0, taskState.id());
assertEquals("UNASSIGNED", taskState.state());
assertEquals(workerId, taskState.workerId());
-
- PowerMock.verifyAll();
}
@Test
public void taskStatus() {
ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
String workerId = "workerId";
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class)
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
+ AbstractHerder herder = mock(AbstractHerder.class, withSettings()
+ .useConstructor(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
+ .defaultAnswer(CALLS_REAL_METHODS));
- EasyMock.expect(herder.generation()).andStubReturn(5);
+ when(herder.generation()).thenReturn(5);
Review Comment:
This stub isn't required
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r935831882
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -141,89 +141,51 @@ public class AbstractHerderTest {
private final String connector = "connector";
private final ConnectorClientConfigOverridePolicy noneConnectorClientConfigOverridePolicy = new NoneConnectorClientConfigOverridePolicy();
- @MockStrict private Worker worker;
- @MockStrict private WorkerConfigTransformer transformer;
- @MockStrict private ConfigBackingStore configStore;
- @MockStrict private StatusBackingStore statusStore;
- @MockStrict private ClassLoader classLoader;
- @Mock private Plugins plugins;
+ private final Worker worker = mock(Worker.class);
+ private final WorkerConfigTransformer transformer = mock(WorkerConfigTransformer.class);
+ private final Plugins plugins = mock(Plugins.class);
+ private final ClassLoader classLoader = mock(ClassLoader.class);
+ private final ConfigBackingStore configStore = mock(ConfigBackingStore.class);
+ private final StatusBackingStore statusStore = mock(StatusBackingStore.class);
+ private ClassLoader loader;
+ private Connector insConnector;
- @Test
- public void testConnectors() {
- AbstractHerder herder = partialMockBuilder(AbstractHerder.class)
- .withConstructor(
- Worker.class,
- String.class,
- String.class,
- StatusBackingStore.class,
- ConfigBackingStore.class,
- ConnectorClientConfigOverridePolicy.class
- )
- .withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy)
- .addMockedMethod("generation")
- .createMock();
-
- EasyMock.expect(herder.generation()).andStubReturn(generation);
- EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
- EasyMock.expect(configStore.snapshot()).andReturn(SNAPSHOT);
- replayAll();
- assertEquals(Collections.singleton(CONN1), new HashSet<>(herder.connectors()));
- PowerMock.verifyAll();
+ @Before
+ public void before() {
+ loader = Utils.getContextOrKafkaClassLoader();
+ }
+
+ @After
+ public void tearDown() {
+ if (loader != null) Plugins.compareAndSwapLoaders(loader);
}
@Test
- public void testConnectorStatus() {
Review Comment:
Reviewers, please note that we have removed this test completely since it is duplicated by another existing test `connectorStatus`.
--
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] C0urante commented on pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
C0urante commented on PR #12473:
URL: https://github.com/apache/kafka/pull/12473#issuecomment-1211000855
@ijuma @divijvaidya I'm pretty tied up this week and next, but can definitely provide a first review by the end of the week after. Please feel free to ping me if I still haven't left a review by Friday, August 26th.
--
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] divijvaidya commented on a diff in pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
divijvaidya commented on code in PR #12473:
URL: https://github.com/apache/kafka/pull/12473#discussion_r952630756
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java:
##########
@@ -556,28 +473,24 @@ public void testConfigValidationTransformsExtendResults() {
assertEquals("transforms.xformB.type", infos.get("transforms.xformB.type").configValue().name());
assertFalse(infos.get("transforms.xformB.type").configValue().errors().isEmpty());
- verifyAll();
+ verify(plugins, times(2)).transformations();
+ verify(plugins).newConnector(connectorClass.getName());
+ verify(plugins).compareAndSwapLoaders(insConnector);
}
- @Test()
+ @Test
public void testConfigValidationPredicatesExtendResults() {
- AbstractHerder herder = createConfigValidationHerder(SampleSourceConnector.class, noneConnectorClientConfigOverridePolicy);
+ final Class<? extends Connector> connectorClass = SampleSourceConnector.class;
+ AbstractHerder herder = createConfigValidationHerder(connectorClass, noneConnectorClientConfigOverridePolicy);
// 2 transform aliases defined -> 2 plugin lookups
- Set<PluginDesc<Transformation<?>>> transformations = new HashSet<>();
- transformations.add(transformationPluginDesc());
- EasyMock.expect(plugins.transformations()).andReturn(transformations).times(1);
-
- Set<PluginDesc<Predicate<?>>> predicates = new HashSet<>();
- predicates.add(predicatePluginDesc());
- EasyMock.expect(plugins.predicates()).andReturn(predicates).times(2);
-
- replayAll();
+ when(plugins.transformations()).thenReturn(Collections.singleton(transformationPluginDesc()));
+ when(plugins.predicates()).thenReturn(Collections.singleton(predicatePluginDesc()));
// Define 2 transformations. One has a class defined and so can get embedded configs, the other is missing
Review Comment:
Yep, looks like it. `predX` and `predY`
Changed.
--
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] mimaison commented on pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
mimaison commented on PR #12473:
URL: https://github.com/apache/kafka/pull/12473#issuecomment-1224259431
Tests passed locally, the CI failure `KRaftClusterTest > testCreateClusterAndCreateListDeleteTopic() FAILED` is unrelated. Merging to trunk.
--
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] C0urante commented on pull request #12473: KAFKA-13133: Replace EasyMock and PowerMock with Mockito for AbstractHerderTest
Posted by GitBox <gi...@apache.org>.
C0urante commented on PR #12473:
URL: https://github.com/apache/kafka/pull/12473#issuecomment-1222533204
Since this is already receiving attention, I'll redirect my focus to other PRs that haven't gotten anything yet for now.
@mimaison Please LMK if you'd like me to lend a hand on this one though :)
--
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