Skip to content

Commit

Permalink
Make call timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sgdesmet committed Oct 7, 2024
1 parent 258d345 commit dac14af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -96,6 +97,13 @@ public static void setHttpProxy(String host, int port, String username, String p
.build();
}

public static void setTimeout(final Duration duration) {

Objects.requireNonNull(duration, "Duration cannot be null");
sharedClient = sharedClient.newBuilder()
.callTimeout( duration )
.build();
}

/**
* Create service s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.net.ProxySelector;
import java.net.URISyntaxException;
import java.time.Duration;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -116,4 +117,21 @@ void testSetHttpProxy_WithAuthentication() {
assertEquals(CustomProxyAuthenticator.class, WhatsappApiServiceGenerator.getSharedClient().proxyAuthenticator().getClass(), "Authenticator should be CustomProxyAuthenticator");

}

/**
* Method under test:
* {@link WhatsappApiServiceGenerator#setTimeout(Duration)}
*/
@Test
void testSetTimeout() {

assertEquals( 20 * 1000, WhatsappApiServiceGenerator.getSharedClient().callTimeoutMillis() );

// Set timeout in shared client
WhatsappApiServiceGenerator.setTimeout( Duration.ofMinutes( 1L ) );

// Check if timeout is set
assertEquals( 60 * 1000, WhatsappApiServiceGenerator.getSharedClient().callTimeoutMillis() );
}

}

0 comments on commit dac14af

Please sign in to comment.