Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 932f153

Browse files
wendigokokosing
authored andcommitted
Retry token removal only on 5xx response codes
1 parent 79aff1c commit 932f153

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

client/trino-client/src/main/java/io/trino/client/auth/external/HttpTokenPoller.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static io.trino.client.JsonCodec.jsonCodec;
3838
import static io.trino.client.JsonResponse.execute;
3939
import static java.lang.String.format;
40+
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
4041
import static java.net.HttpURLConnection.HTTP_OK;
4142
import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
4243
import static java.time.temporal.ChronoUnit.MILLIS;
@@ -96,7 +97,7 @@ public void tokenReceived(URI tokenUri)
9697
.withMaxAttempts(-1)
9798
.withMaxDuration(Duration.ofSeconds(4))
9899
.withBackoff(100, 500, MILLIS)
99-
.handleResultIf(code -> code != HTTP_OK))
100+
.handleResultIf(code -> code >= HTTP_INTERNAL_ERROR))
100101
.get(() -> {
101102
Request request = prepareRequestBuilder(tokenUri)
102103
.delete()

client/trino-client/src/test/java/io/trino/client/auth/external/TestHttpTokenPoller.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,16 @@ public void testTokenReceived()
176176
}
177177

178178
@Test
179-
public void testTokenReceivedRetriesUntilHTTP_OK()
179+
public void testTokenReceivedRetriesUntilNotErrorReturned()
180180
{
181181
server.enqueue(status(HTTP_UNAVAILABLE));
182182
server.enqueue(status(HTTP_UNAVAILABLE));
183183
server.enqueue(status(HTTP_UNAVAILABLE));
184184
server.enqueue(status(202));
185-
server.enqueue(status(303));
186-
server.enqueue(status(HTTP_OK));
187-
server.enqueue(status(HTTP_OK));
188-
server.enqueue(status(HTTP_OK));
189185

190186
tokenPoller.tokenReceived(tokenUri());
191187

192-
assertThat(server.getRequestCount()).isEqualTo(6);
188+
assertThat(server.getRequestCount()).isEqualTo(4);
193189
}
194190

195191
@Test

0 commit comments

Comments
 (0)