Skip to content

Commit 0f77318

Browse files
committed
Make BitbucketApi extends Autoclosable so that who get the interface is warned to close the obtained client implementation.
1 parent 176feea commit 0f77318

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/BitbucketApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Provides access to a specific repository.
4040
* One API object needs to be created for each repository you want to work with.
4141
*/
42-
public interface BitbucketApi {
42+
public interface BitbucketApi extends AutoCloseable {
4343

4444
/**
4545
* Returns the owner name for the repository.

src/test/java/com/cloudbees/jenkins/plugins/bitbucket/impl/client/ExponentialBackOffServiceUnavailableRetryStrategyTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void test_retry(ClientAndServer mockServer) throws Exception {
6060
);
6161

6262
final RetryInterceptor counterInterceptor = new RetryInterceptor();
63-
BitbucketApi client = new BitbucketServerAPIClient("http://localhost:" + mockServer.getPort(),
63+
try (BitbucketApi client = new BitbucketServerAPIClient("http://localhost:" + mockServer.getPort(),
6464
"test",
6565
"testRepos",
6666
(BitbucketAuthenticator) null,
@@ -73,10 +73,11 @@ protected HttpClientBuilder setupClientBuilder(String host) {
7373
.setServiceUnavailableRetryStrategy(new ExponentialBackOffServiceUnavailableRetryStrategy(2, 5, 100))
7474
.addInterceptorFirst(counterInterceptor);
7575
}
76-
};
76+
}) {
7777

78-
assertThatIOException().isThrownBy(() -> client.getTags());
79-
assertThat(counterInterceptor.getRetry()).isEqualTo(6); // retry after 5ms, 10ms, 20ms, 40ms, 80ms, 100ms
78+
assertThatIOException().isThrownBy(() -> client.getTags());
79+
assertThat(counterInterceptor.getRetry()).isEqualTo(6); // retry after 5ms, 10ms, 20ms, 40ms, 80ms, 100ms
80+
}
8081
}
8182

8283
private static class RetryInterceptor implements HttpResponseInterceptor {

0 commit comments

Comments
 (0)