ivanyu commented on code in PR #6934:
URL: https://github.com/apache/kafka/pull/6934#discussion_r1587970461


##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/standalone/StandaloneHerderTest.java:
##########
@@ -751,6 +754,74 @@ public void testPutConnectorConfig() throws Exception {
         verifyNoMoreInteractions(connectorConfigCb);
     }
 
+    @Test
+    public void testPatchConnectorConfigNotFound() {
+        Map<String, String> connConfigPatch = new HashMap<>();
+        connConfigPatch.put("foo1", "baz1");
+
+        Callback<Herder.Created<ConnectorInfo>> patchCallback = 
mock(Callback.class);
+        herder.patchConnectorConfig(CONNECTOR_NAME, connConfigPatch, 
patchCallback);
+
+        ArgumentCaptor<NotFoundException> exceptionCaptor = 
ArgumentCaptor.forClass(NotFoundException.class);
+        verify(patchCallback).onCompletion(exceptionCaptor.capture(), 
isNull());
+        assertEquals(exceptionCaptor.getValue().getMessage(), "Connector " + 
CONNECTOR_NAME + " not found");
+        assertNull(exceptionCaptor.getValue().getCause());
+    }
+
+    @Test
+    public void testPatchConnectorConfig() throws ExecutionException, 
InterruptedException, TimeoutException {
+        // Create the connector.
+        Map<String, String> originalConnConfig = 
connectorConfig(SourceSink.SOURCE);
+        originalConnConfig.put("foo1", "bar1");
+        originalConnConfig.put("foo2", "bar2");
+
+        Map<String, String> connConfigPatch = new HashMap<>();
+        connConfigPatch.put("foo1", "changed");
+        connConfigPatch.put("foo2", null);
+        connConfigPatch.put("foo3", "added");
+
+        Map<String, String> patchedConnConfig = new 
HashMap<>(originalConnConfig);
+        patchedConnConfig.put("foo1", "changed");
+        patchedConnConfig.remove("foo2");
+        patchedConnConfig.put("foo3", "added");
+
+        expectAdd(SourceSink.SOURCE);
+        Connector connectorMock = mock(SourceConnector.class);
+        expectConfigValidation(SourceSink.SOURCE, originalConnConfig, 
patchedConnConfig);
+
+        expectConnectorStartingWithoutTasks(originalConnConfig);
+
+        herder.putConnectorConfig(CONNECTOR_NAME, originalConnConfig, false, 
createCallback);
+        createCallback.get(1000L, TimeUnit.SECONDS);
+
+        expectConnectorStartingWithoutTasks(patchedConnConfig);
+
+        FutureCallback<Herder.Created<ConnectorInfo>> patchCallback = new 
FutureCallback<>();
+        herder.patchConnectorConfig(CONNECTOR_NAME, connConfigPatch, 
patchCallback);
+
+        Map<String, String> returnedConfig = patchCallback.get(1000L, 
TimeUnit.SECONDS).result().config();
+        assertEquals(patchedConnConfig, returnedConfig);
+
+        // Also check the returned config when requested.
+        FutureCallback<Map<String, String>> configCallback = new 
FutureCallback<>();
+        herder.connectorConfig(CONNECTOR_NAME, configCallback);
+
+        Map<String, String> returnedConfig2 = configCallback.get(1000L, 
TimeUnit.SECONDS);
+        assertEquals(patchedConnConfig, returnedConfig2);
+    }
+
+    private void expectConnectorStartingWithoutTasks(Map<String, String> 
config) {

Review Comment:
   Thanks, did the latter



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