-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarantoolSingleInstanceConnectionTJSDKExample.java
More file actions
59 lines (47 loc) · 1.99 KB
/
TarantoolSingleInstanceConnectionTJSDKExample.java
File metadata and controls
59 lines (47 loc) · 1.99 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
/*
* Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY
* All Rights Reserved.
*/
package client;
// --8<-- [start:all]
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import testcontainers.utils.TarantoolSingleNodeConfigUtils;
import io.tarantool.client.box.TarantoolBoxClient;
import io.tarantool.client.factory.TarantoolBoxClientBuilder;
import io.tarantool.client.factory.TarantoolFactory;
import io.tarantool.mapping.TarantoolResponse;
import io.tarantool.pool.InstanceConnectionGroup;
public class TarantoolSingleInstanceConnectionTJSDKExample
extends TarantoolSingleInstanceConnectionAbstractExample {
@Test
protected void simpleConnection() {
// Получаем адрес и порт из докера
// Gets address and port from docker
final InetSocketAddress nodeAddress = CONTAINER.mappedAddress();
// Настраиваем группу подключения
// Set ups connection group
final InstanceConnectionGroup connectionGroup =
InstanceConnectionGroup.builder()
.withHost(nodeAddress.getHostName())
.withPort(nodeAddress.getPort())
.withUser(TarantoolSingleNodeConfigUtils.LOGIN)
.withPassword(TarantoolSingleNodeConfigUtils.PWD.toString())
.build();
final TarantoolBoxClientBuilder clientBuilder =
TarantoolFactory.box().withGroups(Collections.singletonList(connectionGroup));
try (final TarantoolBoxClient singleNodeClient = clientBuilder.build()) {
final TarantoolResponse<List<String>> response =
singleNodeClient.eval("return _TARANTOOL", String.class).join();
final List<String> results = response.get();
Assertions.assertEquals(1, results.size());
Assertions.assertTrue(results.get(0).contains(TARANTOOL_TAG));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
// --8<-- [end:all]