Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.