Skip to content

Commit 06097c8

Browse files
authored
refactor(server): allow TinkerPop exceptions in Gremlin resp (#2987)
* fix(api/gremlin): allow TinkerPop exceptions in Gremlin responses * Address review feedback
1 parent c0a2b93 commit 06097c8

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class GremlinQueryAPI extends API {
4343
"java.util.concurrent.TimeoutException",
4444
"groovy.lang.",
4545
"org.codehaus.",
46-
"org.apache.hugegraph."
46+
"org.apache.hugegraph.",
47+
"org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException"
4748
);
4849

4950
@Context

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.hugegraph.core.RoleElectionStateMachineTest;
2121
import org.apache.hugegraph.unit.api.filter.PathFilterTest;
22+
import org.apache.hugegraph.unit.api.gremlin.GremlinQueryAPITest;
2223
import org.apache.hugegraph.unit.auth.HugeGraphAuthProxyTest;
2324
import org.apache.hugegraph.unit.cache.CacheManagerTest;
2425
import org.apache.hugegraph.unit.cache.CacheTest;
@@ -81,6 +82,9 @@
8182
/* api filter */
8283
PathFilterTest.class,
8384

85+
/* api gremlin */
86+
GremlinQueryAPITest.class,
87+
8488
/* cache */
8589
CacheTest.RamCacheTest.class,
8690
CacheTest.OffheapCacheTest.class,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hugegraph.unit.api.gremlin;
19+
20+
import java.lang.reflect.Method;
21+
22+
import org.apache.hugegraph.api.gremlin.GremlinQueryAPI;
23+
import org.apache.hugegraph.testutil.Assert;
24+
import org.apache.hugegraph.unit.BaseUnitTest;
25+
import org.junit.Test;
26+
27+
public class GremlinQueryAPITest extends BaseUnitTest {
28+
29+
private static boolean matchBadRequest(String exClass) throws Exception {
30+
Method m = GremlinQueryAPI.class.getDeclaredMethod(
31+
"matchBadRequestException", String.class);
32+
m.setAccessible(true);
33+
return (boolean) m.invoke(null, exClass);
34+
}
35+
36+
@Test
37+
public void testMatchBadRequestExceptionWithTinkerpop() throws Exception {
38+
Assert.assertTrue(matchBadRequest(
39+
"org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException"));
40+
}
41+
42+
@Test
43+
public void testMatchBadRequestExceptionWithAuthExceptions() throws Exception {
44+
Assert.assertFalse(matchBadRequest(
45+
"org.apache.tinkerpop.gremlin.server.auth.AuthenticationException"));
46+
Assert.assertFalse(matchBadRequest(
47+
"org.apache.tinkerpop.gremlin.server.authz.AuthorizationException"));
48+
}
49+
50+
@Test
51+
public void testMatchBadRequestExceptionWithHugegraph() throws Exception {
52+
Assert.assertTrue(matchBadRequest("org.apache.hugegraph.exception.NotFoundException"));
53+
Assert.assertTrue(matchBadRequest("java.lang.IllegalArgumentException"));
54+
Assert.assertTrue(matchBadRequest("groovy.lang.MissingPropertyException"));
55+
}
56+
57+
@Test
58+
public void testMatchBadRequestExceptionWithOther() throws Exception {
59+
Assert.assertFalse(matchBadRequest(null));
60+
Assert.assertFalse(matchBadRequest("java.lang.NullPointerException"));
61+
Assert.assertFalse(matchBadRequest("java.io.IOException"));
62+
}
63+
}

0 commit comments

Comments
 (0)