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 @@ -28,7 +28,6 @@
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
Expand All @@ -55,7 +54,7 @@
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;

/**
* Tiny helper
* Tiny helper to send http requests over netty.
*/
public class NettyHttpClient implements Closeable {

Expand Down Expand Up @@ -92,9 +91,11 @@ public Collection<HttpResponse> get(SocketAddress remoteAddress, String... uris)
return sendRequests(remoteAddress, requests);
}

public Collection<HttpResponse> post(SocketAddress remoteAddress, Tuple<String, String>... urisAndBodies) throws InterruptedException {
@SafeVarargs // Safe not because it doesn't do anything with the type parameters but because it won't leak them into other methods.
public final Collection<HttpResponse> post(SocketAddress remoteAddress, Tuple<String, CharSequence>... urisAndBodies)
throws InterruptedException {
Collection<HttpRequest> requests = new ArrayList<>(urisAndBodies.length);
for (Tuple<String, String> uriAndBody : urisAndBodies) {
for (Tuple<String, CharSequence> uriAndBody : urisAndBodies) {
ChannelBuffer content = ChannelBuffers.copiedBuffer(uriAndBody.v2(), StandardCharsets.UTF_8);
HttpRequest request = new DefaultHttpRequest(HTTP_1_1, HttpMethod.POST, uriAndBody.v1());
request.headers().add(HOST, "localhost");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void testLimitsInFlightRequests() throws Exception {
bulkRequest.append(System.lineSeparator());
}

Tuple[] requests = new Tuple[] {
@SuppressWarnings("unchecked")
Tuple<String, CharSequence>[] requests = new Tuple[] {
Tuple.tuple("/index/type/_bulk", bulkRequest),
Tuple.tuple("/index/type/_bulk", bulkRequest),
Tuple.tuple("/index/type/_bulk", bulkRequest),
Expand All @@ -83,7 +84,6 @@ public void testLimitsInFlightRequests() throws Exception {
assertThat(singleResponse, hasSize(1));
assertAtLeastOnceExpectedStatus(singleResponse, HttpResponseStatus.OK);

@SuppressWarnings("unchecked")
Collection<HttpResponse> multipleResponses = nettyHttpClient.post(inetSocketTransportAddress.address(), requests);
assertThat(multipleResponses, hasSize(requests.length));
assertAtLeastOnceExpectedStatus(multipleResponses, HttpResponseStatus.SERVICE_UNAVAILABLE);
Expand Down