-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarantoolDBClusterConnectionAbstractExample.java
More file actions
80 lines (59 loc) · 2.54 KB
/
TarantoolDBClusterConnectionAbstractExample.java
File metadata and controls
80 lines (59 loc) · 2.54 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
/*
* Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY
* All Rights Reserved.
*/
package client;
// --8<-- [start:all]
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.tarantool.TarantoolContainer;
import org.testcontainers.containers.tarantool.config.ConfigurationUtils;
import org.testcontainers.containers.tdb.TDB2ClusterImpl;
import org.testcontainers.containers.tdb.TDBCluster;
import io.tarantool.autogen.Tarantool3Configuration;
import io.tarantool.autogen.credentials.users.usersProperty.UsersProperty;
public abstract class TarantoolDBClusterConnectionAbstractExample {
private static final List<String> ROLES = List.of("super");
protected static final String TARANTOOL_DB_IMAGE =
System.getenv().getOrDefault("TARANTOOL_REGISTRY", "") + "tarantooldb:2.2.1";
protected static final String SELLER_USER = "seller-user";
protected static final String SELLER_USER_PWD = "pwd-1";
protected static final String USER_1182 = "user-1182";
protected static final String USER_1182_PWD = "pwd-2";
protected static final String FIRST_ROUTER_CONTAINER_NAME = "router-1";
protected static final String SECOND_ROUTER_CONTAINER_NAME = "router-2";
protected static TDBCluster CLUSTER;
protected abstract void simpleCrudConnection();
@BeforeAll
static void beforeAll() {
CLUSTER = createTDBCluster();
CLUSTER.start();
}
@AfterAll
static void afterAll() {
CLUSTER.close();
}
@SuppressWarnings("unchecked")
private static TDBCluster createTDBCluster() {
// Adds custom users to emulate documentation example
Map<String, UsersProperty> users =
Map.of(
SELLER_USER,
UsersProperty.builder().withPassword(SELLER_USER_PWD).withRoles(ROLES).build(),
USER_1182,
UsersProperty.builder().withPassword(USER_1182_PWD).withRoles(ROLES).build());
final Tarantool3Configuration commonConfigWithoutCustomUsers =
ConfigurationUtils.generateSimpleConfiguration(2, 3, 2);
final Tarantool3Configuration config =
ConfigurationUtils.addUsers(commonConfigWithoutCustomUsers, users);
return TDB2ClusterImpl.builder(TARANTOOL_DB_IMAGE).withTDB2Configuration(config).build();
}
protected static InetSocketAddress getRouterAddress(String routerName) {
final Map<String, TarantoolContainer<?>> routers = CLUSTER.routers();
return routers.get(routerName).mappedAddress();
}
}
// --8<-- [end:all]