Skip to content

Instantly share code, notes, and snippets.

@reevesm
Created February 28, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reevesm/daf8fcb3824ae9c3f9c2e35a3f1322ff to your computer and use it in GitHub Desktop.
Save reevesm/daf8fcb3824ae9c3f9c2e35a3f1322ff to your computer and use it in GitHub Desktop.
Ratpack-hystrix collapser throwing UnmanagedThreadException
class CollapserTest extends BaseHttpClientSpec {
def setup() {
RxRatpack.initialize()
}
def 'exception on collapser command creation'() {
given:
otherApp {
get("foo/:id") { render pathTokens.get("id") }
}
and:
bindings {
module new HystrixModule()
bind(CommandFactory)
}
handlers { CommandFactory factory ->
path("collapser") {
def firstCall = factory.batchCommand().queue()
Blocking.get {
firstCall.get()
} then {
render it
}
}
}
expect:
getText(executionType) == "1"
where:
executionType << ["collapser"]
}
static class CommandFactory {
private final HttpClient httpClient
@Inject
CommandFactory(HttpClient httpClient) {
this.httpClient = httpClient
}
HystrixCollapser<String, String, String> batchCommand() {
new HystrixCollapser<String, String, String>(
HystrixCollapser.Setter.withCollapserKey(
HystrixCollapserKey.Factory.asKey("hystrix-collapser"))
.andScope(HystrixCollapser.Scope.GLOBAL)) {
@Override
String getRequestArgument() {
return "hystrix-command-argument"
}
@Override
protected HystrixCommand<String> createCommand(Collection<HystrixCollapser.CollapsedRequest<String, String>> collapsedRequests) {
return hystrixCommand('1')
}
@Override
protected void mapResponseToRequests(String batchResponse, Collection<HystrixCollapser.CollapsedRequest<String, String>> collapsedRequests) {
// Single response for all requests
for (HystrixCollapser.CollapsedRequest<TrackerResult, Event> request : collapsedRequests) {
request.setResponse(batchResponse)
}
}
}
}
HystrixCommand<String> hystrixCommand(final String requestNumber) {
new HystrixCommand<String>(HystrixCommandGroupKey.Factory.asKey("hystrix-command")) {
@Override
protected String run() throws Exception {
assert Thread.currentThread().name.startsWith("hystrix-${getCacheKey()}-")
requestNumber
}
@Override
protected String getCacheKey() {
return "hystrix-command"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment