Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@
public class ResilientCloudControllerClient implements CloudControllerClient {

private final CloudControllerClientImpl delegate;
private final Supplier<ResilientCloudOperationExecutor> executorFactory;

public ResilientCloudControllerClient(CloudControllerRestClient delegate) {
this(delegate, ResilientCloudOperationExecutor::new);
}

protected ResilientCloudControllerClient(CloudControllerRestClient delegate,
Supplier<ResilientCloudOperationExecutor> executorFactory) {
this.delegate = new CloudControllerClientImpl(delegate);
this.executorFactory = executorFactory;
}

@Override
Expand Down Expand Up @@ -631,12 +638,14 @@ private void executeWithRetry(Runnable operation, HttpStatus... statusesToIgnore
}

private <T> T executeWithRetry(Supplier<T> operation, HttpStatus... statusesToIgnore) {
ResilientCloudOperationExecutor executor = new ResilientCloudOperationExecutor().withStatusesToIgnore(statusesToIgnore);
ResilientCloudOperationExecutor executor = executorFactory.get()
.withStatusesToIgnore(statusesToIgnore);
return executor.execute(operation);
}

private <T> T executeWithExponentialBackoff(Function<Duration, T> operation, HttpStatus... statusesToIgnore) {
ResilientCloudOperationExecutor executor = new ResilientCloudOperationExecutor().withStatusesToIgnore(statusesToIgnore);
ResilientCloudOperationExecutor executor = executorFactory.get()
.withStatusesToIgnore(statusesToIgnore);
return executor.executeWithExponentialBackoff(operation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public ResilientCloudOperationExecutor withStatusesToIgnore(HttpStatus... status
return this;
}

ResilientCloudOperationExecutor withSleeper(LongConsumer sleeper) {
this.sleeper = sleeper;
public ResilientCloudOperationExecutor withRandomDelaySupplier(LongSupplier randomDelaySupplier) {
this.randomDelaySupplier = randomDelaySupplier;
return this;
}

ResilientCloudOperationExecutor withRandomDelaySupplier(LongSupplier randomDelaySupplier) {
this.randomDelaySupplier = randomDelaySupplier;
ResilientCloudOperationExecutor withSleeper(LongConsumer sleeper) {
this.sleeper = sleeper;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudSpace;
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudStack;
import org.cloudfoundry.multiapps.controller.client.facade.rest.CloudControllerRestClient;
import org.cloudfoundry.multiapps.controller.client.util.ResilientCloudOperationExecutor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,7 +31,8 @@ class ResilientCloudControllerClientTest {
@BeforeEach
void setUp() {
restClient = Mockito.mock(CloudControllerRestClient.class);
client = new ResilientCloudControllerClient(restClient);
client = new ResilientCloudControllerClient(restClient,
() -> new ResilientCloudOperationExecutor().withWaitTimeBetweenRetriesInMillis(0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static HttpStatusCodeException prepareHttpStatusCodeException(HttpStatus
@Test
void testHandleErrorsWithWrongExceptionType() {
ResilientCloudOperationExecutor resilientCloudOperationExecutor = new ResilientCloudOperationExecutor().withWaitTimeBetweenRetriesInMillis(
0);
0).withRandomDelaySupplier(() -> 0);
CustomControllerClientErrorHandler customControllerClientErrorHandler = new CustomControllerClientErrorHandler().withExecutorFactory(
() -> resilientCloudOperationExecutor);
Assertions.assertThrows(IllegalArgumentException.class, () -> customControllerClientErrorHandler.handleErrors(() -> {
Expand Down
Loading