1919import org .junit .jupiter .api .Test ;
2020import org .slf4j .Logger ;
2121import org .slf4j .LoggerFactory ;
22- import org .testcontainers .containers .TarantoolContainer ;
23- import org .testcontainers .containers .output .Slf4jLogConsumer ;
24- import org .testcontainers .junit .jupiter .Container ;
2522import org .testcontainers .junit .jupiter .Testcontainers ;
2623import org .testcontainers .shaded .com .fasterxml .jackson .databind .util .ClassUtil ;
2724
4542 * @author Artyom Dubinin
4643 */
4744@ Testcontainers
48- public class ConnectionIT {
45+ public class ConnectionIT extends SharedTarantoolContainer {
4946 private static final String TEST_SPACE_NAME = "test_space" ;
5047 private static final String GUEST_USER = "guest" ;
5148 private static final String EXISTING_USER_WITHOUT_PASSWORD = "empty_password_user" ;
5249 private static final Logger log = LoggerFactory .getLogger (ConnectionIT .class );
5350
54- @ Container
55- private static final TarantoolContainer tarantoolContainer = new TarantoolContainer ()
56- .withScriptFileName ("org/testcontainers/containers/server.lua" )
57- .withLogConsumer (new Slf4jLogConsumer (log ));
58-
5951 @ Test
6052 public void connectAndCheckMetadata () throws Exception {
6153 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
62- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
54+ container .getUsername (), container .getPassword ());
6355
6456 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
65- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
57+ container .getHost (), container .getPort ());
6658
6759 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
6860 ExecutorService executor = Executors .newFixedThreadPool (10 );
@@ -86,10 +78,10 @@ public void connectAndCheckMetadata() throws Exception {
8678
8779 private CompletableFuture <List <?>> connectAndEval (String command ) throws Exception {
8880 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
89- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
81+ container .getUsername (), container .getPassword ());
9082
9183 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
92- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
84+ container .getHost (), container .getPort ());
9385
9486 ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
9587 CompletableFuture <List <?>> future = client .eval (command );
@@ -119,7 +111,7 @@ public void testGuestExplicit() throws Exception {
119111 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
120112 GUEST_USER , "" );
121113 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
122- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
114+ container .getHost (), container .getPort ());
123115 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
124116 List <?> resultList = client .eval ("return box.session.user()" ).get ();
125117 String sessionUser = (String ) resultList .get (0 );
@@ -133,7 +125,7 @@ public void testGuestExplicitWithPassword_shouldThrowException() throws Exceptio
133125 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
134126 GUEST_USER , "abcd" );
135127 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
136- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
128+ container .getHost (), container .getPort ());
137129 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
138130 ExecutionException e = assertThrows (ExecutionException .class , () -> {
139131 client .eval ("return box.session.user()" ).get ();
@@ -152,7 +144,7 @@ public void testGuestImplicit() throws Exception {
152144 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
153145 "" , "" );
154146 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
155- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
147+ container .getHost (), container .getPort ());
156148 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
157149 List <?> resultList = client .eval ("return box.session.user()" ).get ();
158150 String sessionUser = (String ) resultList .get (0 );
@@ -166,7 +158,7 @@ public void testGuestImplicitWithPassword_shouldThrowException() throws Exceptio
166158 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
167159 "" , "abcd" );
168160 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
169- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
161+ container .getHost (), container .getPort ());
170162 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
171163 ExecutionException e = assertThrows (ExecutionException .class , () -> {
172164 List <?> resultList = client .eval ("return box.session.user()" ).get ();
@@ -185,7 +177,7 @@ public void testExistingUserWithoutPassword() throws Exception {
185177 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
186178 EXISTING_USER_WITHOUT_PASSWORD , "" );
187179 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
188- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
180+ container .getHost (), container .getPort ());
189181 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
190182 List <?> resultList = client .eval ("return box.session.user()" ).get ();
191183 String sessionUser = (String ) resultList .get (0 );
@@ -198,7 +190,7 @@ public void testRandomNameUserWithoutPassword_shouldThrowException() throws Exce
198190 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
199191 "RandomUserName" , "" );
200192 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
201- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
193+ container .getHost (), container .getPort ());
202194 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
203195 ExecutionException e = assertThrows (ExecutionException .class , () -> {
204196 client .eval ("return box.session.user()" ).get ();
@@ -213,9 +205,9 @@ public void testRandomNameUserWithoutPassword_shouldThrowException() throws Exce
213205 public void testIncorrectHostname_shouldThrowException () {
214206 assertThrows (TarantoolClientException .class , () -> {
215207 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
216- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
208+ container .getUsername (), container .getPassword ());
217209 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
218- "wronghost" , tarantoolContainer .getPort ());
210+ "wronghost" , container .getPort ());
219211 ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
220212 // Connection is actually performed here
221213 client .getVersion ();
@@ -226,9 +218,9 @@ public void testIncorrectHostname_shouldThrowException() {
226218 public void testIncorrectPort_shouldThrowException () {
227219 assertThrows (TarantoolClientException .class , () -> {
228220 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
229- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
221+ container .getUsername (), container .getPassword ());
230222 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
231- tarantoolContainer .getHost (), 9999 );
223+ container .getHost (), 9999 );
232224 ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
233225 // Connection is actually performed here
234226 client .getVersion ();
@@ -238,9 +230,9 @@ public void testIncorrectPort_shouldThrowException() {
238230 @ Test
239231 public void testCloseAfterIncorrectPort_shouldThrowException () {
240232 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
241- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
233+ container .getUsername (), container .getPassword ());
242234 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
243- tarantoolContainer .getHost (), 9999 );
235+ container .getHost (), 9999 );
244236 assertThrows (TarantoolClientException .class , () -> {
245237 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
246238 // Connection is actually performed here
@@ -252,9 +244,9 @@ public void testCloseAfterIncorrectPort_shouldThrowException() {
252244 @ Test
253245 public void testCloseAfterIncorrectPassword_shouldThrowException () {
254246 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
255- tarantoolContainer .getUsername (), "incorrect" );
247+ container .getUsername (), "incorrect" );
256248 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
257- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
249+ container .getHost (), container .getPort ());
258250 assertThrows (TarantoolClientException .class , () -> {
259251 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
260252 // Connection is actually performed here
@@ -266,9 +258,9 @@ public void testCloseAfterIncorrectPassword_shouldThrowException() {
266258 @ Test
267259 public void testIncorrectPassword_secondRequestShouldNotHang () {
268260 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
269- tarantoolContainer .getUsername (), "incorrect" );
261+ container .getUsername (), "incorrect" );
270262 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
271- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
263+ container .getHost (), container .getPort ());
272264 assertThrows (TarantoolClientException .class , () -> {
273265 try (ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress )) {
274266 // Connection is actually performed here
@@ -286,9 +278,9 @@ public void testIncorrectPassword_secondRequestShouldNotHang() {
286278 @ Test
287279 public void testIncorrectPassword_multipleRequestsShouldNotHang () {
288280 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
289- tarantoolContainer .getUsername (), "incorrect" );
281+ container .getUsername (), "incorrect" );
290282 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
291- "neverwhere" , tarantoolContainer .getPort ());
283+ "neverwhere" , container .getPort ());
292284 TarantoolClientConfig config = TarantoolClientConfig .builder ()
293285 .withConnectTimeout (100 )
294286 .withRequestTimeout (100 )
@@ -322,10 +314,10 @@ public void testIncorrectPassword_multipleRequestsShouldNotHang() {
322314 @ Test
323315 public void testClientClosing_clientWithoutConnectionsShouldNotHang () throws Exception {
324316 TarantoolCredentials credentials = new SimpleTarantoolCredentials (
325- tarantoolContainer .getUsername (), tarantoolContainer .getPassword ());
317+ container .getUsername (), container .getPassword ());
326318
327319 TarantoolServerAddress serverAddress = new TarantoolServerAddress (
328- tarantoolContainer .getHost (), tarantoolContainer .getPort ());
320+ container .getHost (), container .getPort ());
329321
330322 ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient (credentials , serverAddress );
331323 client .close ();
0 commit comments