-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTarantoolCartridgeBootstrapFromLuaWithFixedPortsIT.java
More file actions
140 lines (126 loc) · 6.55 KB
/
TarantoolCartridgeBootstrapFromLuaWithFixedPortsIT.java
File metadata and controls
140 lines (126 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package org.testcontainers.containers;
import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.RetryCountExceededException;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Container.ExecResult;
import org.testcontainers.containers.exceptions.CartridgeTopologyException;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Alexey Kuzin
*/
@Testcontainers
public class TarantoolCartridgeBootstrapFromLuaWithFixedPortsIT {
@Container
private static final TarantoolCartridgeContainer container =
new TarantoolCartridgeContainer(
"Dockerfile",
System.getenv().getOrDefault("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "") + "cartridge",
"cartridge/instances_fixedport.yml",
"cartridge/topology_fixedport.lua")
.withEnv("TARANTOOL_INSTANCES_FILE", "instances_fixedport.yml")
.withStartupTimeout(Duration.ofMinutes(5))
.withUseFixedPorts(true)
.withAPIPort(18081)
.withRouterPort(13301)
.withLogConsumer(new Slf4jLogConsumer(
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromLuaWithFixedPortsIT.class)));
@Test
public void test_StaticClusterContainer_StartsSuccessfully_ifFilesAreCopied() throws Exception {
CartridgeContainerTestUtils.executeProfileReplaceSmokeTest(container);
}
@Test
public void testTarantoolClusterCookieDefault() throws Exception {
Map<String, String> env = container.getEnvMap();
assertFalse(env.containsKey(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE));
List<Object> result = container.executeCommandDecoded("return true");
assertEquals(1, result.size());
assertTrue((boolean) result.get(0));
}
@Test
public void testTarantoolClusterCookieWithEnv() throws Exception {
try(TarantoolCartridgeContainer newContainer = new TarantoolCartridgeContainer(
"Dockerfile",
System.getenv().getOrDefault("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "") + "cartridge",
"cartridge/instances.yml",
"cartridge/replicasets.yml")
.withEnv(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE, "secret")
.withRouterUsername("admin")
.withRouterPassword("secret")
.withStartupTimeout(Duration.ofMinutes(5))
.withLogConsumer(new Slf4jLogConsumer(
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromYamlIT.class))))
{
newContainer.start();
ExecResult res = newContainer.execInContainer("env");
assertTrue(CartridgeContainerTestUtils.isEnvInStdout(res.getStdout(),
new HashMap<String, String>(){{
put("TARANTOOL_CLUSTER_COOKIE", "secret");
}}));
List<Object> result = newContainer.executeCommandDecoded("return true");
assertEquals(1, result.size());
assertTrue((boolean) result.get(0));
}
}
@Test
public void test_retryingSetupTopology_shouldWork() {
try (TarantoolCartridgeContainer testContainer =
new TarantoolCartridgeContainer(
"Dockerfile",
System.getenv().getOrDefault("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "") + "cartridge",
"cartridge/instances.yml",
"cartridge/incorrect_topology.lua")
.withLogConsumer(new Slf4jLogConsumer(
LoggerFactory.getLogger(
TarantoolCartridgeBootstrapFromLuaWithFixedPortsIT.class)))
.withStartupTimeout(Duration.ofMinutes(5))) {
ContainerLaunchException ex = assertThrows(ContainerLaunchException.class, testContainer::start);
Throwable cause = ex.getCause();
assertEquals(RetryCountExceededException.class, cause.getClass());
cause = cause.getCause();
assertEquals(ContainerLaunchException.class, cause.getClass());
cause = cause.getCause();
assertEquals(CartridgeTopologyException.class, cause.getClass());
assertEquals("Failed to change the app topology after retry", cause.getMessage());
}
}
@Test
public void testBuildArgs() throws Exception {
final Map<String, String> buildArgs = new HashMap<String, String>(){{
put("CARTRIDGE_SRC_DIR", "cartridge");
put("TARANTOOL_WORKDIR", "/app");
put("TARANTOOL_RUNDIR", "/tmp/new_run");
put("TARANTOOL_DATADIR", "/tmp/new_data");
put("TARANTOOL_LOGDIR", "/tmp/log");
put("TARANTOOL_INSTANCES_FILE", "./instances.yml");
put("START_DELAY", "1s");
}};
try(TarantoolCartridgeContainer newContainer = new TarantoolCartridgeContainer(
"Dockerfile",
System.getenv().getOrDefault("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "") + "build_args_test",
"cartridge/instances.yml",
"cartridge/replicasets.yml",
buildArgs)
.withStartupTimeout(Duration.ofMinutes(5))
.withLogConsumer(new Slf4jLogConsumer(
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromYamlIT.class)))
) {
newContainer.start();
ExecResult res = newContainer.execInContainer("env");
buildArgs.remove("CARTRIDGE_SRC_DIR", "cartridge");
assertTrue(CartridgeContainerTestUtils.isEnvInStdout(res.getStdout(), buildArgs));
List<Object> result = newContainer.executeCommandDecoded("return true");
assertEquals(1, result.size());
assertTrue((boolean) result.get(0));
}
}
}