From ab0eb6d5b748c19072d6911a6071396694f3c34c Mon Sep 17 00:00:00 2001 From: ugurtafrali Date: Fri, 10 Apr 2026 06:25:42 +0300 Subject: [PATCH 1/2] fix(api/gremlin): allow TinkerPop exceptions in Gremlin responses --- .../api/gremlin/GremlinQueryAPI.java | 3 +- .../apache/hugegraph/unit/UnitTestSuite.java | 4 ++ .../unit/api/gremlin/GremlinQueryAPITest.java | 57 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java index 1f35da5f1c..92da13d91b 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java @@ -43,7 +43,8 @@ public class GremlinQueryAPI extends API { "java.util.concurrent.TimeoutException", "groovy.lang.", "org.codehaus.", - "org.apache.hugegraph." + "org.apache.hugegraph.", + "org.apache.tinkerpop." ); @Context diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java index f9f20ab9e5..52bf104b01 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java @@ -19,6 +19,7 @@ import org.apache.hugegraph.core.RoleElectionStateMachineTest; import org.apache.hugegraph.unit.api.filter.PathFilterTest; +import org.apache.hugegraph.unit.api.gremlin.GremlinQueryAPITest; import org.apache.hugegraph.unit.auth.HugeGraphAuthProxyTest; import org.apache.hugegraph.unit.cache.CacheManagerTest; import org.apache.hugegraph.unit.cache.CacheTest; @@ -81,6 +82,9 @@ /* api filter */ PathFilterTest.class, + /* api gremlin */ + GremlinQueryAPITest.class, + /* cache */ CacheTest.RamCacheTest.class, CacheTest.OffheapCacheTest.class, diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java new file mode 100644 index 0000000000..eec52da159 --- /dev/null +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java @@ -0,0 +1,57 @@ +/* + * 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.unit.api.gremlin; + +import java.lang.reflect.Method; + +import org.apache.hugegraph.api.gremlin.GremlinQueryAPI; +import org.apache.hugegraph.testutil.Assert; +import org.apache.hugegraph.unit.BaseUnitTest; +import org.junit.Test; + +public class GremlinQueryAPITest extends BaseUnitTest { + + private static boolean matchBadRequest(String exClass) throws Exception { + Method m = GremlinQueryAPI.class.getDeclaredMethod( + "matchBadRequestException", String.class); + m.setAccessible(true); + return (boolean) m.invoke(null, exClass); + } + + @Test + public void testMatchBadRequestExceptionWithTinkerpop() throws Exception { + Assert.assertTrue(matchBadRequest( + "org.apache.tinkerpop.gremlin.structure.util.empty.EmptyProperty")); + Assert.assertTrue(matchBadRequest( + "org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException")); + } + + @Test + public void testMatchBadRequestExceptionWithHugegraph() throws Exception { + Assert.assertTrue(matchBadRequest("org.apache.hugegraph.exception.NotFoundException")); + Assert.assertTrue(matchBadRequest("java.lang.IllegalArgumentException")); + Assert.assertTrue(matchBadRequest("groovy.lang.MissingPropertyException")); + } + + @Test + public void testMatchBadRequestExceptionWithOther() throws Exception { + Assert.assertFalse(matchBadRequest(null)); + Assert.assertFalse(matchBadRequest("java.lang.NullPointerException")); + Assert.assertFalse(matchBadRequest("java.io.IOException")); + } +} From ce9482310d0af625e58593807eae9247e28f2545 Mon Sep 17 00:00:00 2001 From: utafrali Date: Fri, 10 Apr 2026 08:28:57 +0300 Subject: [PATCH 2/2] Address review feedback --- .../apache/hugegraph/api/gremlin/GremlinQueryAPI.java | 2 +- .../unit/api/gremlin/GremlinQueryAPITest.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java index 92da13d91b..2ab55f584a 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java @@ -44,7 +44,7 @@ public class GremlinQueryAPI extends API { "groovy.lang.", "org.codehaus.", "org.apache.hugegraph.", - "org.apache.tinkerpop." + "org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException" ); @Context diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java index eec52da159..94deaf921d 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java @@ -35,12 +35,18 @@ private static boolean matchBadRequest(String exClass) throws Exception { @Test public void testMatchBadRequestExceptionWithTinkerpop() throws Exception { - Assert.assertTrue(matchBadRequest( - "org.apache.tinkerpop.gremlin.structure.util.empty.EmptyProperty")); Assert.assertTrue(matchBadRequest( "org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException")); } + @Test + public void testMatchBadRequestExceptionWithAuthExceptions() throws Exception { + Assert.assertFalse(matchBadRequest( + "org.apache.tinkerpop.gremlin.server.auth.AuthenticationException")); + Assert.assertFalse(matchBadRequest( + "org.apache.tinkerpop.gremlin.server.authz.AuthorizationException")); + } + @Test public void testMatchBadRequestExceptionWithHugegraph() throws Exception { Assert.assertTrue(matchBadRequest("org.apache.hugegraph.exception.NotFoundException"));