X Tutup
Skip to content

Commit 9bd9588

Browse files
committed
Merge pull request #430 from docker-java/issue-424
Fix issue #424
2 parents 70e9680 + af2a37a commit 9bd9588

File tree

8 files changed

+71
-58
lines changed

8 files changed

+71
-58
lines changed

src/main/java/com/github/dockerjava/core/command/ExecStartCmdImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@
55
import java.io.InputStream;
66

77
import com.fasterxml.jackson.annotation.JsonIgnore;
8+
import com.fasterxml.jackson.annotation.JsonInclude;
9+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
811
import com.github.dockerjava.api.async.ResultCallback;
912
import com.github.dockerjava.api.command.ExecStartCmd;
1013
import com.github.dockerjava.api.exception.NotFoundException;
1114
import com.github.dockerjava.api.model.Frame;
1215

16+
@JsonInclude(Include.NON_NULL)
1317
public class ExecStartCmdImpl extends AbstrAsyncDockerCmd<ExecStartCmd, Frame> implements ExecStartCmd {
1418

19+
@JsonIgnore
1520
private String execId;
1621

17-
private Boolean detach, tty;
22+
@JsonProperty("Detach")
23+
private Boolean detach;
24+
25+
@JsonProperty("Tty")
26+
private Boolean tty;
1827

28+
@JsonIgnore
1929
private InputStream stdin;
2030

2131
public ExecStartCmdImpl(ExecStartCmd.Exec exec, String execId) {

src/main/java/com/github/dockerjava/core/command/ExecStartResultCallback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void onNext(Frame frame) {
3535
try {
3636
switch (frame.getStreamType()) {
3737
case STDOUT:
38+
case RAW:
3839
if (stdout != null) {
3940
stdout.write(frame.getPayload());
4041
stdout.flush();

src/main/java/com/github/dockerjava/jaxrs/ExecStartCmdExec.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.jaxrs;
22

3+
import static javax.ws.rs.client.Entity.entity;
34
import javax.ws.rs.client.WebTarget;
45
import javax.ws.rs.core.MediaType;
56

@@ -30,6 +31,6 @@ protected AbstractCallbackNotifier<Frame> callbackNotifier(ExecStartCmd command,
3031
LOGGER.trace("POST: {}", webTarget);
3132

3233
return new POSTCallbackNotifier<Frame>(new FrameStreamProcessor(), resultCallback, webTarget.request().accept(
33-
MediaType.APPLICATION_JSON), null);
34+
MediaType.APPLICATION_JSON), entity(command, MediaType.APPLICATION_JSON));
3435
}
3536
}

src/main/java/com/github/dockerjava/netty/handler/FramedResponseStreamHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.dockerjava.netty.handler;
22

3+
import java.util.Arrays;
4+
35
import io.netty.buffer.ByteBuf;
46
import io.netty.buffer.Unpooled;
57
import io.netty.channel.ChannelHandlerContext;
@@ -74,14 +76,14 @@ private Frame decode() {
7476

7577
headerCnt += headerCount;
7678

77-
if (headerCnt < HEADER_SIZE) {
78-
return null;
79-
}
80-
8179
streamType = streamType(header[0]);
8280

8381
if (streamType.equals(StreamType.RAW)) {
84-
return new Frame(streamType, header);
82+
return new Frame(streamType, Arrays.copyOf(header, headerCount));
83+
}
84+
85+
if (headerCnt < HEADER_SIZE) {
86+
return null;
8587
}
8688
}
8789

src/test/java/com/github/dockerjava/core/command/ExecStartCmdImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void execStart() throws Exception {
5555
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
5656
.withAttachStdout(true).withCmd("touch", "/execStartTest.log").exec();
5757
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(
58-
new ExecStartResultCallback(System.out, System.err));
58+
new ExecStartResultCallback(System.out, System.err)).awaitCompletion();
5959

6060
InputStream response = dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
6161
Boolean bytesAvailable = response.available() > 0;

src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void afterMethod(ITestResult result) {
4646
}
4747

4848
@Test(groups = "ignoreInCircleCi")
49-
public void inspectExec() throws IOException {
49+
public void inspectExec() throws Exception {
5050
String containerName = "generated_" + new SecureRandom().nextInt();
5151

5252
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
@@ -56,34 +56,34 @@ public void inspectExec() throws IOException {
5656

5757
dockerClient.startContainerCmd(container.getId()).exec();
5858

59-
ExecCreateCmdResponse touchFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
60-
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").exec();
61-
LOG.info("Created exec {}", touchFileCmdCreateResponse.toString());
62-
assertThat(touchFileCmdCreateResponse.getId(), not(isEmptyString()));
63-
ExecCreateCmdResponse checkFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
64-
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
65-
LOG.info("Created exec {}", checkFileCmdCreateResponse.toString());
66-
assertThat(checkFileCmdCreateResponse.getId(), not(isEmptyString()));
67-
6859
// Check that file does not exist
69-
dockerClient.execStartCmd(container.getId())
70-
.withExecId(checkFileCmdCreateResponse.getId()).exec(new ExecStartResultCallback(System.out, System.err));
71-
72-
InspectExecResponse first = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
73-
assertThat(first.getExitCode(), is(0));
60+
ExecCreateCmdResponse checkFileExec1 = dockerClient.execCreateCmd(container.getId())
61+
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
62+
LOG.info("Created exec {}", checkFileExec1.toString());
63+
assertThat(checkFileExec1.getId(), not(isEmptyString()));
64+
dockerClient.execStartCmd(checkFileExec1.getId()).exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();
65+
InspectExecResponse first = dockerClient.inspectExecCmd(checkFileExec1.getId()).exec();
66+
assertThat(first.getExitCode(), is(1));
7467

7568
// Create the file
69+
ExecCreateCmdResponse touchFileExec = dockerClient.execCreateCmd(container.getId())
70+
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").exec();
71+
LOG.info("Created exec {}", touchFileExec.toString());
72+
assertThat(touchFileExec.getId(), not(isEmptyString()));
7673
dockerClient.execStartCmd(container.getId())
77-
.withExecId(touchFileCmdCreateResponse.getId()).exec(new ExecStartResultCallback(System.out, System.err));
78-
79-
InspectExecResponse second = dockerClient.inspectExecCmd(touchFileCmdCreateResponse.getId()).exec();
74+
.withExecId(touchFileExec.getId()).exec(new ExecStartResultCallback(System.out, System.err));
75+
InspectExecResponse second = dockerClient.inspectExecCmd(touchFileExec.getId()).exec();
8076
assertThat(second.getExitCode(), is(0));
8177

78+
8279
// Check that file does exist now
80+
ExecCreateCmdResponse checkFileExec2 = dockerClient.execCreateCmd(container.getId())
81+
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
82+
LOG.info("Created exec {}", checkFileExec2.toString());
83+
assertThat(checkFileExec2.getId(), not(isEmptyString()));
8384
dockerClient.execStartCmd(container.getId())
84-
.withExecId(checkFileCmdCreateResponse.getId()).exec(new ExecStartResultCallback(System.out, System.err));
85-
86-
InspectExecResponse third = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
85+
.withExecId(checkFileExec2.getId()).exec(new ExecStartResultCallback(System.out, System.err));
86+
InspectExecResponse third = dockerClient.inspectExecCmd(checkFileExec2.getId()).exec();
8787
assertThat(third.getExitCode(), is(0));
8888

8989
// Get container info and check its roundtrip to ensure the consistency

src/test/java/com/github/dockerjava/netty/exec/ExecStartCmdExecTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public void execStart() throws Exception {
6161
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(
6262
new ExecStartResultCallback(System.out, System.err));
6363

64-
InputStream response = dockerClient.copyFileFromContainerCmd(container.getId(), "/execStartTest.log").exec();
64+
LOG.info("Wait for 5 seconds");
65+
Thread.sleep(5000);
66+
67+
InputStream response = dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
6568

6669
Boolean bytesAvailable = response.available() > 0;
6770
assertTrue(bytesAvailable, "The file was not copied from the container.");
@@ -88,7 +91,7 @@ public void execStartAttached() throws Exception {
8891
dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true)
8992
.exec(new ExecStartResultCallback(System.out, System.err));
9093

91-
InputStream response = dockerClient.copyFileFromContainerCmd(container.getId(), "/execStartTest.log").exec();
94+
InputStream response = dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
9295
Boolean bytesAvailable = response.available() > 0;
9396
assertTrue(bytesAvailable, "The file was not copied from the container.");
9497

src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,48 +48,44 @@ public void afterMethod(ITestResult result) {
4848
}
4949

5050
@Test(groups = "ignoreInCircleCi")
51-
public void inspectExecTest() throws IOException {
51+
public void inspectExec() throws Exception {
5252
String containerName = "generated_" + new SecureRandom().nextInt();
5353

54-
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("top")
54+
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
5555
.withName(containerName).exec();
5656
LOG.info("Created container {}", container.toString());
5757
assertThat(container.getId(), not(isEmptyString()));
5858

5959
dockerClient.startContainerCmd(container.getId()).exec();
6060

61-
ExecCreateCmdResponse touchFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
62-
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").withTty(true).exec();
63-
LOG.info("Created exec {}", touchFileCmdCreateResponse.toString());
64-
assertThat(touchFileCmdCreateResponse.getId(), not(isEmptyString()));
65-
ExecCreateCmdResponse checkFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
66-
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
67-
LOG.info("Created exec {}", checkFileCmdCreateResponse.toString());
68-
assertThat(checkFileCmdCreateResponse.getId(), not(isEmptyString()));
69-
7061
// Check that file does not exist
71-
dockerClient.execStartCmd(container.getId()).withDetach(false).withTty(true)
72-
.withExecId(checkFileCmdCreateResponse.getId())
73-
.exec(new ExecStartResultCallback(System.out, System.err));
74-
75-
InspectExecResponse first = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
76-
assertEquals(first.isRunning(), new Boolean(false));
62+
ExecCreateCmdResponse checkFileExec1 = dockerClient.execCreateCmd(container.getId())
63+
.withAttachStdout(false).withAttachStderr(false).withCmd("test", "-e", "/marker").exec();
64+
LOG.info("Created exec {}", checkFileExec1.toString());
65+
assertThat(checkFileExec1.getId(), not(isEmptyString()));
66+
dockerClient.execStartCmd(checkFileExec1.getId()).exec(new ExecStartResultCallback(System.out, System.err));
67+
InspectExecResponse first = dockerClient.inspectExecCmd(checkFileExec1.getId()).exec();
7768
assertThat(first.getExitCode(), is(1));
7869

7970
// Create the file
80-
dockerClient.execStartCmd(container.getId()).withDetach(false).withTty(true)
81-
.withExecId(touchFileCmdCreateResponse.getId())
82-
.exec(new ExecStartResultCallback(System.out, System.err));
83-
84-
InspectExecResponse second = dockerClient.inspectExecCmd(touchFileCmdCreateResponse.getId()).exec();
85-
assertEquals(first.isRunning(), new Boolean(false));
71+
ExecCreateCmdResponse touchFileExec = dockerClient.execCreateCmd(container.getId())
72+
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").exec();
73+
LOG.info("Created exec {}", touchFileExec.toString());
74+
assertThat(touchFileExec.getId(), not(isEmptyString()));
75+
dockerClient.execStartCmd(container.getId())
76+
.withExecId(touchFileExec.getId()).exec(new ExecStartResultCallback(System.out, System.err));
77+
InspectExecResponse second = dockerClient.inspectExecCmd(touchFileExec.getId()).exec();
8678
assertThat(second.getExitCode(), is(0));
8779

88-
// Check that file does exist now
89-
dockerClient.execStartCmd(container.getId()).withExecId(checkFileCmdCreateResponse.getId())
90-
.exec(new ExecStartResultCallback(System.out, System.err));
9180

92-
InspectExecResponse third = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
81+
// Check that file does exist now
82+
ExecCreateCmdResponse checkFileExec2 = dockerClient.execCreateCmd(container.getId())
83+
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
84+
LOG.info("Created exec {}", checkFileExec2.toString());
85+
assertThat(checkFileExec2.getId(), not(isEmptyString()));
86+
dockerClient.execStartCmd(container.getId())
87+
.withExecId(checkFileExec2.getId()).exec(new ExecStartResultCallback(System.out, System.err));
88+
InspectExecResponse third = dockerClient.inspectExecCmd(checkFileExec2.getId()).exec();
9389
assertThat(third.getExitCode(), is(0));
9490

9591
// Get container info and check its roundtrip to ensure the consistency

0 commit comments

Comments
 (0)
X Tutup