-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from zalando/bugfix/default-circuit-breaker
Removed default circuit breaker
- Loading branch information
Showing
5 changed files
with
199 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.zalando.riptide.failsafe; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.restdriver.clientdriver.ClientDriverRule; | ||
import net.jodah.failsafe.CircuitBreaker; | ||
import net.jodah.failsafe.CircuitBreakerOpenException; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; | ||
import org.zalando.riptide.Http; | ||
import org.zalando.riptide.OriginalStackTracePlugin; | ||
import org.zalando.riptide.httpclient.RestAsyncClientHttpRequestFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.SocketTimeoutException; | ||
import java.util.concurrent.CompletionException; | ||
|
||
import static com.github.restdriver.clientdriver.RestClientDriver.giveEmptyResponse; | ||
import static com.github.restdriver.clientdriver.RestClientDriver.onRequestTo; | ||
import static java.util.concurrent.Executors.newSingleThreadExecutor; | ||
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.zalando.fauxpas.FauxPas.partially; | ||
import static org.zalando.riptide.PassRoute.pass; | ||
|
||
public class FailsafePluginCircuitBreakerTest { | ||
|
||
@Rule | ||
public final ClientDriverRule driver = new ClientDriverRule(); | ||
|
||
private final CloseableHttpClient client = HttpClientBuilder.create() | ||
.setDefaultRequestConfig(RequestConfig.custom() | ||
.setSocketTimeout(500) | ||
.build()) | ||
.build(); | ||
|
||
private final RetryListener listeners = mock(RetryListener.class); | ||
|
||
private final Http unit = Http.builder() | ||
.baseUrl(driver.getBaseUrl()) | ||
.requestFactory(new RestAsyncClientHttpRequestFactory(client, | ||
new ConcurrentTaskExecutor(newSingleThreadExecutor()))) | ||
.converter(createJsonConverter()) | ||
.plugin(new FailsafePlugin(newSingleThreadScheduledExecutor()) | ||
.withCircuitBreaker(new CircuitBreaker() | ||
.withDelay(1, SECONDS)) | ||
.withListener(listeners)) | ||
.plugin(new OriginalStackTracePlugin()) | ||
.build(); | ||
|
||
private static MappingJackson2HttpMessageConverter createJsonConverter() { | ||
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); | ||
converter.setObjectMapper(createObjectMapper()); | ||
return converter; | ||
} | ||
|
||
private static ObjectMapper createObjectMapper() { | ||
return new ObjectMapper().findAndRegisterModules() | ||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
client.close(); | ||
} | ||
|
||
@Test(expected = CircuitBreakerOpenException.class) | ||
public void shouldOpenCircuit() throws Throwable { | ||
driver.addExpectation(onRequestTo("/foo"), giveEmptyResponse().after(800, MILLISECONDS)); | ||
|
||
unit.get("/foo").call(pass()) | ||
.exceptionally(partially(SocketTimeoutException.class, this::ignore)) | ||
.join(); | ||
|
||
try { | ||
unit.get("/foo").call(pass()).join(); | ||
} catch (final CompletionException e) { | ||
throw e.getCause(); | ||
} | ||
} | ||
|
||
private Void ignore(@SuppressWarnings("unused") final Throwable throwable) { | ||
return null; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...ilsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoCircuitBreakerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.zalando.riptide.failsafe; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.restdriver.clientdriver.ClientDriverRule; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; | ||
import org.zalando.riptide.Http; | ||
import org.zalando.riptide.OriginalStackTracePlugin; | ||
import org.zalando.riptide.httpclient.RestAsyncClientHttpRequestFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.SocketTimeoutException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.github.restdriver.clientdriver.RestClientDriver.giveEmptyResponse; | ||
import static com.github.restdriver.clientdriver.RestClientDriver.onRequestTo; | ||
import static java.util.concurrent.Executors.newSingleThreadExecutor; | ||
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.zalando.fauxpas.FauxPas.partially; | ||
import static org.zalando.riptide.PassRoute.pass; | ||
|
||
public class FailsafePluginNoCircuitBreakerTest { | ||
|
||
@Rule | ||
public final ClientDriverRule driver = new ClientDriverRule(); | ||
|
||
private final CloseableHttpClient client = HttpClientBuilder.create() | ||
.setDefaultRequestConfig(RequestConfig.custom() | ||
.setSocketTimeout(500) | ||
.build()) | ||
.build(); | ||
|
||
private final RetryListener listeners = mock(RetryListener.class); | ||
|
||
private final Http unit = Http.builder() | ||
.baseUrl(driver.getBaseUrl()) | ||
.requestFactory(new RestAsyncClientHttpRequestFactory(client, | ||
new ConcurrentTaskExecutor(newSingleThreadExecutor()))) | ||
.converter(createJsonConverter()) | ||
.plugin(new FailsafePlugin(newSingleThreadScheduledExecutor()) | ||
.withListener(listeners)) | ||
.plugin(new OriginalStackTracePlugin()) | ||
.build(); | ||
|
||
private static MappingJackson2HttpMessageConverter createJsonConverter() { | ||
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); | ||
converter.setObjectMapper(createObjectMapper()); | ||
return converter; | ||
} | ||
|
||
private static ObjectMapper createObjectMapper() { | ||
return new ObjectMapper().findAndRegisterModules() | ||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
client.close(); | ||
} | ||
|
||
@Test | ||
public void shouldNotOpenCircuit() { | ||
driver.addExpectation(onRequestTo("/foo"), giveEmptyResponse().after(800, MILLISECONDS)); | ||
driver.addExpectation(onRequestTo("/foo"), giveEmptyResponse().after(800, MILLISECONDS)); | ||
driver.addExpectation(onRequestTo("/foo"), giveEmptyResponse()); | ||
|
||
unit.get("/foo").call(pass()) | ||
.exceptionally(this::ignore) | ||
.join(); | ||
|
||
final CompletableFuture<Void> timeout = unit.get("/foo").call(pass()); | ||
final CompletableFuture<Void> last = unit.get("/foo").call(pass()); | ||
|
||
timeout.exceptionally(partially(SocketTimeoutException.class, this::ignore)).join(); | ||
last.join(); | ||
} | ||
|
||
private Void ignore(@SuppressWarnings("unused") final Throwable throwable) { | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters