kasakrisz commented on code in PR #4863:
URL: https://github.com/apache/hive/pull/4863#discussion_r1433030551


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/metatool/HiveMetaTool.java:
##########
@@ -63,8 +66,10 @@ public static void main(String[] args) {
       task.execute();
     } catch (Exception e) {
       LOGGER.error("Exception occured", e);
+      System.exit(1);
     } finally {
       objectStore.shutdown();
+      System.exit(0);

Review Comment:
   `HiveMetaTool.main` is called from several test example:
   
https://github.com/apache/hive/blob/36ce858163a19e29eafe4a8d3307191bc28fc175/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/tools/metatool/TestHiveMetaTool.java#L185-L187
   and adding `System.exit` call causes
   ```
   19:38:24  Command was /bin/sh -c cd 
/home/jenkins/agent/workspace/hive-precommit_PR-4863/itests/hive-unit && 
/usr/lib/jvm/zulu-8-amd64/jre/bin/java -Xmx2048m -DJETTY_AVAILABLE_PROCESSORS=4 
-jar 
/home/jenkins/agent/workspace/hive-precommit_PR-4863/itests/hive-unit/target/surefire/surefirebooter7556721313418086862.jar
 
/home/jenkins/agent/workspace/hive-precommit_PR-4863/itests/hive-unit/target/surefire
 2023-11-30T17-05-43_001-jvmRun1 surefire408147966509449349tmp 
surefire_573372170409187255344tmp
   19:38:24  Process Exit Code: 0
   19:38:24  Crashed tests:
   19:38:24  org.apache.hadoop.hive.metastore.tools.metatool.TestHiveMetaTool
   19:38:24     at 
org.apache.maven.plugin.surefire.booterclient.ForkStarter.awaitResultsDone(ForkStarter.java:513)
   19:38:24     at 
org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkPerTestSet(ForkStarter.java:460)
   19:38:24     at 
org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:301)
   19:38:24     at 
org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:249)
   19:38:24     at 
org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1217)
   19:38:24     at 
org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1063)
   19:38:24     at 
org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:889)
   19:38:24     at 
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
   19:38:24     at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
   19:38:24     at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
   19:38:24     at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
   19:38:24     at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
   19:38:24     at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
   19:38:24     at 
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
   19:38:24     at 
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
   19:38:24     at 
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
   19:38:24     at 
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
   19:38:24     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
   19:38:24     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:972)
   19:38:24     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
   19:38:24     at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
   19:38:24     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   19:38:24     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   19:38:24     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   19:38:24     at java.lang.reflect.Method.invoke(Method.java:498)
   19:38:24     at 
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
   19:38:24     at 
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
   19:38:24     at 
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
   19:38:24     at 
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
   19:38:24  Caused by: 
org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM 
terminated without properly saying goodbye. VM crash or System.exit called?
   ```
   
   How about refactor the main by extracting the try block to a method and this 
new method would be called from tests:
   ```
   static void createAndExecuteTask(HiveMetaToolCommandLine cl) {
     if (cl.isListFSRoot()) {
           task = new MetaToolTaskListFSRoot();
     ...
     task.execute();
   }
   
   main(String[] args) {
     HiveMetaToolCommandLine cl = HiveMetaToolCommandLine.parseArguments(args);
     ...
     try {
       createAndexecuteTask(cl);
     }
     catch (Exception ex) {
       System.exit(-1);
     }
     finally {
     ...
     }
     System.exit(-1);
   }
   
   @Test
   public void testListFSRoot() throws Exception {
     HiveMetaToolCommandLine cl = HiveMetaToolCommandLine.parseArguments(new 
String[] {"-listFSRoot"});
     HiveMetaTool.createAndExecuteTask(cl);
   ...
   }
   ```



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to