bitflicker64 commented on code in PR #3301:
URL: https://github.com/apache/hugegraph/pull/3301#discussion_r4236982341


##########
hugegraph-server/hugegraph-dist/src/test/java/org/apache/hugegraph/dist/ColdGremlinQueryTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.dist;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hugegraph.query.ConditionQuery;
+import org.apache.hugegraph.security.HugeSecurityManager;
+import org.apache.hugegraph.type.HugeType;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ColdGremlinQueryTest {
+
+    @Test
+    public void testFreshJvmQueriesAndSecurityAfterStartupInitialization() 
throws Exception {
+        Path output = Files.createTempFile("cold-gremlin-query", ".log");
+        Process process = null;
+        try {
+            String java = Path.of(System.getProperty("java.home"), "bin", 
"java").toString();
+            String classpath = System.getProperty("surefire.test.class.path",
+                                                  
System.getProperty("java.class.path"));
+            Path sourceRoot = Path.of(System.getProperty("basedir", 
System.getProperty("user.dir")))
+                                  .getParent().getParent();
+            process = new ProcessBuilder(java, 
"-Djava.security.manager=allow", "-cp", classpath,
+                                         ColdGremlinQueryTest.class.getName())
+                      // Permit source-class loading under the reactor root, 
as in IDE runs.
+                      
.directory(sourceRoot.toFile()).redirectErrorStream(true).redirectOutput(output.toFile()).start();
+            Assert.assertTrue("Fresh JVM timed out", process.waitFor(60, 
TimeUnit.SECONDS));
+            String log = Files.readString(output);
+            Assert.assertEquals(log, 0, process.exitValue());
+            Assert.assertTrue(log, log.contains("PASS: cold queries and 
security restrictions"));
+        } finally {
+            if (process != null && process.isAlive()) {
+                process.destroyForcibly().waitFor();
+            }
+            Files.deleteIfExists(output);
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
+        try {
+            // Initialize Groovy independently of the query/Gson 
initialization.
+            engine.eval("1 + 1");
+            // A real startup has already exercised parameterized logging.
+            Log.logger(ColdGremlinQueryTest.class).warn("Initialize logging 
for {}", "cold query fixture");
+            HugeGraphServer.initializeQueryClasses();

Review Comment:
   Minor: this test passes even if the startup fix is removed. `main()` calls 
`HugeGraphServer.initializeQueryClasses()` itself, and nothing in the test goes 
through the `HugeGraphServer` constructor, so deleting the call at 
`HugeGraphServer.java:65` (the only production call site, and the line that 
fixes #3300) leaves `ColdGremlinQueryTest` green. What the test pins is that 
`new ConditionQuery(...)` initializes Gson, not that the server runs it before 
Gremlin accepts requests. The packaged-server smoke test does not cover the 
order either: `run-server-e2e-smoke-test.sh` sends REST vertex requests before 
its `g.V().hasLabel(...)` Gremlin request in both modes.
   
   Requested change: add a check that fails when the constructor call is 
dropped. The cheapest option is probably a fresh-server step in 
`run-server-e2e-smoke-test.sh` (or its caller) that sends the `hasLabel` 
Gremlin request as the first request after startup, before any REST graph 
query, and then one REST label query.



-- 
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]

Reply via email to