pandaapo commented on code in PR #4557:
URL: https://github.com/apache/eventmesh/pull/4557#discussion_r1394066230


##########
eventmesh-connectors/eventmesh-connector-dingding/src/main/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.dingding.sink.connector;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import 
org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType;
+import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig;
+import org.apache.eventmesh.openconnect.api.config.Config;
+import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
+import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext;
+import org.apache.eventmesh.openconnect.api.sink.Sink;
+import 
org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import com.aliyun.tea.TeaException;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import lombok.SneakyThrows;
+
+public class DingDingSinkConnector implements Sink {
+
+    public static final Cache<String, String> AUTH_CACHE = 
CacheBuilder.newBuilder()
+        .initialCapacity(12)
+        .maximumSize(10)
+        .concurrencyLevel(5)
+        .expireAfterWrite(20, TimeUnit.MINUTES)
+        .build();
+
+    public static final String ACCESS_TOKEN_CACHE_KEY = "access_token";
+
+    private DingDingSinkConfig sinkConfig;
+
+    private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient;
+
+    private com.aliyun.dingtalkoauth2_1_0.Client authClient;
+
+    private volatile boolean isRunning = false;
+
+    @Override
+    public Class<? extends Config> configClass() {
+        return DingDingSinkConfig.class;
+    }
+
+    @Override
+    public void init(Config config) throws Exception {
+        // init config for dingding sink connector
+        this.sinkConfig = (DingDingSinkConfig) config;
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void init(ConnectorContext connectorContext) throws Exception {
+        // init config for dingding source connector
+        SinkConnectorContext sinkConnectorContext = (SinkConnectorContext) 
connectorContext;
+        this.sinkConfig = (DingDingSinkConfig) 
sinkConnectorContext.getSinkConfig();
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void start() {
+        isRunning = true;
+    }
+
+    @Override
+    public void commit(ConnectRecord record) {
+
+    }
+
+    @Override
+    public String name() {
+        return this.sinkConfig.getSinkConnectorConfig().getConnectorName();
+    }
+
+    @Override
+    public void stop() {
+        isRunning = false;
+    }
+
+    public boolean isRunning() {
+        return isRunning;
+    }
+
+    @SneakyThrows
+    @Override
+    public void put(List<ConnectRecord> sinkRecords) {
+        for (ConnectRecord record : sinkRecords) {
+            String accessToken = getAccessToken();
+            com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders 
orgGroupSendHeaders =
+                new com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders();

Review Comment:
   Could you put all these package names at the top of the code to make it 
clearer?
   
   能否将代码中这些包名都放到最上面,使代码更清晰?



##########
eventmesh-openconnect/eventmesh-openconnect-offsetmgmt-plugin/eventmesh-openconnect-offsetmgmt-api/src/main/java/org/apache/eventmesh/openconnect/offsetmgmt/api/constants/ConnectRecordExtensionKeys.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.openconnect.offsetmgmt.api.constants;
+
+/**
+ * Constants of record extension key.
+ */
+public interface ConnectRecordExtensionKeys {
+
+    String DINGDING_TEMPLATE_TYPE_KEY = "dingDingTemplateTypeKey";
+
+    String DINGDING_MARKDOWN_MESSAGE_TITLE = "dingDingMarkdownMessageTitle";
+}

Review Comment:
   Considering these two fields, would it be more appropriate to define this 
constant class in the connector-dingding module? Let each connector define its 
own unique constants.
   
   考虑到这两个属性,将这个常量类定义在connector-dingding模块中是否更合适?让各个connector分别定义自己特有的常量。



##########
eventmesh-connectors/eventmesh-connector-dingding/src/test/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnectorTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.dingding.sink.connector;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import 
org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType;
+import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig;
+import 
org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordOffset;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordPartition;
+import org.apache.eventmesh.openconnect.util.ConfigUtil;
+
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.platform.commons.support.HierarchyTraversalMode;
+import org.junit.platform.commons.support.ReflectionSupport;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponseBody;
+
+@ExtendWith(MockitoExtension.class)
+public class DingDingSinkConnectorTest {
+
+    @Spy
+    private DingDingSinkConnector connector;
+
+    @Mock
+    private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient;
+
+    @Mock
+    private com.aliyun.dingtalkoauth2_1_0.Client authClient;
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        Mockito.doReturn(null).when(sendMessageClient)
+            .orgGroupSendWithOptions(Mockito.any(), Mockito.any(), 
Mockito.any());
+        GetAccessTokenResponse response = new GetAccessTokenResponse();
+        GetAccessTokenResponseBody body = new GetAccessTokenResponseBody();
+        body.setAccessToken("testAccessToken");
+        response.setBody(body);
+        
Mockito.doReturn(response).when(authClient).getAccessToken(Mockito.any());
+
+        DingDingSinkConfig sinkConfig = (DingDingSinkConfig) 
ConfigUtil.parse(connector.configClass());
+        connector.init(sinkConfig);
+        Field sendMessageClientField = 
ReflectionSupport.findFields(connector.getClass(),
+            (f) -> f.getName().equals("sendMessageClient"),
+            HierarchyTraversalMode.BOTTOM_UP).get(0);
+        Field authClientField = 
ReflectionSupport.findFields(connector.getClass(),
+            (f) -> f.getName().equals("authClient"),
+            HierarchyTraversalMode.BOTTOM_UP).get(0);
+        sendMessageClientField.setAccessible(true);
+        authClientField.setAccessible(true);
+        sendMessageClientField.set(connector, sendMessageClient);
+        authClientField.set(connector, authClient);
+        connector.start();
+    }
+
+    @Test
+    public void testSendPlainTextMessageToDingDing() throws Exception {
+        final int times = 3;
+        List<ConnectRecord> records = new ArrayList<>();
+        for (int i = 0; i < times; i++) {
+            RecordPartition partition = new RecordPartition();
+            RecordOffset offset = new RecordOffset();
+            ConnectRecord connectRecord = new ConnectRecord(partition, offset,
+                System.currentTimeMillis(), "Hello, 
EventMesh!".getBytes(StandardCharsets.UTF_8));
+            
connectRecord.addExtension(ConnectRecordExtensionKeys.DINGDING_TEMPLATE_TYPE_KEY,
+                DingDingMessageTemplateType.PLAIN_TEXT.getTemplateKey());
+            records.add(connectRecord);
+        }
+        connector.put(records);
+        verify(sendMessageClient, times(times)).orgGroupSendWithOptions(any(), 
any(), any());
+        // verify for access token cache.
+        verify(authClient, times(1)).getAccessToken(any());
+    }
+
+    @Test
+    public void testSendMarkDownMessageToDingDing() throws Exception {
+        final int times = 3;
+        List<ConnectRecord> records = new ArrayList<>();
+        for (int i = 0; i < times; i++) {
+            RecordPartition partition = new RecordPartition();
+            RecordOffset offset = new RecordOffset();
+            ConnectRecord connectRecord = new ConnectRecord(partition, offset,
+                System.currentTimeMillis(), "***Hello, 
EventMesh!***".getBytes(StandardCharsets.UTF_8));
+            
connectRecord.addExtension(ConnectRecordExtensionKeys.DINGDING_TEMPLATE_TYPE_KEY,
+                DingDingMessageTemplateType.MARKDOWN.getTemplateKey());
+            
connectRecord.addExtension(ConnectRecordExtensionKeys.DINGDING_MARKDOWN_MESSAGE_TITLE,
+                "EventMesh MarkDown Message");
+            records.add(connectRecord);
+        }
+        connector.put(records);
+        verify(sendMessageClient, times(times)).orgGroupSendWithOptions(any(), 
any(), any());
+        // verify for access token cache.
+        verify(authClient, times(1)).getAccessToken(any());

Review Comment:
   Could you eliminate one of the tests for sending plain text and the test for 
sending markdown text? From the perspective of your verification target 
`verify()`, there is no difference between the two. In essence, the only 
difference between the two is that the ConnectRecord has a different 
`extension`.
   
   
发送普通文本的测试和这个发送markdown文本的测试,是不是可以省去一个?因为从您的校验目标`verify()`来看,其他这两者没有区别。实质上两者的区别也只是ConnectRecord差了一个`extension`。



##########
eventmesh-openconnect/eventmesh-openconnect-offsetmgmt-plugin/eventmesh-openconnect-offsetmgmt-api/src/main/java/org/apache/eventmesh/openconnect/offsetmgmt/api/constants/ConnectRecordExtensionKeys.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.openconnect.offsetmgmt.api.constants;
+
+/**
+ * Constants of record extension key.
+ */
+public interface ConnectRecordExtensionKeys {
+
+    String DINGDING_TEMPLATE_TYPE_KEY = "dingDingTemplateTypeKey";
+
+    String DINGDING_MARKDOWN_MESSAGE_TITLE = "dingDingMarkdownMessageTitle";
+}

Review Comment:
   Considering these two fields, would it be more appropriate to define this 
constant class in the connector-dingding module? Let each connector define its 
own unique constants.
   
   考虑到这两个属性,将这个常量类定义在connector-dingding模块中是否更合适?让各个connector分别定义自己特有的常量。



##########
eventmesh-connectors/eventmesh-connector-dingding/src/main/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.dingding.sink.connector;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import 
org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType;
+import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig;
+import org.apache.eventmesh.openconnect.api.config.Config;
+import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
+import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext;
+import org.apache.eventmesh.openconnect.api.sink.Sink;
+import 
org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import com.aliyun.tea.TeaException;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import lombok.SneakyThrows;
+
+public class DingDingSinkConnector implements Sink {
+
+    public static final Cache<String, String> AUTH_CACHE = 
CacheBuilder.newBuilder()
+        .initialCapacity(12)
+        .maximumSize(10)
+        .concurrencyLevel(5)
+        .expireAfterWrite(20, TimeUnit.MINUTES)
+        .build();
+
+    public static final String ACCESS_TOKEN_CACHE_KEY = "access_token";
+
+    private DingDingSinkConfig sinkConfig;
+
+    private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient;
+
+    private com.aliyun.dingtalkoauth2_1_0.Client authClient;
+
+    private volatile boolean isRunning = false;
+
+    @Override
+    public Class<? extends Config> configClass() {
+        return DingDingSinkConfig.class;
+    }
+
+    @Override
+    public void init(Config config) throws Exception {
+        // init config for dingding sink connector
+        this.sinkConfig = (DingDingSinkConfig) config;
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void init(ConnectorContext connectorContext) throws Exception {
+        // init config for dingding source connector
+        SinkConnectorContext sinkConnectorContext = (SinkConnectorContext) 
connectorContext;
+        this.sinkConfig = (DingDingSinkConfig) 
sinkConnectorContext.getSinkConfig();
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void start() {
+        isRunning = true;
+    }
+
+    @Override
+    public void commit(ConnectRecord record) {
+
+    }
+
+    @Override
+    public String name() {
+        return this.sinkConfig.getSinkConnectorConfig().getConnectorName();
+    }
+
+    @Override
+    public void stop() {
+        isRunning = false;
+    }
+
+    public boolean isRunning() {
+        return isRunning;
+    }
+
+    @SneakyThrows
+    @Override
+    public void put(List<ConnectRecord> sinkRecords) {
+        for (ConnectRecord record : sinkRecords) {
+            String accessToken = getAccessToken();
+            com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders 
orgGroupSendHeaders =
+                new com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders();

Review Comment:
   Could you put all these package names at the top of the code to make it 
clearer?
   
   能否将代码中这些包名都放到最上面,使代码更清晰?



##########
eventmesh-connectors/eventmesh-connector-dingding/src/test/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnectorTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.dingding.sink.connector;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import 
org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType;
+import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig;
+import 
org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordOffset;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordPartition;
+import org.apache.eventmesh.openconnect.util.ConfigUtil;
+
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.platform.commons.support.HierarchyTraversalMode;
+import org.junit.platform.commons.support.ReflectionSupport;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponseBody;
+
+@ExtendWith(MockitoExtension.class)
+public class DingDingSinkConnectorTest {
+
+    @Spy
+    private DingDingSinkConnector connector;
+
+    @Mock
+    private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient;
+
+    @Mock
+    private com.aliyun.dingtalkoauth2_1_0.Client authClient;
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        Mockito.doReturn(null).when(sendMessageClient)
+            .orgGroupSendWithOptions(Mockito.any(), Mockito.any(), 
Mockito.any());
+        GetAccessTokenResponse response = new GetAccessTokenResponse();
+        GetAccessTokenResponseBody body = new GetAccessTokenResponseBody();
+        body.setAccessToken("testAccessToken");
+        response.setBody(body);
+        
Mockito.doReturn(response).when(authClient).getAccessToken(Mockito.any());
+
+        DingDingSinkConfig sinkConfig = (DingDingSinkConfig) 
ConfigUtil.parse(connector.configClass());
+        connector.init(sinkConfig);
+        Field sendMessageClientField = 
ReflectionSupport.findFields(connector.getClass(),
+            (f) -> f.getName().equals("sendMessageClient"),
+            HierarchyTraversalMode.BOTTOM_UP).get(0);
+        Field authClientField = 
ReflectionSupport.findFields(connector.getClass(),
+            (f) -> f.getName().equals("authClient"),
+            HierarchyTraversalMode.BOTTOM_UP).get(0);
+        sendMessageClientField.setAccessible(true);
+        authClientField.setAccessible(true);
+        sendMessageClientField.set(connector, sendMessageClient);
+        authClientField.set(connector, authClient);
+        connector.start();
+    }
+
+    @Test
+    public void testSendPlainTextMessageToDingDing() throws Exception {
+        final int times = 3;
+        List<ConnectRecord> records = new ArrayList<>();
+        for (int i = 0; i < times; i++) {
+            RecordPartition partition = new RecordPartition();
+            RecordOffset offset = new RecordOffset();
+            ConnectRecord connectRecord = new ConnectRecord(partition, offset,
+                System.currentTimeMillis(), "Hello, 
EventMesh!".getBytes(StandardCharsets.UTF_8));
+            
connectRecord.addExtension(ConnectRecordExtensionKeys.DINGDING_TEMPLATE_TYPE_KEY,
+                DingDingMessageTemplateType.PLAIN_TEXT.getTemplateKey());
+            records.add(connectRecord);
+        }
+        connector.put(records);
+        verify(sendMessageClient, times(times)).orgGroupSendWithOptions(any(), 
any(), any());
+        // verify for access token cache.
+        verify(authClient, times(1)).getAccessToken(any());
+    }
+
+    @Test
+    public void testSendMarkDownMessageToDingDing() throws Exception {
+        final int times = 3;
+        List<ConnectRecord> records = new ArrayList<>();
+        for (int i = 0; i < times; i++) {
+            RecordPartition partition = new RecordPartition();
+            RecordOffset offset = new RecordOffset();
+            ConnectRecord connectRecord = new ConnectRecord(partition, offset,
+                System.currentTimeMillis(), "***Hello, 
EventMesh!***".getBytes(StandardCharsets.UTF_8));
+            
connectRecord.addExtension(ConnectRecordExtensionKeys.DINGDING_TEMPLATE_TYPE_KEY,
+                DingDingMessageTemplateType.MARKDOWN.getTemplateKey());
+            
connectRecord.addExtension(ConnectRecordExtensionKeys.DINGDING_MARKDOWN_MESSAGE_TITLE,
+                "EventMesh MarkDown Message");
+            records.add(connectRecord);
+        }
+        connector.put(records);
+        verify(sendMessageClient, times(times)).orgGroupSendWithOptions(any(), 
any(), any());
+        // verify for access token cache.
+        verify(authClient, times(1)).getAccessToken(any());

Review Comment:
   Could you eliminate one of the tests for sending plain text and the test for 
sending markdown text? From the perspective of your verification target 
`verify()`, there is no difference between the two. In essence, the only 
difference between the two is that the ConnectRecord has a different 
`extension`.
   
   
发送普通文本的测试和这个发送markdown文本的测试,是不是可以省去一个?因为从您的校验目标`verify()`来看,其他这两者没有区别。实质上两者的区别也只是ConnectRecord差了一个`extension`。



##########
eventmesh-connectors/eventmesh-connector-dingding/src/main/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.dingding.sink.connector;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import 
org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType;
+import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig;
+import org.apache.eventmesh.openconnect.api.config.Config;
+import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
+import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext;
+import org.apache.eventmesh.openconnect.api.sink.Sink;
+import 
org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import com.aliyun.tea.TeaException;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import lombok.SneakyThrows;
+
+public class DingDingSinkConnector implements Sink {
+
+    public static final Cache<String, String> AUTH_CACHE = 
CacheBuilder.newBuilder()
+        .initialCapacity(12)
+        .maximumSize(10)
+        .concurrencyLevel(5)
+        .expireAfterWrite(20, TimeUnit.MINUTES)
+        .build();
+
+    public static final String ACCESS_TOKEN_CACHE_KEY = "access_token";
+
+    private DingDingSinkConfig sinkConfig;
+
+    private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient;
+
+    private com.aliyun.dingtalkoauth2_1_0.Client authClient;
+
+    private volatile boolean isRunning = false;
+
+    @Override
+    public Class<? extends Config> configClass() {
+        return DingDingSinkConfig.class;
+    }
+
+    @Override
+    public void init(Config config) throws Exception {
+        // init config for dingding sink connector
+        this.sinkConfig = (DingDingSinkConfig) config;
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void init(ConnectorContext connectorContext) throws Exception {
+        // init config for dingding source connector
+        SinkConnectorContext sinkConnectorContext = (SinkConnectorContext) 
connectorContext;
+        this.sinkConfig = (DingDingSinkConfig) 
sinkConnectorContext.getSinkConfig();
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void start() {
+        isRunning = true;
+    }
+
+    @Override
+    public void commit(ConnectRecord record) {
+
+    }
+
+    @Override
+    public String name() {
+        return this.sinkConfig.getSinkConnectorConfig().getConnectorName();
+    }
+
+    @Override
+    public void stop() {
+        isRunning = false;
+    }
+
+    public boolean isRunning() {
+        return isRunning;
+    }
+
+    @SneakyThrows
+    @Override
+    public void put(List<ConnectRecord> sinkRecords) {

Review Comment:
   In this connector, I did not see the configuration of the EventMesh runtime, 
so I am a bit confused where does the connector obtain data?
   
   在该connector中,并没有看到EventMesh runtime的配置,所以我有点困惑该connector从哪里获取数据?



##########
eventmesh-connectors/eventmesh-connector-dingding/src/main/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnector.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.dingding.sink.connector;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import 
org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType;
+import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig;
+import org.apache.eventmesh.openconnect.api.config.Config;
+import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
+import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext;
+import org.apache.eventmesh.openconnect.api.sink.Sink;
+import 
org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import com.aliyun.tea.TeaException;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import lombok.SneakyThrows;
+
+public class DingDingSinkConnector implements Sink {
+
+    public static final Cache<String, String> AUTH_CACHE = 
CacheBuilder.newBuilder()
+        .initialCapacity(12)
+        .maximumSize(10)
+        .concurrencyLevel(5)
+        .expireAfterWrite(20, TimeUnit.MINUTES)
+        .build();
+
+    public static final String ACCESS_TOKEN_CACHE_KEY = "access_token";
+
+    private DingDingSinkConfig sinkConfig;
+
+    private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient;
+
+    private com.aliyun.dingtalkoauth2_1_0.Client authClient;
+
+    private volatile boolean isRunning = false;
+
+    @Override
+    public Class<? extends Config> configClass() {
+        return DingDingSinkConfig.class;
+    }
+
+    @Override
+    public void init(Config config) throws Exception {
+        // init config for dingding sink connector
+        this.sinkConfig = (DingDingSinkConfig) config;
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void init(ConnectorContext connectorContext) throws Exception {
+        // init config for dingding source connector
+        SinkConnectorContext sinkConnectorContext = (SinkConnectorContext) 
connectorContext;
+        this.sinkConfig = (DingDingSinkConfig) 
sinkConnectorContext.getSinkConfig();
+        sendMessageClient = createSendMessageClient();
+        authClient = createOAuthClient();
+    }
+
+    @Override
+    public void start() {
+        isRunning = true;
+    }
+
+    @Override
+    public void commit(ConnectRecord record) {
+
+    }
+
+    @Override
+    public String name() {
+        return this.sinkConfig.getSinkConnectorConfig().getConnectorName();
+    }
+
+    @Override
+    public void stop() {
+        isRunning = false;
+    }
+
+    public boolean isRunning() {
+        return isRunning;
+    }
+
+    @SneakyThrows
+    @Override
+    public void put(List<ConnectRecord> sinkRecords) {

Review Comment:
   In this connector, I did not see the configuration of the EventMesh runtime, 
so I am a bit confused where does the connector obtain data?
   
   在该connector中,并没有看到EventMesh runtime的配置,所以我有点困惑该connector从哪里获取数据?



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