@@ -63,6 +63,29 @@ static constexpr int kPlainClientTabletPort = 9224;
6363// / Execute a shell command and return its exit code.
6464inline int RunCommand (const std::string& cmd) { return system (cmd.c_str ()); }
6565
66+ // / Join property lines with the escaped newline separator used by `printf` in docker commands.
67+ inline std::string JoinProps (const std::vector<std::string>& lines) {
68+ std::string result;
69+ for (size_t i = 0 ; i < lines.size (); ++i) {
70+ if (i > 0 ) result += " \\ n" ;
71+ result += lines[i];
72+ }
73+ return result;
74+ }
75+
76+ // / Build a `docker run` command with FLUSS_PROPERTIES.
77+ inline std::string DockerRunCmd (const std::string& name, const std::string& props,
78+ const std::vector<std::string>& port_mappings,
79+ const std::string& server_type) {
80+ std::string cmd = " docker run -d --rm --name " + name + " --network " + kNetworkName ;
81+ for (const auto & pm : port_mappings) {
82+ cmd += " -p " + pm;
83+ }
84+ cmd += " -e FLUSS_PROPERTIES=\" $(printf '" + props + " ')\" " ;
85+ cmd += " " + std::string (kFlussImage ) + " :" + kFlussVersion + " " + server_type;
86+ return cmd;
87+ }
88+
6689// / Wait until a TCP port is accepting connections, or timeout.
6790inline bool WaitForPort (const std::string& host, int port, int timeout_seconds = 60 ) {
6891 auto deadline = std::chrono::steady_clock::now () + std::chrono::seconds (timeout_seconds);
@@ -129,28 +152,24 @@ class FlussTestCluster {
129152 std::string sasl_jaas =
130153 " org.apache.fluss.security.auth.sasl.plain.PlainLoginModule required"
131154 " user_admin=\" admin-secret\" user_alice=\" alice-secret\" ;" ;
132- std::string coord_props =
133- " zookeeper.address: " + std::string (kZookeeperName ) +
134- " :2181\\ n"
135- " bind.listeners: INTERNAL://" +
136- std::string (kCoordinatorName ) + " :0, CLIENT://" + std::string (kCoordinatorName ) +
137- " :9123, PLAIN_CLIENT://" + std::string (kCoordinatorName ) +
138- " :9223\\ n"
139- " advertised.listeners: CLIENT://localhost:9123, PLAIN_CLIENT://localhost:9223\\ n"
140- " internal.listener.name: INTERNAL\\ n"
141- " security.protocol.map: CLIENT:sasl\\ n"
142- " security.sasl.enabled.mechanisms: plain\\ n"
143- " security.sasl.plain.jaas.config: " +
144- sasl_jaas +
145- " \\ n"
146- " netty.server.num-network-threads: 1\\ n"
147- " netty.server.num-worker-threads: 3" ;
148-
149- std::string coord_cmd = std::string (" docker run -d --rm" ) + " --name " + kCoordinatorName +
150- " --network " + kNetworkName + " -p 9123:9123" + " -p 9223:9223" +
151- " -e FLUSS_PROPERTIES=\" $(printf '" + coord_props + " ')\" " + " " +
152- std::string (kFlussImage ) + " :" + kFlussVersion +
153- " coordinatorServer" ;
155+
156+ std::string coord = std::string (kCoordinatorName );
157+ std::string zk = std::string (kZookeeperName );
158+ std::string coord_props = JoinProps ({
159+ " zookeeper.address: " + zk + " :2181" ,
160+ " bind.listeners: INTERNAL://" + coord + " :0, CLIENT://" + coord +
161+ " :9123, PLAIN_CLIENT://" + coord + " :9223" ,
162+ " advertised.listeners: CLIENT://localhost:9123, PLAIN_CLIENT://localhost:9223" ,
163+ " internal.listener.name: INTERNAL" ,
164+ " security.protocol.map: CLIENT:sasl" ,
165+ " security.sasl.enabled.mechanisms: plain" ,
166+ " security.sasl.plain.jaas.config: " + sasl_jaas,
167+ " netty.server.num-network-threads: 1" ,
168+ " netty.server.num-worker-threads: 3" ,
169+ });
170+
171+ std::string coord_cmd = DockerRunCmd (kCoordinatorName , coord_props,
172+ {" 9123:9123" , " 9223:9223" }, " coordinatorServer" );
154173 if (RunCommand (coord_cmd) != 0 ) {
155174 std::cerr << " Failed to start Coordinator Server" << std::endl;
156175 Stop ();
@@ -165,33 +184,26 @@ class FlussTestCluster {
165184 }
166185
167186 // Start Tablet Server (dual listeners: CLIENT=SASL on 9123, PLAIN_CLIENT=plaintext on 9223)
168- std::string ts_props =
169- " zookeeper.address: " + std::string (kZookeeperName ) +
170- " :2181\\ n"
171- " bind.listeners: INTERNAL://" +
172- std::string (kTabletServerName ) + " :0, CLIENT://" + std::string (kTabletServerName ) +
173- " :9123, PLAIN_CLIENT://" + std::string (kTabletServerName ) +
174- " :9223\\ n"
175- " advertised.listeners: CLIENT://localhost:" +
176- std::to_string (kTabletServerPort ) +
177- " , PLAIN_CLIENT://localhost:" + std::to_string (kPlainClientTabletPort ) +
178- " \\ n"
179- " internal.listener.name: INTERNAL\\ n"
180- " security.protocol.map: CLIENT:sasl\\ n"
181- " security.sasl.enabled.mechanisms: plain\\ n"
182- " security.sasl.plain.jaas.config: " +
183- sasl_jaas +
184- " \\ n"
185- " tablet-server.id: 0\\ n"
186- " netty.server.num-network-threads: 1\\ n"
187- " netty.server.num-worker-threads: 3" ;
188-
189- std::string ts_cmd = std::string (" docker run -d --rm" ) + " --name " + kTabletServerName +
190- " --network " + kNetworkName + " -p " +
191- std::to_string (kTabletServerPort ) + " :9123" + " -p " +
192- std::to_string (kPlainClientTabletPort ) + " :9223" +
193- " -e FLUSS_PROPERTIES=\" $(printf '" + ts_props + " ')\" " + " " +
194- std::string (kFlussImage ) + " :" + kFlussVersion + " tabletServer" ;
187+ std::string ts = std::string (kTabletServerName );
188+ std::string ts_props = JoinProps ({
189+ " zookeeper.address: " + zk + " :2181" ,
190+ " bind.listeners: INTERNAL://" + ts + " :0, CLIENT://" + ts + " :9123, PLAIN_CLIENT://" +
191+ ts + " :9223" ,
192+ " advertised.listeners: CLIENT://localhost:" + std::to_string (kTabletServerPort ) +
193+ " , PLAIN_CLIENT://localhost:" + std::to_string (kPlainClientTabletPort ),
194+ " internal.listener.name: INTERNAL" ,
195+ " security.protocol.map: CLIENT:sasl" ,
196+ " security.sasl.enabled.mechanisms: plain" ,
197+ " security.sasl.plain.jaas.config: " + sasl_jaas,
198+ " tablet-server.id: 0" ,
199+ " netty.server.num-network-threads: 1" ,
200+ " netty.server.num-worker-threads: 3" ,
201+ });
202+
203+ std::string ts_cmd = DockerRunCmd (kTabletServerName , ts_props,
204+ {std::to_string (kTabletServerPort ) + " :9123" ,
205+ std::to_string (kPlainClientTabletPort ) + " :9223" },
206+ " tabletServer" );
195207 if (RunCommand (ts_cmd) != 0 ) {
196208 std::cerr << " Failed to start Tablet Server" << std::endl;
197209 Stop ();
0 commit comments