Skip to content

Conversation

dengzhhu653
Copy link
Member

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

No

How was this patch tested?

https://ci.hive.apache.org/job/hive-flaky-check/915


warehouse = new Warehouse(conf);

conf.set("metastore.leader.test.listener", TestLeaderNotification.class.getName());
Copy link
Member

Choose a reason for hiding this comment

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

could we move this to constants?

Copy link
Member Author

Choose a reason for hiding this comment

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

This property is for test only, it's shouldn't be exposed to user or else where in the unit test

Copy link
Member

@deniskuzZ deniskuzZ Oct 22, 2025

Choose a reason for hiding this comment

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

threadClasses.forEach((thread, status) -> threadClasses.put(thread, false));
}

public static class TestLeaderNotification implements LeaderElection.LeadershipStateListener {
Copy link
Member

Choose a reason for hiding this comment

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

maybe package-private

Copy link
Member Author

Choose a reason for hiding this comment

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

for creating the instance from reflection, https://github.com/apache/hive/pull/6142/files#diff-d697cd0d86def896a111982bc9a1c1d4cdd1175fcc3a21599ce3f0e228613895R109, a public access of the class is needed

Copy link
Member

Choose a reason for hiding this comment

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

using reflection in tests is typically not the best approach, as it often indicates underlying design issues

listenerMap.forEach((k, v) -> newListeners.get(TTYPE.HOUSEKEEPING).addAll(v));
List<LeadershipStateListener> listeners = new ArrayList<>();
listenerMap.forEach((k, v) -> listeners.addAll(v));
String testListenerCls = conf.get("metastore.leader.test.listener");
Copy link
Member

Choose a reason for hiding this comment

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

That is a very bad practice to bring test related things into production code! Try mocking/stubbing, etc..

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for the integration test, the mocking/stubbing I think couldn't imitate a HMS similar as the one deployed in production.

Copy link
Member

@deniskuzZ deniskuzZ Oct 22, 2025

Choose a reason for hiding this comment

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

Including test-specific workarounds in production code is generally discouraged, as it’s considered a code smell and not a best practice.
same applies conf.getBoolean(LEADER_IN_TEST, false)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, IMO we need to trade off between the test coverage and the maintenance(code smell), and reach a balance. We also have some properties such as hive.in*.test for testing purpose.

Copy link
Member

Choose a reason for hiding this comment

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

We also have some properties such as hive.in*.test for testing purpose

True — those are legacy and should be removed once all tests are refactored (I’ve already done this in several cases).
However, that’s not a reason to introduce more such configs. The code should be structured in a way that makes it easy to test using the existing test framework tools.

notifyListener();
}
if (!conf.getBoolean(METASTORE_RENEW_LEASE, true)) {
// For test only.
Copy link
Member

Choose a reason for hiding this comment

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

again, same thing.

Copy link
Member

@deniskuzZ deniskuzZ left a comment

Choose a reason for hiding this comment

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

added comments

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants