mirror of https://github.com/apache/jclouds.git
[JCLOUDS-1011] force closing HTTP client connection after using Docker build REST API method
This commit is contained in:
parent
288d387610
commit
d7b3f5d98f
|
@ -65,7 +65,7 @@ public interface MiscApi {
|
||||||
@Named("image:build")
|
@Named("image:build")
|
||||||
@POST
|
@POST
|
||||||
@Path("/build")
|
@Path("/build")
|
||||||
@Headers(keys = "Content-Type", values = "application/tar")
|
@Headers(keys = { "Content-Type", "Connection" }, values = { "application/tar", "close" })
|
||||||
InputStream build(Payload inputStream);
|
InputStream build(Payload inputStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +79,7 @@ public interface MiscApi {
|
||||||
@Named("image:build")
|
@Named("image:build")
|
||||||
@POST
|
@POST
|
||||||
@Path("/build")
|
@Path("/build")
|
||||||
@Headers(keys = "Content-Type", values = "application/tar")
|
@Headers(keys = { "Content-Type", "Connection" }, values = { "application/tar", "close" })
|
||||||
InputStream build(Payload inputStream, BuildOptions options);
|
InputStream build(Payload inputStream, BuildOptions options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.jclouds.docker.features;
|
||||||
|
|
||||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
import com.squareup.okhttp.mockwebserver.RecordedRequest;
|
||||||
|
|
||||||
import org.jclouds.docker.DockerApi;
|
import org.jclouds.docker.DockerApi;
|
||||||
import org.jclouds.docker.internal.BaseDockerMockTest;
|
import org.jclouds.docker.internal.BaseDockerMockTest;
|
||||||
import org.jclouds.docker.parse.InfoParseTest;
|
import org.jclouds.docker.parse.InfoParseTest;
|
||||||
|
@ -26,11 +28,14 @@ import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.jclouds.docker.compute.BaseDockerApiLiveTest.tarredDockerfile;
|
import static org.jclouds.docker.compute.BaseDockerApiLiveTest.tarredDockerfile;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock tests for the {@link org.jclouds.docker.features.MiscApi} class.
|
* 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();
|
MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi();
|
||||||
try {
|
try {
|
||||||
api.build(tarredDockerfile());
|
api.build(tarredDockerfile());
|
||||||
assertSent(server, "POST", "/build");
|
RecordedRequest request = assertSent(server, "POST", "/build");
|
||||||
|
assertDockerBuildHttpHeaders(request);
|
||||||
} finally {
|
} finally {
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
}
|
}
|
||||||
|
@ -79,10 +85,22 @@ public class MiscApiMockTest extends BaseDockerMockTest {
|
||||||
payload.getContentMetadata().setContentLength(file.length());
|
payload.getContentMetadata().setContentLength(file.length());
|
||||||
try {
|
try {
|
||||||
api.build(payload);
|
api.build(payload);
|
||||||
assertSent(server, "POST", "/build");
|
RecordedRequest request = assertSent(server, "POST", "/build");
|
||||||
|
assertDockerBuildHttpHeaders(request);
|
||||||
} finally {
|
} finally {
|
||||||
server.shutdown();
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue