hhuang1231 commented on code in PR #4599:
URL: https://github.com/apache/eventmesh/pull/4599#discussion_r1415845536


##########
eventmesh-connectors/eventmesh-connector-lark/src/test/java/org/apache/eventmesh/connector/lark/sink/ImServiceHandlerTest.java:
##########
@@ -85,31 +88,75 @@ public void setup() throws Exception {
 
     @Test
     public void testRegularSink() throws Exception {
+        sinkConnectorConfig.setSinkAsync("false");
+        init();
+        regularSink();
+    }
+
+    @Test
+    public void testRegularSinkAsync() throws Exception {
+        sinkConnectorConfig.setSinkAsync("true");
+        init();
+        regularSink();
+    }
+
+    private void regularSink() throws Exception {
         final int times = 3;
         for (int i = 0; i < times; i++) {
             RecordPartition partition = new RecordPartition();
             RecordOffset offset = new RecordOffset();
             ConnectRecord connectRecord = new ConnectRecord(partition, offset,
                     System.currentTimeMillis(), 
"test-lark".getBytes(StandardCharsets.UTF_8));
-            imServiceHandler.sink(connectRecord);
+            if (Boolean.parseBoolean(sinkConnectorConfig.getSinkAsync())) {
+                imServiceHandler.sinkAsync(connectRecord);
+                long retryDelayInMills = 
Long.parseLong(sinkConnectorConfig.getRetryDelayInMills());
+                long duration = retryDelayInMills * times;
+                Thread.sleep(duration);
+            } else {
+                imServiceHandler.sink(connectRecord);
+            }
         }
-
-        verify(message, times(times)).create(any(), any());
     }
 
     @Test
     public void testRetrySink() throws Exception {
-        doThrow(new Exception()).when(message).create(any(), any());
+        sinkConnectorConfig.setSinkAsync("false");
+        init();
+        retrySink();
+    }
+
+    @Test
+    public void testRetrySinkAsync() throws Exception {
+        sinkConnectorConfig.setSinkAsync("true");
+        init();
+        retrySink();
+    }
+
+    private void retrySink() throws Exception {
+        CreateMessageResp resp = new CreateMessageResp();
+        resp.setCode(1);
+        doReturn(resp).when(message).create(any(), any());
         final int times = 3;
+        long retryDelayInMills = 
Long.parseLong(sinkConnectorConfig.getRetryDelayInMills());
+        int maxRetryTimes = 
Integer.parseInt(sinkConnectorConfig.getMaxRetryTimes());
+        // (maxRetryTimes + 1) event are actually sent
+        int sinkTimes = times * (maxRetryTimes + 1);
+        long duration = retryDelayInMills * sinkTimes;
+
         for (int i = 0; i < times; i++) {
             RecordPartition partition = new RecordPartition();
             RecordOffset offset = new RecordOffset();
             ConnectRecord connectRecord = new ConnectRecord(partition, offset,
                     System.currentTimeMillis(), 
"test-lark".getBytes(StandardCharsets.UTF_8));
-            Assertions.assertThrows(Exception.class, () -> 
imServiceHandler.sink(connectRecord));
-        }
+            if (Boolean.parseBoolean(sinkConnectorConfig.getSinkAsync())) {
+                imServiceHandler.sinkAsync(connectRecord);
 
-        // (maxRetryTimes + 1) event are actually sent
-        verify(message, times(times * 
(Integer.parseInt(sinkConnectorConfig.getMaxRetryTimes()) + 1))).create(any(), 
any());
+                Thread.sleep(duration);

Review Comment:
   Yes,i make a mistake.I will fix it.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to