imbajin commented on code in PR #349: URL: https://github.com/apache/hugegraph-computer/pull/349#discussion_r3472596577
########## computer/computer-api/src/main/java/org/apache/hugegraph/computer/core/util/HugeClientUtil.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.computer.core.util; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.hugegraph.driver.HugeClient; +import org.apache.hugegraph.driver.HugeClientBuilder; +import org.apache.hugegraph.rest.RestResult; +import org.apache.hugegraph.structure.schema.EdgeLabel; +import org.apache.hugegraph.util.JsonUtil; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.module.SimpleModule; + +public final class HugeClientUtil { + + private static final AtomicBoolean COMPATIBILITY_REGISTERED = + new AtomicBoolean(false); + + public static HugeClient newHugeClient(String url, String graph, + String username, String password) { + registerCompatibilityModule(); + return new HugeClientBuilder(url, graph).configUser(username, password) + .build(); + } + + public static HugeClient newHugeClient(String url, String graph, + String username, String password, + int timeout) { + registerCompatibilityModule(); + return new HugeClientBuilder(url, graph).configUser(username, password) + .configTimeout(timeout) + .build(); + } + + public static void registerCompatibilityModule() { Review Comment: ⚠️ Important: please make the completion flag reflect completed registration, not registration start. `COMPATIBILITY_REGISTERED.compareAndSet(false, true)` flips the guard before the compatibility module is registered into both global mappers. A concurrent caller entering during that window will return immediately and can create/use a client before `RestResult` and `JsonUtil` are both configured. Please make the registration completion the synchronization boundary, for example: ```suggestion public static void registerCompatibilityModule() { if (COMPATIBILITY_REGISTERED.get()) { return; } synchronized (HugeClientUtil.class) { if (COMPATIBILITY_REGISTERED.get()) { return; } RestResult.registerModule(newCompatibilityModule()); JsonUtil.registerModule(newCompatibilityModule()); COMPATIBILITY_REGISTERED.set(true); } } ``` ########## computer/computer-test/src/main/java/org/apache/hugegraph/computer/core/input/hg/HugeClientCompatibilityTest.java: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.computer.core.input.hg; + +import java.lang.reflect.Method; + +import org.apache.hugegraph.computer.core.util.HugeClientUtil; +import org.apache.hugegraph.rest.RestResult; +import org.apache.hugegraph.structure.schema.EdgeLabel; +import org.apache.hugegraph.testutil.Assert; +import org.junit.Test; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; + +public class HugeClientCompatibilityTest { Review Comment: ⚠️ Important: this new compatibility test is not wired into the normal unit-test suite. `computer-test/pom.xml` runs the unit profile through `**/UnitTestSuite.java`, and `UnitTestSuite` reaches this area through `InputTestSuite`. However `InputTestSuite` still only includes `InputSplitTest`, `FileInputSplitTest`, `InputSplitDataTest`, and `HugeConverterTest`; it does not include `HugeClientCompatibilityTest`. That means the EdgeLabel unknown-field compatibility coverage can pass when run explicitly with `-Dtest=HugeClientCompatibilityTest`, but it is not protected by the normal `mvn test -P unit-test` / CI unit path. Please add this class to an executed suite, likely `InputTestSuite`, or add a small `core.input.hg` suite and wire it into `InputTestSuite` / `UnitTestSuite`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
