Skip to content

Conversation

@VishalMCF
Copy link
Contributor

@VishalMCF VishalMCF commented Oct 19, 2023

fix #4474

Motivation

There were duplicate final static constants that could have been created in a single common file and could be reused anywhere in the project.

Modifications

The common file which is suitable for hosting the static constants was found to be inside the package -> package org.apache.eventmesh.common. The file is the Constants.java file. There I added the following String constants ->
{ HTTP = "HTTP", TCP = "TCP", GRPC = "GRPC"}
Other than this there is one more constant in the eventmesh-common.Constants file called ( CLOUD_EVENTS_PROTOCOL_NAME = "cloudevents" ) which I have added wherever applicable.
and changed the import statements accordingly.

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable
  • If a feature is not applicable for documentation, explain why? PR deals with only refactoring

@VishalMCF
Copy link
Contributor Author

@mxsm I ran the following command -> ./gradlew build -x test and it worked fine.

But for a few modules, there were test-case failures. I can name them here as a reference. Is there any specific reason for that? Because I have made only small changes and if the compilation was successful then my changes should not have any impact on the test cases. Please suggest accordingly. I will look further into more detail if my changes are causing the issue.

  1. eventmesh-common -> IPUtilsTest
  2. evemtmesh-runtime
  3. eventmesh-sdks
  4. eventmesh-storage-plugin
  5. eventmesh-trace-plugin

@Pil0tXia
Copy link
Member

Pil0tXia commented Oct 19, 2023

@VishalMCF You may checkout master branch, run the gradlew command again and try to reproduce it.

@pandaapo pandaapo changed the title ISSUE #4474 -> moved common constants to eventmesh-common.Constants file. [ISSUE #4474] Uniformly manage duplicate static variables Oct 19, 2023
Comment on lines 86 to 88
Preconditions.checkNotNull(cloudEvent.getDataContentType(), "DateContentType cannot be null");
msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME);
msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, CLOUD_EVENTS_PROTOCOL_NAME);
msg.getHeader().putProperty(Constants.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding Style differs here. Please use static import only when this class uses single constant class.

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Merging #4495 (7a5fd63) into master (f629730) will increase coverage by 0.01%.
The diff coverage is 0.00%.

❗ Current head 7a5fd63 differs from pull request most recent head b39ef9f. Consider uploading reports for the commit b39ef9f to get more accurate results

@@             Coverage Diff              @@
##             master    #4495      +/-   ##
============================================
+ Coverage     15.46%   15.47%   +0.01%     
  Complexity     1452     1452              
============================================
  Files           691      691              
  Lines         28101    28106       +5     
  Branches       2624     2626       +2     
============================================
+ Hits           4345     4349       +4     
- Misses        23309    23312       +3     
+ Partials        447      445       -2     
Files Coverage Δ
...in/java/org/apache/eventmesh/common/Constants.java 75.00% <ø> (ø)
...entmesh/common/utils/ConfigurationContextUtil.java 70.00% <ø> (ø)
...ics/prometheus/metrics/PrometheusGrpcExporter.java 0.00% <ø> (ø)
...ics/prometheus/metrics/PrometheusHttpExporter.java 0.00% <ø> (ø)
...rics/prometheus/metrics/PrometheusTcpExporter.java 0.00% <ø> (ø)
.../prometheus/utils/PrometheusExporterConstants.java 0.00% <ø> (ø)
...apache/eventmesh/runtime/boot/EventMeshServer.java 0.00% <ø> (ø)
...apache/eventmesh/client/http/ProtocolConstant.java 0.00% <ø> (ø)
...e/eventmesh/client/tcp/common/EventMeshCommon.java 0.00% <ø> (ø)
...e/eventmesh/common/config/CommonConfiguration.java 83.33% <0.00%> (ø)
... and 9 more

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pandaapo
Copy link
Member

Have all duplicate variables been optimized? If not, it is recommended that you create a new issue as a sub issue of issue #4474 and link this PR to the new issue.

@xwm1992 xwm1992 merged commit d2531b2 into apache:master Oct 20, 2023
Copy link
Member

@Pil0tXia Pil0tXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this PR has done all it can do. @VishalMCF Please optimize it further when you have time~

Comment on lines 41 to 44

// protocol type
public static final String CLOUD_EVENTS_PROTOCOL_NAME = "cloudevents";
public static final String EM_MESSAGE_PROTOCOL_NAME = "eventmeshmessage";
public static final String OPEN_MESSAGE_PROTOCOL_NAME = "openmessage";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloudevents removed but eventmeshmessage and openmessage remaining here.

Comment on lines 20 to 24
public final class ProtocolConstant {

public static final String CE_PROTOCOL = "cloudevents";
public static final String EM_MESSAGE_PROTOCOL = "eventmeshmessage";
public static final String OP_MESSAGE_PROTOCOL = "openmessage";
public static final String PROTOCOL_DESC = "http";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another cloudevents removed but eventmeshmessage and openmessage remaining here. The protocols are torn apart and still duplicate.

Comment on lines 18 to 23
package org.apache.eventmesh.client.tcp.common;

import static org.apache.eventmesh.common.Constants.CLOUD_EVENTS_PROTOCOL_NAME;

import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.protocol.SubscriptionItem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static imports should not be used here, because Constants class has already been imported.

xuhongjia pushed a commit to Deckers-Ohana/eventmesh that referenced this pull request Mar 13, 2025
…he#4495)

* 4474 -> moved common constants to appache-common

* shifted common static variables to a common Constants.java file in eventmesh.common module

* removed unused constant from the file.

* refactored constants related to HTTP, GRPC, TCP in the relevant files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]Uniformly manage duplicate static variables

4 participants