Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public static HugeClientBuilder builder(String url, String graphSpace, String gr
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);
}

public static HugeClientBuilder builder(String url, String graph) {
return new HugeClientBuilder(url, HugeClientBuilder.DEFAULT_GRAPHSPACE, graph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ public class HugeClientBuilder {
/** Set them null by default to keep compatibility with 'timeout' */
private Integer connectTimeout;
private Integer readTimeout;
private final boolean skipRequiredChecks;

public HugeClientBuilder(String url, String graphSpace, String graph) {
E.checkArgument(url != null && !url.isEmpty(),
"Expect a string value as the url parameter argument, but got: %s", url);
E.checkArgument(graph != null && !graph.isEmpty(),
"Expect a string value as the graph name parameter argument, but got: %s",
graph);
this(url, graphSpace, graph, false);
}

public HugeClientBuilder(String url, String graphSpace, String graph,
boolean skipRequiredChecks) {
this.skipRequiredChecks = skipRequiredChecks;

if (!skipRequiredChecks) {
E.checkArgument(url != null && !url.isEmpty(),
"Expect a string value as the url parameter " +
"argument, but got: %s", url);
E.checkArgument(graph != null && !graph.isEmpty(),
"Expect a string value as the graph name " +
"parameter argument, but got: %s",
graph);
}

this.url = url;
this.graphSpace = graphSpace;
this.graph = graph;
Expand All @@ -76,8 +89,10 @@ public HugeClientBuilder(String url, String graphSpace, String graph) {
}

public HugeClient build() {
E.checkArgument(this.url != null, "The url parameter can't be null");
E.checkArgument(this.graph != null, "The graph parameter can't be null");
if (!this.skipRequiredChecks) {
E.checkArgument(this.url != null, "The url parameter can't be null");
E.checkArgument(this.graph != null, "The graph parameter can't be null");
}
return new HugeClient(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ public static class UserRole {

// Mapping of: graphSpace -> graph -> permission -> resourceType -> resources
@JsonProperty("roles")
private Map<String, Map<String, Map<HugePermission, Map<String, List<HugeResource>>>>> roles;
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() {
Comment on lines +158 to +162
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.
return Collections.unmodifiableMap(this.roles);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.apache.hugegraph.unit;

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.
import org.junit.Assert;
import org.junit.Test;

public class HugeClientBuilderTest {

@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.
}
Comment on lines +11 to +22
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.
}

@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();
}
Comment on lines +25 to +30
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.

@Test
public void testHugeClientBuilderMethod() {
// Should not throw IllegalArgumentException
HugeClientBuilder builder = HugeClient.builder("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
}
}

@Test(expected = IllegalArgumentException.class)
public void testHugeClientBuilderMethodWithoutSkip() {
// Should throw exception
HugeClientBuilder builder = HugeClient.builder("http://127.0.0.1:8080", "DEFAULT", null);
builder.build();
}
}
Loading