19
19
import org .junit .jupiter .api .Test ;
20
20
import org .slf4j .Logger ;
21
21
import org .slf4j .LoggerFactory ;
22
- import org .testcontainers .containers .TarantoolContainer ;
23
- import org .testcontainers .containers .output .Slf4jLogConsumer ;
24
- import org .testcontainers .junit .jupiter .Container ;
25
22
import org .testcontainers .junit .jupiter .Testcontainers ;
26
23
import org .testcontainers .shaded .com .fasterxml .jackson .databind .util .ClassUtil ;
27
24
45
42
* @author Artyom Dubinin
46
43
*/
47
44
@ Testcontainers
48
- public class ConnectionIT {
45
+ public class ConnectionIT extends SharedTarantoolContainer {
49
46
private static final String TEST_SPACE_NAME = "test_space" ;
50
47
private static final String GUEST_USER = "guest" ;
51
48
private static final String EXISTING_USER_WITHOUT_PASSWORD = "empty_password_user" ;
52
49
private static final Logger log = LoggerFactory .getLogger (ConnectionIT .class );
53
50
54
- @ Container
55
- private static final TarantoolContainer tarantoolContainer = new TarantoolContainer ()
56
- .withScriptFileName ("org/testcontainers/containers/server.lua" )
57
- .withLogConsumer (new Slf4jLogConsumer (log ));
58
-
59
51
@ Test
60
52
public void connectAndCheckMetadata () throws Exception {
61
53
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
62
- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
54
+ container .getUsername (), container .getPassword ());
63
55
64
56
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
65
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
57
+ container .getHost (), container .getPort ());
66
58
67
59
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
68
60
ExecutorService executor = Executors .newFixedThreadPool (10 );
@@ -86,10 +78,10 @@ public void connectAndCheckMetadata() throws Exception {
86
78
87
79
private CompletableFuture <List <?>> connectAndEval (String command ) throws Exception {
88
80
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
89
- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
81
+ container .getUsername (), container .getPassword ());
90
82
91
83
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
92
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
84
+ container .getHost (), container .getPort ());
93
85
94
86
ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
95
87
CompletableFuture <List <?>> future = client .eval (command );
@@ -119,7 +111,7 @@ public void testGuestExplicit() throws Exception {
119
111
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
120
112
GUEST_USER , "" );
121
113
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
122
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
114
+ container .getHost (), container .getPort ());
123
115
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
124
116
List <?> resultList = client .eval ("return box.session.user()" ).get ();
125
117
String sessionUser = (String ) resultList .get (0 );
@@ -133,7 +125,7 @@ public void testGuestExplicitWithPassword_shouldThrowException() throws Exceptio
133
125
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
134
126
GUEST_USER , "abcd" );
135
127
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
136
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
128
+ container .getHost (), container .getPort ());
137
129
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
138
130
ExecutionException e = assertThrows (ExecutionException .class , () -> {
139
131
client .eval ("return box.session.user()" ).get ();
@@ -152,7 +144,7 @@ public void testGuestImplicit() throws Exception {
152
144
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
153
145
"" , "" );
154
146
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
155
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
147
+ container .getHost (), container .getPort ());
156
148
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
157
149
List <?> resultList = client .eval ("return box.session.user()" ).get ();
158
150
String sessionUser = (String ) resultList .get (0 );
@@ -166,7 +158,7 @@ public void testGuestImplicitWithPassword_shouldThrowException() throws Exceptio
166
158
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
167
159
"" , "abcd" );
168
160
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
169
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
161
+ container .getHost (), container .getPort ());
170
162
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
171
163
ExecutionException e = assertThrows (ExecutionException .class , () -> {
172
164
List <?> resultList = client .eval ("return box.session.user()" ).get ();
@@ -185,7 +177,7 @@ public void testExistingUserWithoutPassword() throws Exception {
185
177
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
186
178
EXISTING_USER_WITHOUT_PASSWORD , "" );
187
179
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
188
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
180
+ container .getHost (), container .getPort ());
189
181
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
190
182
List <?> resultList = client .eval ("return box.session.user()" ).get ();
191
183
String sessionUser = (String ) resultList .get (0 );
@@ -198,7 +190,7 @@ public void testRandomNameUserWithoutPassword_shouldThrowException() throws Exce
198
190
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
199
191
"RandomUserName" , "" );
200
192
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
201
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
193
+ container .getHost (), container .getPort ());
202
194
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
203
195
ExecutionException e = assertThrows (ExecutionException .class , () -> {
204
196
client .eval ("return box.session.user()" ).get ();
@@ -213,9 +205,9 @@ public void testRandomNameUserWithoutPassword_shouldThrowException() throws Exce
213
205
public void testIncorrectHostname_shouldThrowException () {
214
206
assertThrows (TarantoolClientException .class , () -> {
215
207
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
216
- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
208
+ container .getUsername (), container .getPassword ());
217
209
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
218
- "wronghost" , tarantoolContainer .getPort ());
210
+ "wronghost" , container .getPort ());
219
211
ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
220
212
// Connection is actually performed here
221
213
client .getVersion ();
@@ -226,9 +218,9 @@ public void testIncorrectHostname_shouldThrowException() {
226
218
public void testIncorrectPort_shouldThrowException () {
227
219
assertThrows (TarantoolClientException .class , () -> {
228
220
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
229
- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
221
+ container .getUsername (), container .getPassword ());
230
222
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
231
- tarantoolContainer .getHost (), 9999 );
223
+ container .getHost (), 9999 );
232
224
ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
233
225
// Connection is actually performed here
234
226
client .getVersion ();
@@ -238,9 +230,9 @@ public void testIncorrectPort_shouldThrowException() {
238
230
@ Test
239
231
public void testCloseAfterIncorrectPort_shouldThrowException () {
240
232
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
241
- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
233
+ container .getUsername (), container .getPassword ());
242
234
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
243
- tarantoolContainer .getHost (), 9999 );
235
+ container .getHost (), 9999 );
244
236
assertThrows (TarantoolClientException .class , () -> {
245
237
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
246
238
// Connection is actually performed here
@@ -252,9 +244,9 @@ public void testCloseAfterIncorrectPort_shouldThrowException() {
252
244
@ Test
253
245
public void testCloseAfterIncorrectPassword_shouldThrowException () {
254
246
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
255
- tarantoolContainer .getUsername (), "incorrect" );
247
+ container .getUsername (), "incorrect" );
256
248
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
257
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
249
+ container .getHost (), container .getPort ());
258
250
assertThrows (TarantoolClientException .class , () -> {
259
251
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
260
252
// Connection is actually performed here
@@ -266,9 +258,9 @@ public void testCloseAfterIncorrectPassword_shouldThrowException() {
266
258
@ Test
267
259
public void testIncorrectPassword_secondRequestShouldNotHang () {
268
260
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
269
- tarantoolContainer .getUsername (), "incorrect" );
261
+ container .getUsername (), "incorrect" );
270
262
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
271
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
263
+ container .getHost (), container .getPort ());
272
264
assertThrows (TarantoolClientException .class , () -> {
273
265
try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
274
266
// Connection is actually performed here
@@ -286,9 +278,9 @@ public void testIncorrectPassword_secondRequestShouldNotHang() {
286
278
@ Test
287
279
public void testIncorrectPassword_multipleRequestsShouldNotHang () {
288
280
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
289
- tarantoolContainer .getUsername (), "incorrect" );
281
+ container .getUsername (), "incorrect" );
290
282
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
291
- "neverwhere" , tarantoolContainer .getPort ());
283
+ "neverwhere" , container .getPort ());
292
284
TarantoolClientConfig config = TarantoolClientConfig .builder ()
293
285
.withConnectTimeout (100 )
294
286
.withRequestTimeout (100 )
@@ -322,10 +314,10 @@ public void testIncorrectPassword_multipleRequestsShouldNotHang() {
322
314
@ Test
323
315
public void testClientClosing_clientWithoutConnectionsShouldNotHang () throws Exception {
324
316
TarantoolCredentials credentials = new SimpleTarantoolCredentials (
325
- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
317
+ container .getUsername (), container .getPassword ());
326
318
327
319
TarantoolServerAddress serverAddress = new TarantoolServerAddress (
328
- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
320
+ container .getHost (), container .getPort ());
329
321
330
322
ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
331
323
client .close ();
0 commit comments