1
1
package org .testcontainers .containers ;
2
2
3
- import com .github .dockerjava .api .command .ExecCreateCmdResponse ;
4
3
import com .github .dockerjava .api .command .InspectContainerResponse ;
5
4
import lombok .SneakyThrows ;
6
5
import org .testcontainers .images .builder .Transferable ;
7
6
import org .testcontainers .utility .DockerImageName ;
8
7
import org .testcontainers .utility .TestcontainersConfiguration ;
9
8
10
9
import java .nio .charset .StandardCharsets ;
11
- import java .util .concurrent .TimeUnit ;
12
10
import java .util .stream .Collectors ;
13
11
import java .util .stream .Stream ;
14
12
@@ -108,14 +106,18 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
108
106
return ;
109
107
}
110
108
109
+ String command = "#!/bin/bash\n " ;
111
110
final String zookeeperConnect ;
112
111
if (externalZookeeperConnect != null ) {
113
112
zookeeperConnect = externalZookeeperConnect ;
114
113
} else {
115
- zookeeperConnect = startZookeeper ();
114
+ zookeeperConnect = "localhost:" + ZOOKEEPER_PORT ;
115
+ command += "echo 'clientPort=" + ZOOKEEPER_PORT + "' > zookeeper.properties\n " ;
116
+ command += "echo 'dataDir=/var/lib/zookeeper/data' >> zookeeper.properties\n " ;
117
+ command += "echo 'dataLogDir=/var/lib/zookeeper/log' >> zookeeper.properties\n " ;
118
+ command += "zookeeper-server-start zookeeper.properties &\n " ;
116
119
}
117
120
118
- String command = "#!/bin/bash \n " ;
119
121
command += "export KAFKA_ZOOKEEPER_CONNECT='" + zookeeperConnect + "'\n " ;
120
122
command += "export KAFKA_ADVERTISED_LISTENERS='" + Stream
121
123
.concat (
@@ -130,22 +132,8 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
130
132
command += "/etc/confluent/docker/launch \n " ;
131
133
132
134
copyFileToContainer (
133
- Transferable .of (command .getBytes (StandardCharsets .UTF_8 ), 700 ),
135
+ Transferable .of (command .getBytes (StandardCharsets .UTF_8 ), 0777 ),
134
136
STARTER_SCRIPT
135
137
);
136
138
}
137
-
138
- @ SneakyThrows (InterruptedException .class )
139
- private String startZookeeper () {
140
- ExecCreateCmdResponse execCreateCmdResponse = dockerClient .execCreateCmd (getContainerId ())
141
- .withCmd ("sh" , "-c" , "" +
142
- "printf 'clientPort=" + ZOOKEEPER_PORT + "\n dataDir=/var/lib/zookeeper/data\n dataLogDir=/var/lib/zookeeper/log' > /zookeeper.properties\n " +
143
- "zookeeper-server-start /zookeeper.properties\n "
144
- )
145
- .exec ();
146
-
147
- dockerClient .execStartCmd (execCreateCmdResponse .getId ()).start ().awaitStarted (10 , TimeUnit .SECONDS );
148
-
149
- return "localhost:" + ZOOKEEPER_PORT ;
150
- }
151
139
}
0 commit comments