hemanthumashankar0511 commented on code in PR #6640:
URL: https://github.com/apache/hive/pull/6640#discussion_r3893542563


##########
itests/tez-yarn-it/src/test/java/org/apache/hive/tez/yarn/TestTezYarnLocalization.java:
##########
@@ -0,0 +1,262 @@
+/*
+ * 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.hive.tez.yarn;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hive.service.server.HiveServer2;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+
+import java.net.ServerSocket;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class TestTezYarnLocalization {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(TestTezYarnLocalization.class);
+
+  private static final String HDFS_BASE      = "hdfs://namenode:8020";
+  private static final String HDFS_WAREHOUSE = HDFS_BASE + 
"/tmp/hive-tez-loc/warehouse";
+  private static final String HDFS_SCRATCH   = HDFS_BASE + 
"/tmp/hive-tez-loc/scratch";
+  private static final String HDFS_ROOT      = "/tmp/hive-tez-loc";
+
+  private static TezYarnClusterContainer cluster;
+  private static HiveServer2 hs2;
+  private static int hs2Port;
+
+  @BeforeClass
+  public static void startAll() throws Exception {
+    cluster = new TezYarnClusterContainer(true);
+    cluster.start();
+
+    GenericContainer<?> nn = cluster.namenodeContainer();
+    nn.execInContainer("hdfs", "dfs", "-mkdir", "-p", "/tmp");
+    nn.execInContainer("hdfs", "dfs", "-chmod", "-R", "777", "/tmp");
+
+    nn.execInContainer("hdfs", "dfs", "-mkdir", "-p", HDFS_ROOT + 
"/warehouse");
+    nn.execInContainer("hdfs", "dfs", "-mkdir", "-p", HDFS_ROOT + "/scratch");
+    nn.execInContainer("hdfs", "dfs", "-mkdir", "-p", HDFS_ROOT + 
"/user-install");
+    nn.execInContainer("hdfs", "dfs", "-chmod", "-R", "777", HDFS_ROOT);
+
+    String tezLibUris = cluster.uploadTezLibsToHdfs();
+    LOG.info("Staged Tez libs to HDFS: {}", tezLibUris);
+
+    Path localScratch = Files.createDirectories(
+            Path.of("/tmp", "hive-tez-loc-" + System.currentTimeMillis()));
+    HiveConf conf = buildHiveConf(tezLibUris, localScratch);
+
+    hs2 = new HiveServer2();
+    hs2.init(conf);
+    hs2.start();
+
+    waitForJdbc(hs2Port);
+    LOG.info("HiveServer2 is ready on port {}", hs2Port);
+  }
+
+  @AfterClass
+  public static void stopAll() {
+    dumpNodeManagerDiagnostics();
+    if (hs2 != null) {
+      hs2.stop();
+      hs2 = null;
+    }
+    if (cluster != null) {
+      cluster.stop();
+      cluster = null;
+    }
+  }
+
+  @Test
+  public void testQuerySucceedsWithAppJar() throws Exception {
+    String url = jdbcUrl(hs2Port);
+    try (Connection conn = DriverManager.getConnection(url, "hive", "")) {
+      try (Statement stmt = conn.createStatement()) {
+
+        stmt.execute("CREATE TABLE IF NOT EXISTS tez_loc_test (id INT) STORED 
AS ORC");
+        stmt.execute("CREATE TABLE IF NOT EXISTS tez_source (id INT) STORED AS 
ORC");
+
+        stmt.execute("INSERT INTO tez_loc_test SELECT count(*) FROM 
tez_source");
+
+        try (ResultSet rs = stmt.executeQuery("SELECT id FROM tez_loc_test")) {
+          Assert.assertTrue("Result set must contain at least one row", 
rs.next());
+          long count = rs.getLong(1);
+          Assert.assertEquals(
+              "INSERT SELECT count(*) FROM empty tez_source should return 0 
(hive-exec.jar was localized)",
+              0L, count);
+          LOG.info("Tez query succeeded: inserted count(*) = {}", count);
+        }
+      }
+    }
+
+    verifyTezYarnAppExists();
+  }
+
+  /** Prints Tez AM and NodeManager logs to the Surefire *-output.txt file at 
teardown. */
+  private static void dumpNodeManagerDiagnostics() {
+    if (cluster == null) {
+      return;
+    }
+    System.out.println("########## BEGIN NodeManager diagnostics ##########");
+    try {
+      dumpNmCommand("launch_container.sh (AM launch command + classpath)",
+          "find /tmp -name 'launch_container.sh' 2>/dev/null | head -3 "
+          + "| xargs -I{} sh -c 'echo \"--- {} ---\"; cat {}' 2>/dev/null || 
true");
+
+      dumpNmCommand("container syslog (Tez AM log4j output)",
+          "find /var/log/hadoop/userlogs -name 'syslog*' 2>/dev/null | head 
-10 "
+          + "| xargs -I{} sh -c 'echo \"--- {} ---\"; cat {}' 2>/dev/null || 
true");
+
+      dumpNmCommand("container stdout + stderr + prelaunch.err",
+          "find /var/log/hadoop/userlogs \\( -name 'stdout' -o -name 'stderr' 
-o -name 'prelaunch.err' \\) "
+          + "2>/dev/null | head -20 | xargs -I{} sh -c 'echo \"--- {} ---\"; 
cat {}' 2>/dev/null || true");
+
+      dumpNmCommand("NodeManager daemon log (tail 200)",
+          "find /var/log/hadoop -maxdepth 1 -name '*.log' 2>/dev/null | head 
-3 "
+          + "| xargs -I{} sh -c 'echo \"--- {} ---\"; tail -200 {}' 
2>/dev/null || true");

Review Comment:
   Expected. The Hadoop image routes the NM daemon process output to the 
container's stdout/stderr, so /var/log/hadoop/*.log is always empty. The 
diagnostic dump for the NM daemon log has been removed since it was always 
producing (no output found). The three remaining dumps (launch_container.sh, 
container syslog, stdout/stderr/prelaunch.err) all target 
/var/log/hadoop/userlogs/ and are populated by a real Tez run.



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