[JCLOUDS-1011] force closing HTTP client connection after using Docker build REST API method

This commit is contained in:
Josef Cacek 2015-10-02 15:00:55 +02:00 committed by Ignasi Barrera
parent 288d387610
commit d7b3f5d98f
2 changed files with 22 additions and 4 deletions

View File

@ -65,7 +65,7 @@ public interface MiscApi {
@Named("image:build")
@POST
@Path("/build")
@Headers(keys = "Content-Type", values = "application/tar")
@Headers(keys = { "Content-Type", "Connection" }, values = { "application/tar", "close" })
InputStream build(Payload inputStream);
/**
@ -79,7 +79,7 @@ public interface MiscApi {
@Named("image:build")
@POST
@Path("/build")
@Headers(keys = "Content-Type", values = "application/tar")
@Headers(keys = { "Content-Type", "Connection" }, values = { "application/tar", "close" })
InputStream build(Payload inputStream, BuildOptions options);
}

View File

@ -18,6 +18,8 @@ package org.jclouds.docker.features;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
import org.jclouds.docker.DockerApi;
import org.jclouds.docker.internal.BaseDockerMockTest;
import org.jclouds.docker.parse.InfoParseTest;
@ -26,11 +28,14 @@ import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jclouds.docker.compute.BaseDockerApiLiveTest.tarredDockerfile;
import static org.testng.Assert.assertEquals;
import java.io.File;
import java.io.FileInputStream;
import javax.ws.rs.core.HttpHeaders;
/**
* Mock tests for the {@link org.jclouds.docker.features.MiscApi} class.
*/
@ -64,7 +69,8 @@ public class MiscApiMockTest extends BaseDockerMockTest {
MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi();
try {
api.build(tarredDockerfile());
assertSent(server, "POST", "/build");
RecordedRequest request = assertSent(server, "POST", "/build");
assertDockerBuildHttpHeaders(request);
} finally {
server.shutdown();
}
@ -79,10 +85,22 @@ public class MiscApiMockTest extends BaseDockerMockTest {
payload.getContentMetadata().setContentLength(file.length());
try {
api.build(payload);
assertSent(server, "POST", "/build");
RecordedRequest request = assertSent(server, "POST", "/build");
assertDockerBuildHttpHeaders(request);
} finally {
server.shutdown();
}
}
/**
* Asserts that correct values of HTTP headers are used in Docker build REST
* API calls.
*
* @param request
*/
private void assertDockerBuildHttpHeaders(RecordedRequest request) {
assertThat(request.getHeader("Connection")).isEqualTo("close");
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("application/tar");
}
}