X Tutup
Skip to content

Commit ccbad49

Browse files
committed
Test that exec finishes
1 parent d242f5c commit ccbad49

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public RC_T awaitCompletion() throws InterruptedException {
9595

9696
/**
9797
* Blocks until {@link ResultCallback#onComplete()} was called or the given timeout occurs
98+
* @return {@code true} if completed and {@code false} if the waiting time elapsed
99+
* before {@link ResultCallback#onComplete()} was called.
98100
*/
99-
@SuppressWarnings("unchecked")
100-
public RC_T awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException {
101-
completed.await(timeout, timeUnit);
102-
return (RC_T) this;
101+
public boolean awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException {
102+
return completed.await(timeout, timeUnit);
103103
}
104104

105105
/**
@@ -115,11 +115,11 @@ public RC_T awaitStarted() throws InterruptedException {
115115
/**
116116
* Blocks until {@link ResultCallback#onStart()} was called or the given timeout occurs. {@link ResultCallback#onStart()} is called when
117117
* the request was processed on the server side and the response is incoming.
118+
* @return {@code true} if started and {@code false} if the waiting time elapsed
119+
* before {@link ResultCallback#onStart()} was called.
118120
*/
119-
@SuppressWarnings("unchecked")
120-
public RC_T awaitStarted(long timeout, TimeUnit timeUnit) throws InterruptedException {
121-
started.await(timeout, timeUnit);
122-
return (RC_T) this;
121+
public boolean awaitStarted(long timeout, TimeUnit timeUnit) throws InterruptedException {
122+
return started.await(timeout, timeUnit);
123123
}
124124

125125
@CheckForNull

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public void onNext(Frame frame) {
6868
};
6969

7070
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
71-
.withLogs(true).exec(callback).awaitCompletion(30, TimeUnit.SECONDS).close();
71+
.withLogs(true).exec(callback).awaitCompletion(30, TimeUnit.SECONDS);
72+
callback.close();
7273

7374
assertThat(callback.toString(), containsString(snippet));
7475
}
@@ -97,7 +98,8 @@ public void onNext(Frame frame) {
9798
};
9899

99100
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
100-
.exec(callback).awaitCompletion(15, TimeUnit.SECONDS).close();
101+
.exec(callback).awaitCompletion(15, TimeUnit.SECONDS);
102+
callback.close();
101103

102104
System.out.println("log: " + callback.toString());
103105

@@ -130,7 +132,8 @@ public void onNext(Frame frame) {
130132
InputStream stdin = new ByteArrayInputStream("".getBytes());
131133

132134
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
133-
.withLogs(true).withStdIn(stdin).exec(callback).awaitCompletion(30, TimeUnit.SECONDS).close();
135+
.withLogs(true).withStdIn(stdin).exec(callback).awaitCompletion(30, TimeUnit.SECONDS);
136+
callback.close();
134137
}
135138

136139
public static class AttachContainerTestCallback extends AttachContainerResultCallback {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public void onNext(Frame frame) {
7070
};
7171

7272
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
73-
.withLogs(true).exec(callback).awaitCompletion(10, TimeUnit.SECONDS).close();
73+
.withLogs(true).exec(callback).awaitCompletion(10, TimeUnit.SECONDS);
74+
callback.close();
7475

7576
assertThat(callback.toString(), containsString(snippet));
7677
}
@@ -104,7 +105,8 @@ public void onNext(Frame frame) {
104105
InputStream stdin = new ByteArrayInputStream((snippet + "\n").getBytes());
105106

106107
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
107-
.withStdIn(stdin).exec(callback).awaitCompletion(2, TimeUnit.SECONDS).close();
108+
.withStdIn(stdin).exec(callback).awaitCompletion(2, TimeUnit.SECONDS);
109+
callback.close();
108110

109111
assertThat(callback.toString(), containsString(snippet));
110112
}
@@ -133,7 +135,8 @@ public void onNext(Frame frame) {
133135
};
134136

135137
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
136-
.exec(callback).awaitCompletion(10, TimeUnit.SECONDS).close();
138+
.exec(callback).awaitCompletion(10, TimeUnit.SECONDS);
139+
callback.close();
137140

138141
// HexDump.dump(collectFramesCallback.toString().getBytes(), 0, System.out, 0);
139142

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ public void execStartAttachStdin() throws Exception {
115115

116116
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
117117
.withAttachStdout(true).withAttachStdin(true).withCmd("cat").exec();
118-
dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true).withStdIn(stdin)
118+
boolean completed = dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true).withStdIn(stdin)
119119
.exec(new ExecStartResultCallback(stdout, System.err)).awaitCompletion(5, TimeUnit.SECONDS);
120120

121+
assertTrue(completed, "The process was not finished.");
121122
assertEquals(stdout.toString("UTF-8"), "STDIN\n");
122123
}
123124

@@ -138,9 +139,10 @@ public void execStartNotAttachedStdin() throws Exception {
138139

139140
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
140141
.withAttachStdout(true).withAttachStdin(false).withCmd("/bin/sh").exec();
141-
dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withStdIn(stdin)
142+
boolean completed = dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withStdIn(stdin)
142143
.exec(new ExecStartResultCallback(stdout, System.err)).awaitCompletion(5, TimeUnit.SECONDS);
143144

145+
assertTrue(completed, "The process was not finished.");
144146
assertEquals(stdout.toString(), "");
145147
}
146148
}

0 commit comments

Comments
 (0)
X Tutup