abstractdog commented on code in PR #427:
URL: https://github.com/apache/tez/pull/427#discussion_r2565140913


##########
tez-api/src/test/java/org/apache/tez/client/registry/zookeeper/TestZkFrameworkClient.java:
##########
@@ -0,0 +1,243 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.tez.client.registry.zookeeper;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.test.TestingServer;
+import org.apache.hadoop.registry.client.binding.RegistryUtils;
+import org.apache.hadoop.registry.client.types.ServiceRecord;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClientApplication;
+import org.apache.tez.client.registry.AMRecord;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.zookeeper.CreateMode;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit tests for {@link ZkFrameworkClient}.
+ * <p>
+ * This test class validates the ZooKeeper-based framework client that 
discovers
+ * and communicates with Application Masters through ZooKeeper registry.
+ * </p>
+ */
+public class TestZkFrameworkClient {
+  private static final Logger LOG = 
LoggerFactory.getLogger(TestZkFrameworkClient.class);
+  private static final File TEST_DIR = new 
File(System.getProperty("test.build.data", "target"),
+      TestZkFrameworkClient.class.getName()).getAbsoluteFile();
+
+  private TestingServer zkServer;
+  private ZkFrameworkClient zkFrameworkClient;
+  private CuratorFramework curatorClient;
+
+  @Before
+  public void setup() throws Exception {
+    zkServer = new TestingServer(true);
+    LOG.info("Started ZooKeeper test server on port: {}", zkServer.getPort());
+  }
+
+  @After
+  public void teardown() throws Exception {
+    if (zkFrameworkClient != null) {
+      zkFrameworkClient.close();
+    }
+    IOUtils.closeQuietly(curatorClient);
+    IOUtils.closeQuietly(zkServer);
+  }
+
+  /**
+   * Tests initialization and lifecycle methods of ZkFrameworkClient.
+   */
+  @Test
+  public void testInitAndLifecycle() throws Exception {
+    TezConfiguration tezConf = createTezConf();
+
+    zkFrameworkClient = new ZkFrameworkClient();
+    zkFrameworkClient.init(tezConf);
+
+    assertTrue("Client should be running after init", 
zkFrameworkClient.isRunning());
+
+    zkFrameworkClient.start();
+    assertTrue("Client should be running after start", 
zkFrameworkClient.isRunning());
+
+    zkFrameworkClient.stop();
+    assertFalse("Client should not be running after stop", 
zkFrameworkClient.isRunning());
+  }
+
+  /**
+   * Tests retrieving application report when AM is registered in ZooKeeper.
+   */
+  @Test
+  public void testGetApplicationReportWithRegisteredAM() throws Exception {
+    TezConfiguration tezConf = createTezConf();
+
+    // Register a mock AM in ZooKeeper
+    ApplicationId appId = 
ApplicationId.newInstance(System.currentTimeMillis(), 1);
+    String testHostName = "test-host";
+    String testHostIp = "127.0.0.1";
+    int testPort = 12345;
+    registerMockAM(tezConf, appId, testHostName, testHostIp, testPort);
+
+    zkFrameworkClient = new ZkFrameworkClient();
+    zkFrameworkClient.init(tezConf);
+    zkFrameworkClient.start();
+
+    // Give time for ZK registry to initialize
+    Thread.sleep(500);

Review Comment:
   ack, the ZK TreeCache INITIALIZED callback can be used for such purposes



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

Reply via email to