chenboat commented on a change in pull request #4995: Decouple server instance 
id with hostname/port config.
URL: https://github.com/apache/incubator-pinot/pull/4995#discussion_r368170412
 
 

 ##########
 File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ServerStarterIntegrationTest.java
 ##########
 @@ -0,0 +1,179 @@
+/**
+ * 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.pinot.integration.tests;
+
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.common.utils.ZkStarter;
+import org.apache.pinot.controller.helix.ControllerTest;
+import org.apache.pinot.server.starter.helix.HelixServerStarter;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static 
org.apache.pinot.common.utils.CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST;
+import static 
org.apache.pinot.common.utils.CommonConstants.Helix.KEY_OF_SERVER_NETTY_PORT;
+import static 
org.apache.pinot.common.utils.CommonConstants.Server.CONFIG_OF_INSTANCE_ID;
+import static 
org.apache.pinot.common.utils.CommonConstants.Server.CONFIG_OF_USE_LOGICAL_INSTANCE_ID;
+import static org.testng.Assert.assertEquals;
+
+
+public class ServerStarterIntegrationTest extends ControllerTest {
+  public static final String DEFAULT_SERVER_ID = "Server_127.0.0.1_8098";
+  public static final String SERVER1 = "Server1";
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    startZk();
+    startController();
+  }
+
+  @AfterClass
+  public void tearDown()
+      throws Exception {
+    stopController();
+    stopZk();
+  }
+
+  @Test
+  public void testWithNoInstanceIdNoHostnamePort()
+      throws Exception {
+    // Test the behavior when no instance id nor hostname/port is specified in 
server conf.
+    Configuration serverConf = new PropertiesConfiguration();
+    // Start the server
+    HelixServerStarter helixServerStarter =
+        new HelixServerStarter(getHelixClusterName(), 
ZkStarter.DEFAULT_ZK_STR, serverConf);
+
+    // Verify the serverId, host and port are set correctly in Zk.
+    HelixManager helixManager = helixServerStarter.getHelixManager();
+    PropertyKey.Builder keyBuilder = 
helixManager.getHelixDataAccessor().keyBuilder();
+    InstanceConfig config =  
helixManager.getHelixDataAccessor().getProperty(keyBuilder.instanceConfig(DEFAULT_SERVER_ID));
+    helixServerStarter.stop();
+
+    assertEquals(config.getInstanceName(), DEFAULT_SERVER_ID);
+    // By default (auto joined instances), server instance name is of format: 
{@code Server_<hostname>_<port>}, e.g.
+    // {@code Server_localhost_12345}, hostname is of format: {@code 
Server_<hostname>}, e.g. {@code Server_localhost}.
+    // More details refer to the class ServerInstance.
+    assertEquals(config.getHostName(), "Server_127.0.0.1");
+    assertEquals(config.getPort(), "8098");
+  }
+
+  @Test
+  public void testWithNoInstanceIdButWithHostnamePort()
+      throws Exception {
+    // Test the behavior when no instance id specified but hostname/port is 
specified in server conf.
+    Configuration serverConf = new PropertiesConfiguration();
+    serverConf.setProperty(KEY_OF_SERVER_NETTY_HOST, "host1");
+    serverConf.setProperty(KEY_OF_SERVER_NETTY_PORT, 10001);
+    // Start the server
+    HelixServerStarter helixServerStarter =
 
 Review comment:
   Code refactored to remove duplicate codes.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to