codope commented on code in PR #10970: URL: https://github.com/apache/hudi/pull/10970#discussion_r1557488353
########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/callback/client/http/TestCallbackHttpClient.java: ########## @@ -101,43 +107,85 @@ private void mockResponse(int statusCode) { } @Test - public void sendPayloadShouldLogWhenRequestFailed() throws IOException { + void sendPayloadShouldLogWhenRequestFailed() throws IOException { when(httpClient.execute(any())).thenThrow(IOException.class); HoodieWriteCommitHttpCallbackClient hoodieWriteCommitCallBackHttpClient = - new HoodieWriteCommitHttpCallbackClient("fake_api_key", "fake_url", httpClient); - hoodieWriteCommitCallBackHttpClient.send("{}"); + new HoodieWriteCommitHttpCallbackClient(FAKE_API_KEY, FAKE_URL, httpClient, null); + hoodieWriteCommitCallBackHttpClient.send(CALLBACK_MSG); verify(appender).append(logCaptor.capture()); assertEquals("Failed to send callback.", logCaptor.getValue().getMessage().getFormattedMessage()); assertEquals(Level.WARN, logCaptor.getValue().getLevel()); } @Test - public void sendPayloadShouldLogUnsuccessfulSending() { + void sendPayloadShouldLogUnsuccessfulSending() { mockResponse(401); when(httpResponse.toString()).thenReturn("unauthorized"); HoodieWriteCommitHttpCallbackClient hoodieWriteCommitCallBackHttpClient = - new HoodieWriteCommitHttpCallbackClient("fake_api_key", "fake_url", httpClient); - hoodieWriteCommitCallBackHttpClient.send("{}"); + new HoodieWriteCommitHttpCallbackClient(FAKE_API_KEY, FAKE_URL, httpClient, null); + hoodieWriteCommitCallBackHttpClient.send(CALLBACK_MSG); verify(appender).append(logCaptor.capture()); assertEquals("Failed to send callback message. Response was unauthorized", logCaptor.getValue().getMessage().getFormattedMessage()); assertEquals(Level.WARN, logCaptor.getValue().getLevel()); } @Test - public void sendPayloadShouldLogSuccessfulSending() { + void sendPayloadShouldLogSuccessfulSending() { mockResponse(202); + Map<String, String> customHeaders = new HashMap<>(); + customHeaders.put("key1", "val1"); + customHeaders.put("key2", "val2"); HoodieWriteCommitHttpCallbackClient hoodieWriteCommitCallBackHttpClient = - new HoodieWriteCommitHttpCallbackClient("fake_api_key", "fake_url", httpClient); - hoodieWriteCommitCallBackHttpClient.send("{}"); + new HoodieWriteCommitHttpCallbackClient(FAKE_API_KEY, FAKE_URL, httpClient, customHeaders); + hoodieWriteCommitCallBackHttpClient.send(CALLBACK_MSG); verify(appender).append(logCaptor.capture()); - assertTrue(logCaptor.getValue().getMessage().getFormattedMessage().startsWith("Sent Callback data")); + assertTrue(logCaptor.getValue().getMessage().getFormattedMessage().startsWith("Sent Callback data with 2 custom headers")); assertEquals(Level.INFO, logCaptor.getValue().getLevel()); } + @Test + void testParsingCustomHeaders() { Review Comment: let's also test some negative scenarios when customer header is null/empty. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/callback/client/http/HoodieWriteCommitHttpCallbackClient.java: ########## @@ -43,36 +48,42 @@ public class HoodieWriteCommitHttpCallbackClient implements Closeable { private static final Logger LOG = LoggerFactory.getLogger(HoodieWriteCommitHttpCallbackClient.class); public static final String HEADER_KEY_API_KEY = "HUDI-CALLBACK-KEY"; + public static final String HEADERS_DELIMITER = ";"; + public static final String HEADERS_KV_DELIMITER = ":"; Review Comment: Can these be private or package-protected? -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org