Skip to content

Commit 355d1e9

Browse files
committed
Fix after review
Closes #12
1 parent 8eb53c4 commit 355d1e9

File tree

3 files changed

+17
-161
lines changed

3 files changed

+17
-161
lines changed

README.md

Lines changed: 14 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public class SomeOtherTest {
167167
private static final TarantoolCartridgeContainer container =
168168
// Pass the classpath-relative paths of the instances configuration and topology script files
169169
new TarantoolCartridgeContainer("cartridge/instances.yml", "cartridge/topology.lua")
170-
// Optional, "localhost" is default
170+
// Tarantool URI, optional. Default is "localhost"
171171
.withRouterHost("localhost")
172-
// Binary port, optional, 3301 is default
172+
// Binary port, optional. Default is 3301
173173
.withRouterPort(3301)
174174
// Cartridge HTTP API port, optional, 8081 is default
175175
.withAPIPort(8801)
@@ -201,180 +201,36 @@ public class SomeOtherTest {
201201
###### Build arguments:
202202

203203
This section describes the Docker image build arguments and environment variables inside the container. It is worth
204-
noting that all build arguments listed here are passed into environment variables of the same name. At the moment,
205-
the following arguments are available to build the image:
204+
nothing that almost all build arguments listed here are passed into environment variables of the same name. At the
205+
moment, the following arguments are available to build the image:
206206

207207
- `CARTRIDGE_SRC_DIR` - directory on the host machine that contains all the .lua scripts needed to initialize and run
208-
cartridge. Defaults to `cartridge`. Does not convert to an environment variable.
209-
- `TARANTOOL_WORKDIR` - a directory where all data will be stored: snapshots, wal logs and cartridge config file.
210-
Defaults to `/app`. Converts to an environment variable. It is not recommended to override via the `withEnv(...)` method.
211-
- `TARANTOOL_RUNDIR` - a directory where PID and socket files are stored. Defaults to `/tmp/run`. Converts to an
208+
cartridge. Defaults is `cartridge`. **Only as a build argument.**
209+
- `TARANTOOL_WORKDIR` - a directory where all data will be stored: snapshots, wal logs and cartridge config files.
210+
Defaults is `/app`. Converts to an environment variable. It is not recommended to override via the `withEnv(...)` method.
211+
- `TARANTOOL_RUNDIR` - a directory where PID and socket files are stored. Defaults is `/tmp/run`. Converts to an
212212
environment variable. It is not recommended to override via the `withEnv(...)` method.
213-
- `TARANTOOL_DATADIR` - a directory containing the instances working directories. Defaults to `/tmp/data`. Converts to
213+
- `TARANTOOL_DATADIR` - a directory containing the instances working directories. Defaults is `/tmp/data`. Converts to
214214
an environment variable. It is not recommended to override via the `withEnv(...)` method.
215-
- `TARANTOOL_LOGDIR` - the directory where log files are stored. Defaults to `/tmp/log`. Converts to an environment
215+
- `TARANTOOL_LOGDIR` - the directory where log files are stored. Defaults is `/tmp/log`. Converts to an environment
216216
- variable. It is not recommended to override via the `withEnv(...)` method.
217-
- `TARANTOOL_INSTANCES_FILE` - path to the configuration file. Defaults to `./instances.yml`. Converts to an environment
217+
- `TARANTOOL_INSTANCES_FILE` - path to the configuration file. Defaults is `./instances.yml`. Converts to an environment
218218
variable. It is not recommended to override via the `withEnv(...)` method.
219219
- `START_DELAY` - the time after which cartridge will actually run after the container has started. Converts to an
220220
environment variable. It is not recommended to override via the `withEnv(...)` method.
221221

222222
You can set the Docker image build arguments using a map, which is passed as an input argument to the constructor when
223-
creating a container in Java code:
224-
225-
```java
226-
import java.util.HashMap;
227-
import java.util.Map;
228-
229-
import org.junit.Test;
230-
231-
@Testcontainers
232-
public class BuildArgsTest {
233-
234-
private static final Map<String, String> buildArgs = new HashMap<>() {{
235-
// Set src directory
236-
put("CARTRIDGE_SRC_DIR", "cartridge");
237-
238-
// Set Tarantool work directory (has an environment variable of the same name)
239-
put("TARANTOOL_WORKDIR", "/app");
240-
241-
// Set Tarantool run directory (has an environment variable of the same name)
242-
put("TARANTOOL_RUNDIR", "/tmp/new_run");
243-
244-
// Set Tarantool data directory (has an environment variable of the same name)
245-
put("TARANTOOL_DATADIR", "/tmp/new_data");
246-
247-
// Set Tarantool log files directory (has an environment variable of the same name)
248-
put("TARANTOOL_LOGDIR", "/tmp/log");
249-
250-
// Path to the configuration file (has an environment variable of the same name)
251-
put("TARANTOOL_INSTANCES_FILE", "./instances.yml");
252-
253-
// Set container start delay (has an environment variable of the same name)
254-
put("START_DELAY", "1s");
255-
}};
256-
257-
258-
@Container
259-
// Create container with build arguments
260-
private static final TarantoolCartridgeContainer newContainer = new TarantoolCartridgeContainer(
261-
"Dockerfile",
262-
"build_args_test",
263-
"cartridge/instances.yml",
264-
"cartridge/replicasets.yml",
265-
buildArgs)
266-
.withStartupTimeout(Duration.ofMinutes(5))
267-
.withLogConsumer(new Slf4jLogConsumer(
268-
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromYamlTest.class)));
269-
270-
271-
@Test
272-
public void testBuildArgs() {
273-
//Start container
274-
newContainer.start();
275-
276-
// Get environment variables from container
277-
ExecResult res = newContainer.execInContainer("env");
278-
279-
// Remove src directory to create expected env map
280-
buildArgs.remove("CARTRIDGE_SRC_DIR", "cartridge");
281-
282-
// Check that environment variables from container contains expected env map
283-
assertTrue(envIsContainsInStdout(res.getStdout(), buildArgs));
284-
285-
// Check cartridge functionality
286-
List<Object> result = newContainer.executeCommandDecoded("return true");
287-
assertEquals(1, result.size());
288-
assertTrue((boolean) result.get(0));
289-
}
290-
291-
public bolean envIsContainsInStdout(String stdout, Map<String, String> env) {
292-
Map<String, String> envMap = Arrays.stream(stdout.split("\n"))
293-
.collect(Collectors.toMap(toKey -> toKey.split("=")[0],
294-
toValue -> {
295-
String[] pair = toValue.split("=");
296-
if (pair.length == 1) {
297-
return "null";
298-
}
299-
return pair[1];
300-
}));
301-
302-
return envMap.entrySet().containsAll(env.entrySet());
303-
}
304-
}
305-
```
223+
creating a container in Java code. See example: [link](https://github.com/tarantool/testcontainers-java-tarantool/blob/8eb53c43e4c00570378de91a1269837448232de8/src/test/java/org/testcontainers/containers/TarantoolCartridgeBootstrapFromLuaWithFixedPortsTest.java#L111-L119).
306224

307225
###### Environment variables:
308226

309227
To set an environment variable, use the `withEnv(...)` method of testcontainers API. Full list of variables the
310-
environments used in cartridge can be found here [link](https://www.tarantool.io/ru/doc/2.11/book/cartridge/cartridge_api/modules/cartridge/).
228+
environments used in cartridge can be found here [link](https://www.tarantool.io/ru/doc/2.11/book/cartridge/cartridge_api/modules/cartridge/#cfg-opts-box-opts).
311229

312230
***Note:*** As shown in the previous section, some build arguments are converted to environment variables and used to
313231
cartridge build at the image build stage.
314232

315-
An example of how to set the `TARANTOOL_CLUSTER_COOKIE` parameter:
316-
317-
```java
318-
import java.util.HashMap;
319-
import java.util.Map;
320-
321-
import org.junit.Test;
322-
323-
@Testcontainers
324-
public class EnvTest {
325-
326-
@Container
327-
// Create container with env
328-
private static final TarantoolCartridgeContainer newContainer = new TarantoolCartridgeContainer(
329-
"Dockerfile",
330-
"cartridge",
331-
"cartridge/instances.yml",
332-
"cartridge/replicasets.yml")
333-
// Set environment
334-
.withEnv(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE, "secret")
335-
.withRouterUsername("admin")
336-
.withRouterPassword("secret")
337-
.withStartupTimeout(Duration.ofMinutes(5))
338-
.withLogConsumer(new Slf4jLogConsumer(
339-
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromYamlTest.class)));
340-
341-
342-
@Test
343-
public void testEnv() {
344-
345-
// Start container
346-
newContainer.start();
347-
348-
// Get environment variables from container
349-
ExecResult res = newContainer.execInContainer("env");
350-
351-
// Check that environment variables from container contains expected env map
352-
assertTrue(envIsContainsInStdout(res.getStdout(), new HashMap<String, String>(){{
353-
put("TARANTOOL_CLUSTER_COOKIE", "secret");
354-
}}));
355-
356-
// Check cartridge functionality
357-
List<Object> result = newContainer.executeCommandDecoded("return true");
358-
assertEquals(1, result.size());
359-
assertTrue((boolean) result.get(0));
360-
}
361-
362-
public bolean envIsContainsInStdout(String stdout, Map<String, String> env) {
363-
Map<String, String> envMap = Arrays.stream(stdout.split("\n"))
364-
.collect(Collectors.toMap(toKey -> toKey.split("=")[0],
365-
toValue -> {
366-
String[] pair = toValue.split("=");
367-
if (pair.length == 1) {
368-
return "null";
369-
}
370-
return pair[1];
371-
}));
372-
373-
return envMap.entrySet().containsAll(env.entrySet());
374-
}
375-
}
376-
377-
```
233+
An example of how to set the `TARANTOOL_CLUSTER_COOKIE` parameter: [link](https://github.com/tarantool/testcontainers-java-tarantool/blob/8eb53c43e4c00570378de91a1269837448232de8/src/test/java/org/testcontainers/containers/TarantoolCartridgeBootstrapFromLuaWithFixedPortsTest.java#L57-L82).
378234

379235
## License
380236

src/test/java/org/testcontainers/containers/CartridgeContainerTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static public void executeProfileReplaceSmokeTest(TarantoolCartridgeContainer co
2525
assertEquals(33, ((List<?>) result.get(0)).get(3));
2626
}
2727

28-
public static boolean envIsContainsInStdout(String stdout, Map<String, String> env) {
28+
public static boolean isEnvInStdout(String stdout, Map<String, String> env) {
2929
Map<String, String> envMap = Arrays.stream(stdout.split("\n"))
3030
.collect(Collectors.toMap(toKey -> toKey.split("=")[0],
3131
toValue -> {

src/test/java/org/testcontainers/containers/TarantoolCartridgeBootstrapFromLuaWithFixedPortsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testTarantoolClusterCookieWithEnv() throws Exception {
7070
{
7171
newContainer.start();
7272
ExecResult res = newContainer.execInContainer("env");
73-
assertTrue(CartridgeContainerTestUtils.envIsContainsInStdout(res.getStdout(),
73+
assertTrue(CartridgeContainerTestUtils.isEnvInStdout(res.getStdout(),
7474
new HashMap<String, String>(){{
7575
put("TARANTOOL_CLUSTER_COOKIE", "secret");
7676
}}));
@@ -131,7 +131,7 @@ public void testBuildArgs() throws Exception {
131131
newContainer.start();
132132
ExecResult res = newContainer.execInContainer("env");
133133
buildArgs.remove("CARTRIDGE_SRC_DIR", "cartridge");
134-
assertTrue(CartridgeContainerTestUtils.envIsContainsInStdout(res.getStdout(), buildArgs));
134+
assertTrue(CartridgeContainerTestUtils.isEnvInStdout(res.getStdout(), buildArgs));
135135

136136
List<Object> result = newContainer.executeCommandDecoded("return true");
137137
assertEquals(1, result.size());

0 commit comments

Comments
 (0)