/**
 * 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.transport.common;

import org.apache.pinot.common.response.ServerInstance;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;


public class ServerInstanceTest {

  @Test
  public void testServerInstance() {
    // Same local host name and port
    assertEquals(new ServerInstance("localhost", 8080), new ServerInstance("localhost", 8080));

    // Same IP address host and port
    assertEquals(new ServerInstance("127.0.0.1", 8080), new ServerInstance("127.0.0.1", 8080));

    // Same other host name and port
    assertEquals(new ServerInstance("test-host", 8080), new ServerInstance("test-host", 8080));

    // Same other IP address host and port
    assertEquals(new ServerInstance("192.168.0.1", 8080), new ServerInstance("192.168.0.1", 8080));

    // Same local host and port, one with host name and one with IP address
    assertEquals(new ServerInstance("localhost", 8080), new ServerInstance("127.0.0.1", 8080));

    // Same host but different port
    assertNotEquals(new ServerInstance("localhost", 8081), new ServerInstance("localhost", 8082));

    // Same port but different host
    assertNotEquals(new ServerInstance("foo", 8080), new ServerInstance("bar", 8080));
  }
}

/**
 * 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.transport.common;

import java.net.InetAddress;
import org.apache.pinot.common.response.ServerInstance;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;


public class ServerInstanceTest {

  @Test
  public void testServerInstance()
      throws Exception {
    // Same local host name and port
    assertEquals(new ServerInstance("localhost", 8080), new ServerInstance("localhost", 8080));

    // Same local host IP address and port
    assertEquals(new ServerInstance("127.0.0.1", 8080), new ServerInstance("127.0.0.1", 8080));

    // Same other host name and port
    assertEquals(new ServerInstance("test-host", 8080), new ServerInstance("test-host", 8080));

    // Same other host IP address and port
    assertEquals(new ServerInstance("192.168.0.1", 8080), new ServerInstance("192.168.0.1", 8080));

    // Same local host and port, one with IP address and one with host name
    assertEquals(new ServerInstance("127.0.0.1", 8080),
        new ServerInstance(InetAddress.getByName("127.0.0.1").getHostName(), 8080));

    // Same host but different port
    assertNotEquals(new ServerInstance("localhost", 8081), new ServerInstance("localhost", 8082));

    // Same port but different host
    assertNotEquals(new ServerInstance("foo", 8080), new ServerInstance("bar", 8080));
  }
}

Fix ServerInstanceTest (#4442)