This is an automated email from the ASF dual-hosted git repository.

piotr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b171164e feat(java): Add test for AsyncIggyTcpClientBuilder (#2726)
1b171164e is described below

commit 1b171164e1119ac635aefdcd3de1a99ad0b080ef
Author: Qichao Chu <[email protected]>
AuthorDate: Sat Feb 14 15:30:18 2026 -0800

    feat(java): Add test for AsyncIggyTcpClientBuilder (#2726)
    
    Closes #2725
---
 .../async/tcp/AsyncIggyTcpClientBuilderTest.java   | 330 ++++++++++++++++++++-
 1 file changed, 321 insertions(+), 9 deletions(-)

diff --git 
a/foreign/java/java-sdk/src/test/java/org/apache/iggy/client/async/tcp/AsyncIggyTcpClientBuilderTest.java
 
b/foreign/java/java-sdk/src/test/java/org/apache/iggy/client/async/tcp/AsyncIggyTcpClientBuilderTest.java
index 643671e2b..db8aa9bae 100644
--- 
a/foreign/java/java-sdk/src/test/java/org/apache/iggy/client/async/tcp/AsyncIggyTcpClientBuilderTest.java
+++ 
b/foreign/java/java-sdk/src/test/java/org/apache/iggy/client/async/tcp/AsyncIggyTcpClientBuilderTest.java
@@ -19,33 +19,41 @@
 
 package org.apache.iggy.client.async.tcp;
 
+import org.apache.iggy.client.blocking.IggyBaseClient;
 import org.apache.iggy.client.blocking.IntegrationTest;
+import org.apache.iggy.config.RetryPolicy;
 import org.apache.iggy.exception.IggyInvalidArgumentException;
+import org.apache.iggy.exception.IggyMissingCredentialsException;
+import org.apache.iggy.exception.IggyNotConnectedException;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
+import java.time.Duration;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
-import static org.apache.iggy.client.blocking.IntegrationTest.LOCALHOST_IP;
-import static org.apache.iggy.client.blocking.IntegrationTest.TCP_PORT;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 /**
  * Integration tests for AsyncIggyTcpClient builder pattern.
  * Tests the builder functionality against a running Iggy server.
  */
-public abstract class AsyncIggyTcpClientBuilderTest extends IntegrationTest {
+class AsyncIggyTcpClientBuilderTest extends IntegrationTest {
+
+    private static final String TEST_USERNAME = "iggy";
+    private static final String TEST_PASSWORD = "iggy";
+    private static final int TEST_TIMEOUT_SECONDS = 5;
 
     private AsyncIggyTcpClient client;
 
     @AfterEach
     void cleanup() throws Exception {
         if (client != null) {
-            client.close().get(5, TimeUnit.SECONDS);
+            client.close().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
         }
     }
 
@@ -55,7 +63,7 @@ public abstract class AsyncIggyTcpClientBuilderTest extends 
IntegrationTest {
         client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(tcpPort()).build();
 
         // When: Connect to server
-        client.connect().get(5, TimeUnit.SECONDS);
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
 
         // Then: Client should be connected and functional
         assertNotNull(client.users());
@@ -67,11 +75,16 @@ public abstract class AsyncIggyTcpClientBuilderTest extends 
IntegrationTest {
 
     @Test
     void shouldUseDefaultValues() throws Exception {
+        // This only applies to external-server mode where endpoint is fixed 
at localhost:8090.
+        assumeTrue(
+                System.getenv("USE_EXTERNAL_SERVER") != null,
+                "Default host/port test requires external server mode at 
127.0.0.1:8090");
+
         // Given: Builder with defaults (should use host=localhost, port=8090)
         client = AsyncIggyTcpClient.builder().build();
 
         // When: Connect to server
-        client.connect().get(5, TimeUnit.SECONDS);
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
 
         // Then: Should succeed
         assertNotNull(client.users());
@@ -123,7 +136,7 @@ public abstract class AsyncIggyTcpClientBuilderTest extends 
IntegrationTest {
         client = new AsyncIggyTcpClient(LOCALHOST_IP, tcpPort());
 
         // When: Connect to server
-        client.connect().get(5, TimeUnit.SECONDS);
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
 
         // Then: Should work as before
         assertNotNull(client.users());
@@ -135,7 +148,7 @@ public abstract class AsyncIggyTcpClientBuilderTest extends 
IntegrationTest {
         client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(tcpPort()).build();
 
         // When: Connect
-        client.connect().get(5, TimeUnit.SECONDS);
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
 
         // Then: Should be able to access all clients
         assertNotNull(client.users(), "Users client should not be null");
@@ -153,10 +166,309 @@ public abstract class AsyncIggyTcpClientBuilderTest 
extends IntegrationTest {
 
         // When: Close connection
         CompletableFuture<Void> closeFuture = client.close();
-        closeFuture.get(5, TimeUnit.SECONDS);
+        closeFuture.get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
 
         // Then: Should complete without exception
         assertTrue(closeFuture.isDone());
         assertFalse(closeFuture.isCompletedExceptionally());
     }
+
+    @Test
+    void testThrowExceptionWhenLoginBeforeConnect() {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(TCP_PORT)
+                .credentials(TEST_USERNAME, TEST_PASSWORD)
+                .build();
+
+        assertThrows(IggyNotConnectedException.class, () -> client.login());
+    }
+
+    @Test
+    void testThrowExceptionWhenAccessingUsersBeforeConnect() {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).build();
+
+        assertThrows(IggyNotConnectedException.class, () -> client.users());
+    }
+
+    @Test
+    void testThrowExceptionWhenAccessingMessagesBeforeConnect() {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).build();
+
+        assertThrows(IggyNotConnectedException.class, () -> client.messages());
+    }
+
+    @Test
+    void testThrowExceptionWhenAccessingStreamsBeforeConnect() {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).build();
+
+        assertThrows(IggyNotConnectedException.class, () -> client.streams());
+    }
+
+    @Test
+    void testThrowExceptionWhenAccessingTopicsBeforeConnect() {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).build();
+
+        assertThrows(IggyNotConnectedException.class, () -> client.topics());
+    }
+
+    @Test
+    void testThrowExceptionWhenAccessingConsumerGroupsBeforeConnect() {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).build();
+
+        assertThrows(IggyNotConnectedException.class, () -> 
client.consumerGroups());
+    }
+
+    @Test
+    void testThrowExceptionWhenLoginWithoutCredentials() throws Exception {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(tcpPort()).build();
+        client.connect().get(5, TimeUnit.SECONDS);
+
+        assertThrows(IggyMissingCredentialsException.class, () -> 
client.login());
+    }
+
+    @Test
+    void testThrowExceptionWhenBuildAndLoginWithoutCredentials() {
+        AsyncIggyTcpClientBuilder builder =
+                AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT);
+
+        assertThrows(IggyMissingCredentialsException.class, 
builder::buildAndLogin);
+    }
+
+    @Test
+    void testThrowExceptionWhenBuildAndLoginWithNullUsername() {
+        AsyncIggyTcpClientBuilder builder =
+                
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).credentials(null,
 TEST_PASSWORD);
+
+        assertThrows(IggyMissingCredentialsException.class, 
builder::buildAndLogin);
+    }
+
+    @Test
+    void testThrowExceptionWhenBuildAndLoginWithNullPassword() {
+        AsyncIggyTcpClientBuilder builder =
+                
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).credentials(TEST_USERNAME,
 null);
+
+        assertThrows(IggyMissingCredentialsException.class, 
builder::buildAndLogin);
+    }
+
+    @Test
+    void testBuildClientWithCredentials() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .credentials(TEST_USERNAME, TEST_PASSWORD)
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithConnectionTimeout() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .connectionTimeout(Duration.ofSeconds(10))
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithRequestTimeout() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .requestTimeout(Duration.ofSeconds(30))
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithConnectionPoolSize() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .connectionPoolSize(5)
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithExponentialBackoffRetryPolicy() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .retryPolicy(RetryPolicy.exponentialBackoff())
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithFixedDelayRetryPolicy() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .retryPolicy(RetryPolicy.fixedDelay(3, Duration.ofMillis(100)))
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithNoRetryPolicy() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .retryPolicy(RetryPolicy.noRetry())
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithTlsBoolean() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .tls(false)
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildClientWithEnableTls() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(TCP_PORT)
+                .enableTls()
+                .build();
+
+        assertNotNull(client);
+    }
+
+    @Test
+    void testBuildClientWithAllConfigurationOptions() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .credentials(TEST_USERNAME, TEST_PASSWORD)
+                .connectionTimeout(Duration.ofSeconds(10))
+                .requestTimeout(Duration.ofSeconds(30))
+                .connectionPoolSize(5)
+                .retryPolicy(RetryPolicy.exponentialBackoff())
+                .tls(false)
+                .build();
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+        assertNotNull(client.messages());
+        assertNotNull(client.streams());
+        assertNotNull(client.topics());
+        assertNotNull(client.consumerGroups());
+    }
+
+    @Test
+    void testBuildAndLoginSuccessfully() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .credentials(TEST_USERNAME, TEST_PASSWORD)
+                .buildAndLogin()
+                .get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+        assertNotNull(client.messages());
+        assertNotNull(client.streams());
+        assertNotNull(client.topics());
+        assertNotNull(client.consumerGroups());
+    }
+
+    @Test
+    void testHandleCloseOnUnconnectedClient() throws Exception {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(TCP_PORT).build();
+
+        CompletableFuture<Void> closeFuture = client.close();
+        closeFuture.get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertTrue(closeFuture.isDone());
+        assertFalse(closeFuture.isCompletedExceptionally());
+    }
+
+    @Test
+    void testHandleMultipleCloseCalls() throws Exception {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(tcpPort()).build();
+        client.connect().get(5, TimeUnit.SECONDS);
+
+        CompletableFuture<Void> firstClose = client.close();
+        firstClose.get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        CompletableFuture<Void> secondClose = client.close();
+        secondClose.get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertTrue(firstClose.isDone());
+        assertFalse(firstClose.isCompletedExceptionally());
+        assertTrue(secondClose.isDone());
+        assertFalse(secondClose.isCompletedExceptionally());
+    }
+
+    @Test
+    void testHandleNullTlsCertificateString() {
+        AsyncIggyTcpClientBuilder builder = 
AsyncIggyTcpClient.builder().tlsCertificate((String) null);
+
+        assertNotNull(builder);
+    }
+
+    @Test
+    void testHandleEmptyTlsCertificateString() {
+        AsyncIggyTcpClientBuilder builder = 
AsyncIggyTcpClient.builder().tlsCertificate("");
+
+        assertNotNull(builder);
+    }
+
+    @Test
+    void testHandleBlankTlsCertificateString() {
+        AsyncIggyTcpClientBuilder builder = 
AsyncIggyTcpClient.builder().tlsCertificate("   ");
+
+        assertNotNull(builder);
+    }
+
+    @Test
+    void testBuildConnectAndLoginManually() throws Exception {
+        client = AsyncIggyTcpClient.builder()
+                .host(LOCALHOST_IP)
+                .port(tcpPort())
+                .credentials(TEST_USERNAME, TEST_PASSWORD)
+                .build();
+
+        client.connect().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        client.login().get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Test
+    void testBuildAndConnectWithoutCredentialsThenLoginExplicitly() throws 
Exception {
+        client = 
AsyncIggyTcpClient.builder().host(LOCALHOST_IP).port(tcpPort()).build();
+
+        client.connect().get(5, TimeUnit.SECONDS);
+        client.users().login(TEST_USERNAME, 
TEST_PASSWORD).get(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+        assertNotNull(client.users());
+    }
+
+    @Override
+    protected IggyBaseClient getClient() {
+        return null;
+    }
 }

Reply via email to