pandaapo commented on code in PR #4582:
URL: https://github.com/apache/eventmesh/pull/4582#discussion_r1405941177
##########
eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java:
##########
@@ -25,17 +27,29 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
public class SpringSourceConnectorTest {
@Spy
private SpringSourceConnector connector;
Review Comment:
The @Spy annotation doesn't make much sense in this context since there are
no mocks of the SpringSourceConnector object in this test.
这个@spy注解的意义不大,因为该测试中没有对SpringSourceConnector对象进行任何模拟。
##########
eventmesh-connectors/eventmesh-connector-spring/src/main/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnector.java:
##########
@@ -131,6 +144,40 @@ public void send(Object message, SendMessageCallback
workerCallback) {
RecordOffset offset = new RecordOffset();
ConnectRecord record = new ConnectRecord(partition, offset,
System.currentTimeMillis(), message);
record.addExtension(SourceWorker.CALLBACK_EXTENSION, workerCallback);
+ addSpringEnvironmentPropertyExtensions(record);
queue.offer(record);
}
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
+ private void addSpringEnvironmentPropertyExtensions(ConnectRecord
connectRecord) {
+ ConfigurableApplicationContext context =
(ConfigurableApplicationContext) applicationContext;
+ MutablePropertySources propertySources =
context.getEnvironment().getPropertySources();
+ for (PropertySource<?> propertySource : propertySources) {
+ if (!(propertySource instanceof OriginTrackedMapPropertySource)) {
+ continue;
+ }
+ OriginTrackedMapPropertySource originTrackedMapPropertySource =
+ (OriginTrackedMapPropertySource) propertySource;
+ String[] keys = originTrackedMapPropertySource.getPropertyNames();
+ for (String key : keys) {
+ if (!key.startsWith(CONNECTOR_PROPERTY_PREFIX)) {
+ continue;
+ }
+ Object value = null;
+ try {
+ value = originTrackedMapPropertySource.getProperty(key);
+ if (value != null) {
+
connectRecord.addExtension(key.replaceAll(CONNECTOR_PROPERTY_PREFIX,
"").toLowerCase(),
+ value.toString());
Review Comment:
Which one is more appropriate here, using toString() or directly casting the
type?
这里用toString()和直接转换类型哪个更合适?
##########
eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java:
##########
@@ -25,17 +27,29 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
Review Comment:
It seems unnecessary to add @MockitoSettings because you are configuring
LENIENT, which is the default mode for Mockito at runtime, requiring the
loosest expectations for code.
好像没有必要添加@MockitoSettings,因为您配置的是LENIENT,这就是Mockito运行时默认的模式,即代码要求最宽松。
##########
eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java:
##########
@@ -25,17 +27,29 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
public class SpringSourceConnectorTest {
@Spy
private SpringSourceConnector connector;
Review Comment:
The @Spy annotation doesn't make much sense in this context since there are
no mocks of the SpringSourceConnector object in this test.
这个@spy注解的意义不大,因为该测试中没有对SpringSourceConnector对象进行任何模拟。
##########
eventmesh-connectors/eventmesh-connector-spring/src/main/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnector.java:
##########
@@ -131,6 +144,40 @@ public void send(Object message, SendMessageCallback
workerCallback) {
RecordOffset offset = new RecordOffset();
ConnectRecord record = new ConnectRecord(partition, offset,
System.currentTimeMillis(), message);
record.addExtension(SourceWorker.CALLBACK_EXTENSION, workerCallback);
+ addSpringEnvironmentPropertyExtensions(record);
queue.offer(record);
}
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
+ private void addSpringEnvironmentPropertyExtensions(ConnectRecord
connectRecord) {
+ ConfigurableApplicationContext context =
(ConfigurableApplicationContext) applicationContext;
+ MutablePropertySources propertySources =
context.getEnvironment().getPropertySources();
+ for (PropertySource<?> propertySource : propertySources) {
+ if (!(propertySource instanceof OriginTrackedMapPropertySource)) {
+ continue;
+ }
+ OriginTrackedMapPropertySource originTrackedMapPropertySource =
+ (OriginTrackedMapPropertySource) propertySource;
+ String[] keys = originTrackedMapPropertySource.getPropertyNames();
+ for (String key : keys) {
+ if (!key.startsWith(CONNECTOR_PROPERTY_PREFIX)) {
+ continue;
+ }
+ Object value = null;
+ try {
+ value = originTrackedMapPropertySource.getProperty(key);
+ if (value != null) {
+
connectRecord.addExtension(key.replaceAll(CONNECTOR_PROPERTY_PREFIX,
"").toLowerCase(),
+ value.toString());
Review Comment:
Which one is more appropriate here, using toString() or directly casting the
type?
这里用toString()和直接转换类型哪个更合适?
##########
eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/utils/PrometheusExporterUtils.java:
##########
@@ -70,7 +70,7 @@ public static <T extends Metric> void observeOfValue(Meter
meter, String metricN
* @return
*/
public static String[] join(String metricName, String desc) {
- return new String[] {metricName, desc};
+ return new String[]{metricName, desc};
Review Comment:
This is my question. Were these code format changes automatically made by
Spotless? If so, does the fact that CI passed previously mean that there is a
difference in the code format requirements between Spotless and Checkstyle?
这是我的疑问:这些代码格式的修改,是spotless自动修改的吗?如果是的话,因为之前CI通过了,是不是表示现在Spotless和Checkstyle对代码格式的要求有差别?
##########
eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java:
##########
@@ -25,17 +27,29 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
Review Comment:
It seems unnecessary to add @MockitoSettings because you are configuring
LENIENT, which is the default mode for Mockito at runtime, requiring the
loosest expectations for code.
好像没有必要添加@MockitoSettings,因为您配置的是LENIENT,这就是Mockito运行时默认的模式,即代码要求最宽松。
##########
eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/utils/PrometheusExporterUtils.java:
##########
@@ -70,7 +70,7 @@ public static <T extends Metric> void observeOfValue(Meter
meter, String metricN
* @return
*/
public static String[] join(String metricName, String desc) {
- return new String[] {metricName, desc};
+ return new String[]{metricName, desc};
Review Comment:
This is my question. Were these code format changes automatically made by
Spotless? If so, does the fact that CI passed previously mean that there is a
difference in the code format requirements between Spotless and Checkstyle?
这是我的疑问:这些代码格式的修改,是spotless自动修改的吗?如果是的话,因为之前CI通过了,是不是表示现在Spotless和Checkstyle对代码格式的要求有差别?
--
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]