Created
February 28, 2017 14:33
-
-
Save reevesm/daf8fcb3824ae9c3f9c2e35a3f1322ff to your computer and use it in GitHub Desktop.
Ratpack-hystrix collapser throwing UnmanagedThreadException
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
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