This is an automated email from the ASF dual-hosted git repository.
nixonrodrigues pushed a commit to branch atlas-2.6
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/atlas-2.6 by this push:
new 6e9e1c756 ATLAS-5402 : Fix AtlasAdminClientTest UnitTest case on 2.6.
(#751)
6e9e1c756 is described below
commit 6e9e1c756e423164f6bb09605ee6e21d24704480
Author: Nixon Rodrigues <[email protected]>
AuthorDate: Wed Sep 9 17:34:08 2026 +0530
ATLAS-5402 : Fix AtlasAdminClientTest UnitTest case on 2.6. (#751)
---
.../org/apache/atlas/AtlasAdminClientTest.java | 28 +++++++++++++++-------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git
a/client/client-v1/src/test/java/org/apache/atlas/AtlasAdminClientTest.java
b/client/client-v1/src/test/java/org/apache/atlas/AtlasAdminClientTest.java
index cb1395b0d..f6f1026a6 100644
--- a/client/client-v1/src/test/java/org/apache/atlas/AtlasAdminClientTest.java
+++ b/client/client-v1/src/test/java/org/apache/atlas/AtlasAdminClientTest.java
@@ -30,9 +30,11 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.net.ServerSocket;
import java.security.Permission;
import static org.mockito.Mockito.mock;
@@ -44,6 +46,16 @@ import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
public class AtlasAdminClientTest {
+ /**
+ * Returns an {@code http://127.0.0.1:<port>} URL where {@code port} is
unused so the client reliably
+ * fails to connect (avoids asserting on {@code localhost:21000}, which
often has Atlas in dev/CI).
+ */
+ private static String unreachableAtlasRestUrl() throws IOException {
+ try (ServerSocket socket = new ServerSocket(0)) {
+ return "http://127.0.0.1:" + socket.getLocalPort();
+ }
+ }
+
@Mock
private Configuration mockConfiguration;
@@ -311,7 +323,7 @@ public class AtlasAdminClientTest {
public void testRunWithValidStatusOption() throws Exception {
applicationPropertiesMock.when(ApplicationProperties::get).thenReturn(mockConfiguration);
when(mockConfiguration.getStringArray("atlas.rest.address"))
- .thenReturn(new String[] {"http://localhost:21000"});
+ .thenReturn(new String[] {unreachableAtlasRestUrl()});
authenticationUtilMock.when(AuthenticationUtil::isKerberosAuthenticationEnabled).thenReturn(false);
authenticationUtilMock.when(AuthenticationUtil::getBasicAuthenticationInput)
@@ -323,7 +335,6 @@ public class AtlasAdminClientTest {
try {
int result = (Integer) runMethod.invoke(client, (Object) new
String[] {"-status"});
- // If we get here, it should be -1
assertEquals(result, -1);
} catch (Exception e) {
assertTrue(e.getCause().getMessage().contains("Connection") ||
e.getCause().getMessage().contains("refused"));
@@ -334,7 +345,7 @@ public class AtlasAdminClientTest {
public void testRunWithValidStatsOption() throws Exception {
applicationPropertiesMock.when(ApplicationProperties::get).thenReturn(mockConfiguration);
when(mockConfiguration.getStringArray("atlas.rest.address"))
- .thenReturn(new String[] {"http://localhost:21000"});
+ .thenReturn(new String[] {unreachableAtlasRestUrl()});
authenticationUtilMock.when(AuthenticationUtil::isKerberosAuthenticationEnabled).thenReturn(false);
authenticationUtilMock.when(AuthenticationUtil::getBasicAuthenticationInput)
@@ -367,9 +378,10 @@ public class AtlasAdminClientTest {
runMethod.setAccessible(true);
try {
- // Act
+ // Act: null address falls back to
AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS (localhost:21000)
int result = (Integer) runMethod.invoke(client, (Object) new
String[] {"-status"});
- assertEquals(result, -1);
+ assertTrue(result == 0 || result == -1,
+ "Default REST URL success depends on whether a server
listens on localhost:21000");
} catch (Exception e) {
assertTrue(e.getCause().getMessage().contains("Connection") ||
e.getCause().getMessage().contains("refused"));
}
@@ -389,10 +401,10 @@ public class AtlasAdminClientTest {
runMethod.setAccessible(true);
try {
- // Act
+ // Act: empty array falls back to DEFAULT_ATLAS_REST_ADDRESS —
outcome is environment-dependent
int result = (Integer) runMethod.invoke(client, (Object) new
String[] {"-status"});
- // If we get here, should be -1
- assertEquals(result, -1);
+ assertTrue(result == 0 || result == -1,
+ "Default REST URL success depends on whether a server
listens on localhost:21000");
} catch (Exception e) {
assertTrue(e.getCause().getMessage().contains("Connection") ||
e.getCause().getMessage().contains("refused"));
}