Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low friction cleanups (suggested by IntelliJ) #361

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

samba2
Copy link

@samba2 samba2 commented Apr 24, 2022

To familiarize with the code base I tried to perform a "random act of kindness" (Uncle Bob) 😊 by applying some of the suggested IntelliJ refactorings/ cleanups.

@@ -94,15 +93,6 @@ public XinfraMonitor(Map<String, Map> allClusterProps) throws Exception {
(config, now) -> _offlineRunnables.size());
}

private boolean constructorContainsClass(Constructor<?>[] constructors, Class<?> classObject) {
Copy link
Author

Choose a reason for hiding this comment

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

was never called

/* Delay 2 second to reduce the chance that produce and consumer thread has race condition
with TopicManagementService and MultiClusterTopicManagementService */
long threadSleepMs = TimeUnit.SECONDS.toMillis(2);
Copy link
Author

Choose a reason for hiding this comment

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

I tried to concisely use the Utils.delay(...) method. Here, I additionally had to import delay statically since a Kafka Utils class is already used. (avoiding fully qualified import)

@@ -55,8 +55,6 @@
*/
public class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
public static final int ZK_CONNECTION_TIMEOUT_MS = 30_000;
Copy link
Author

Choose a reason for hiding this comment

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

unused

@@ -117,9 +115,7 @@ public static List<Integer> replicaIdentifiers(Set<BrokerMetadata> brokers) {
Collections.shuffle(brokerMetadataList);

// Get broker ids for replica list
List<Integer> replicaList = brokerMetadataList.stream().map(m -> m.id()).collect(Collectors.toList());
Copy link
Author

Choose a reason for hiding this comment

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

inline

for (Map.Entry<String, String> entry : customProps.entrySet()) {
consumerProps.put(entry.getKey(), entry.getValue());
}
consumerProps.putAll(customProps);
Copy link
Author

Choose a reason for hiding this comment

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

never would have spotted this myself - putAll is a convenient shortcut + also more performant (I know, not relevant here)

Comment on lines +55 to +56
_metricMap = new HashMap<>();
_dimensionsMap = new HashMap<>();
Copy link
Author

Choose a reason for hiding this comment

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

was redundant


return offsetCommitSuccessRate + offsetCommitFailureRate > 0 ? offsetCommitSuccessRate / (
offsetCommitSuccessRate + offsetCommitFailureRate) : 0;
Measurable measurable = (config, now) -> {
Copy link
Author

Choose a reason for hiding this comment

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

using lambda


consumeService.stop();
thread.join(500);

Assert.assertFalse(thread.isAlive());
Assert.assertEquals(error.get(), null);
Assert.assertNull(error.get());
Copy link
Author

Choose a reason for hiding this comment

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

simplify

@@ -207,8 +200,7 @@ public void run() {
*/
private Metrics consumeServiceMetrics(ConsumeService consumeService) {
setup();
Metrics metrics = consumeService.metrics();
return metrics;
return consumeService.metrics();
Copy link
Author

Choose a reason for hiding this comment

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

inline

public XinfraMonitorConstants() {

}
private XinfraMonitorConstants() {}
Copy link
Author

Choose a reason for hiding this comment

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

utility class

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.

1 participant