mdedetrich commented on code in PR #12728:
URL: https://github.com/apache/kafka/pull/12728#discussion_r1003415030


##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/standalone/StandaloneHerderTest.java:
##########
@@ -319,35 +318,28 @@ public void testRestartConnectorNewTaskConfigs() throws 
Exception {
 
         Map<String, String> config = connectorConfig(SourceSink.SOURCE);
         ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
-        Connector connectorMock = PowerMock.createMock(SourceConnector.class);
+        Connector connectorMock = mock(SourceConnector.class);
         expectConfigValidation(connectorMock, true, config);
 
         worker.stopAndAwaitConnector(CONNECTOR_NAME);
-        EasyMock.expectLastCall();
+        doNothing().when(worker).stopAndAwaitConnector(CONNECTOR_NAME);
 
-        Capture<Callback<TargetState>> onStart = EasyMock.newCapture();
-        worker.startConnector(eq(CONNECTOR_NAME), eq(config), 
EasyMock.anyObject(HerderConnectorContext.class),
-                eq(herder), eq(TargetState.STARTED), 
EasyMock.capture(onStart));
-        EasyMock.expectLastCall().andAnswer(() -> {
+        final ArgumentCaptor<Callback<TargetState>> onStart = 
ArgumentCaptor.forClass(Callback.class);
+        doAnswer(invocation -> {
             onStart.getValue().onCompletion(null, TargetState.STARTED);
             return true;
-        });
+        }).when(worker).startConnector(eq(CONNECTOR_NAME), eq(config), 
any(HerderConnectorContext.class),
+            eq(herder), eq(TargetState.STARTED), onStart.capture());
 
-        
EasyMock.expect(worker.connectorNames()).andReturn(Collections.singleton(CONNECTOR_NAME));
-        EasyMock.expect(worker.getPlugins()).andReturn(plugins);
+        
when(worker.connectorNames()).thenReturn(Collections.singleton(CONNECTOR_NAME));
+        when(worker.getPlugins()).thenReturn(plugins);
         // changed task configs, expect a new set of tasks to be brought up 
(and the old ones to be stopped)
         Map<String, String> taskConfigs = taskConfig(SourceSink.SOURCE);
         taskConfigs.put("k", "v");
-        EasyMock.expect(worker.connectorTaskConfigs(CONNECTOR_NAME, new 
SourceConnectorConfig(plugins, config, 
true))).andReturn(Collections.singletonList(taskConfigs));
+        when(worker.connectorTaskConfigs(CONNECTOR_NAME, new 
SourceConnectorConfig(plugins, config, true)))
+            .thenReturn(Collections.singletonList(taskConfigs));
 
-        worker.stopAndAwaitTasks(Collections.singletonList(taskId));

Review Comment:
   > Don't we still need to verify that this call takes place?
   
   So if you are talking specifically about 
`worker.stopAndAwaitTasks(Collections.singletonList(taskId));`, at 
https://github.com/apache/kafka/pull/12728/files#r991517316 you mentioned 
removing the reference to `taskId` which means that this is not relevant 
anymore?
   
   > I think this test may need to be reordered so that mocking behavior is set 
up immediately before invoking methods on the herder instance; otherwise, we 
end up overwriting older mocks, which I believe is happening here.
   
   Which mocking behaviour are you specifically talking about wrt re-ordering? 
Currently
   
   ```java
           final ArgumentCaptor<Callback<TargetState>> onStart = 
ArgumentCaptor.forClass(Callback.class);
           doAnswer(invocation -> {
               onStart.getValue().onCompletion(null, TargetState.STARTED);
               return true;
           }).when(worker).startConnector(eq(CONNECTOR_NAME), eq(config), 
any(HerderConnectorContext.class),
               eq(herder), eq(TargetState.STARTED), onStart.capture());
   
           
when(worker.connectorNames()).thenReturn(Collections.singleton(CONNECTOR_NAME));
           when(worker.getPlugins()).thenReturn(plugins);
           // changed task configs, expect a new set of tasks to be brought up 
(and the old ones to be stopped)
           Map<String, String> taskConfigs = taskConfig(SourceSink.SOURCE);
           taskConfigs.put("k", "v");
           when(worker.connectorTaskConfigs(CONNECTOR_NAME, new 
SourceConnectorConfig(plugins, config, true)))
               .thenReturn(Collections.singletonList(taskConfigs));
   
           when(worker.startSourceTask(eq(new ConnectorTaskId(CONNECTOR_NAME, 
0)), any(), eq(connectorConfig(SourceSink.SOURCE)), eq(taskConfigs), 
eq(herder), eq(TargetState.STARTED))).thenReturn(true);
   ```
   
   is just before
   
   ```java
           herder.putConnectorConfig(CONNECTOR_NAME, config, false, 
createCallback);
           Herder.Created<ConnectorInfo> connectorInfo = 
createCallback.get(1000L, TimeUnit.SECONDS);
           assertEquals(createdInfo(SourceSink.SOURCE), connectorInfo.result());
   ```
   



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

Reply via email to