Skip to content

feat(client): add support for skipping required checks in HugeClientBuilder#718

Open
FrostyHec wants to merge 1 commit intoapache:masterfrom
FrostyHec:fix-hg-client-initialize-check
Open

feat(client): add support for skipping required checks in HugeClientBuilder#718
FrostyHec wants to merge 1 commit intoapache:masterfrom
FrostyHec:fix-hg-client-initialize-check

Conversation

@FrostyHec
Copy link
Collaborator

Purpose of the PR

This pull request introduces a new option to bypass required argument checks when building a HugeClientBuilder, allowing for more flexible client initialization. The main changes include updating constructors and builder methods to support the skipRequiredChecks flag, modifying validation logic, and adding unit tests to verify this new behavior.

Main Changes

Enhancements to client builder flexibility:

  • Added a new skipRequiredChecks boolean parameter to the HugeClientBuilder constructor and the corresponding HugeClient.builder static method, allowing users to bypass mandatory checks for url and graph arguments when needed.
  • Updated validation logic in both the constructor and the build() method of HugeClientBuilder to conditionally skip argument checks based on the skipRequiredChecks flag.

Testing:

  • Introduced a new test class HugeClientBuilderTest with tests to ensure that the builder behaves correctly with and without the skipRequiredChecks flag, including cases where required arguments are missing.

Verifying these changes

  • Trivial rework / code cleanup without any test coverage. (No Need)
  • Already covered by existing tests, such as (please modify tests here).
  • Need tests and can be verified as follows:
    • add new tests.

Does this PR potentially affect the following parts?

  • Nope
  • Dependencies (add/update license info)
  • Modify configurations
  • The public API
  • Other affects (typed here)

Documentation Status

  • Doc - TODO
  • Doc - Done
  • Doc - No Need

@github-actions github-actions bot added the client hugegraph-client label Mar 19, 2026
@imbajin imbajin requested a review from Copilot March 20, 2026 08:49
@imbajin
Copy link
Member

imbajin commented Mar 20, 2026

Also need handle the ci error
image

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an opt-in flag to HugeClientBuilder/HugeClient.builder(...) to bypass required url/graph argument validation, enabling more flexible client initialization flows (e.g., deferring configuration until later).

Changes:

  • Added skipRequiredChecks to HugeClientBuilder (new constructor overload + conditional validation in ctor/build).
  • Added a new HugeClient.builder(..., boolean skipRequiredChecks) overload.
  • Added a new unit test class covering skip vs non-skip behavior; minor formatting update in User.UserRole.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
hugegraph-client/src/test/java/org/apache/hugegraph/unit/HugeClientBuilderTest.java Adds tests for the new skipRequiredChecks behavior (but currently has some issues around determinism/coverage).
hugegraph-client/src/main/java/org/apache/hugegraph/structure/auth/User.java Wraps a long generic type declaration for line-length; introduces trailing whitespace.
hugegraph-client/src/main/java/org/apache/hugegraph/driver/HugeClientBuilder.java Introduces skipRequiredChecks flag and conditionally skips required argument validation.
hugegraph-client/src/main/java/org/apache/hugegraph/driver/HugeClient.java Adds a new public builder overload exposing skipRequiredChecks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +22
@Test
public void testBuilderWithSkipRequiredChecks() {
// Should not throw IllegalArgumentException when skipRequiredChecks is true and graph is null
HugeClientBuilder builder = new HugeClientBuilder("http://127.0.0.1:8080", "DEFAULT", null, true);
try {
builder.build();
} catch (IllegalArgumentException e) {
Assert.fail("Should not throw IllegalArgumentException when skipRequiredChecks is true, but got: " + e.getMessage());
} catch (Exception e) {
// Expected since there is probably no server running at localhost:8080
// The fact we reach here means the bypass of graph/url check was successful.
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

These tests call builder.build(), which constructs HugeClient and triggers server API version checks over HTTP. If no server is running, this can block up to the default 20s timeout per test, making the suite slow/flaky. Consider avoiding the network path (e.g., assert only that constructor/build validation doesn’t throw) or explicitly set very small connect/read timeouts before build() so failures return quickly.

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +30
@Test(expected = IllegalArgumentException.class)
public void testBuilderWithoutSkipRequiredChecks() {
// Should throw exception when skipRequiredChecks is false and graph is null
HugeClientBuilder builder = new HugeClientBuilder("http://127.0.0.1:8080", "DEFAULT", null, false);
builder.build();
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

@Test(expected = IllegalArgumentException.class) here is satisfied by the exception thrown in the constructor (because graph is null) before build() is reached, so it doesn’t actually validate the new conditional checks inside build(). To cover the build() path, construct with a non-null graph, then set configGraph(null) (and/or configUrl(null)) before calling build() and asserting the expected behavior with/without skipRequiredChecks.

Copilot uses AI. Check for mistakes.

import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.driver.HugeClientBuilder;
import org.apache.hugegraph.rest.ClientException;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

Unused import ClientException should be removed to keep the test file clean and avoid failing builds in environments that treat unused imports as errors (e.g., stricter compiler/lint settings).

Suggested change
import org.apache.hugegraph.rest.ClientException;

Copilot uses AI. Check for mistakes.
Comment on lines 121 to +128
public static HugeClientBuilder builder(String url, String graphSpace, String graph) {
return new HugeClientBuilder(url, graphSpace, graph);
}

public static HugeClientBuilder builder(String url, String graphSpace, String graph,
boolean skipRequiredChecks) {
return new HugeClientBuilder(url, graphSpace, graph, skipRequiredChecks);
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

PR description indicates this does not affect the public API, but this adds a new public overload HugeClient.builder(..., boolean skipRequiredChecks) (and a new public HugeClientBuilder constructor signature). The PR metadata/checkboxes should be updated to reflect that this is a public API change.

Copilot uses AI. Check for mistakes.
Comment on lines +158 to +162
private Map<String, Map<String, Map<HugePermission, Map<String,
List<HugeResource>>>>> roles;

public Map<String, Map<String, Map<HugePermission, Map<String, List<HugeResource>>>>> roles() {
public Map<String, Map<String, Map<HugePermission, Map<String,
List<HugeResource>>>>> roles() {
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

These wrapped generic type lines include trailing whitespace before the newline (after the comma). This is easy to miss in reviews and can create noisy diffs or fail whitespace-sensitive tooling; please remove the trailing spaces while keeping the line wrap.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client hugegraph-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants