-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarantoolDBClusterConnectionCartridgeDriverExample.java
More file actions
64 lines (51 loc) · 2.15 KB
/
TarantoolDBClusterConnectionCartridgeDriverExample.java
File metadata and controls
64 lines (51 loc) · 2.15 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
/*
* 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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import io.tarantool.driver.api.TarantoolClient;
import io.tarantool.driver.api.TarantoolClientFactory;
import io.tarantool.driver.api.TarantoolResult;
import io.tarantool.driver.api.TarantoolServerAddress;
import io.tarantool.driver.api.tuple.TarantoolTuple;
public class TarantoolDBClusterConnectionCartridgeDriverExample
extends TarantoolDBClusterConnectionAbstractExample {
@Test
@Override
protected void simpleCrudConnection() {
try (TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> crudClient =
setupClient()) {
final String helloWorld = "hello world";
// Evals return instruction in Tarantool lua
final List<?> helloResponse =
crudClient.eval(String.format("return '%s'", helloWorld)).join();
Assertions.assertEquals(1, helloResponse.size());
Assertions.assertEquals(helloWorld, helloResponse.get(0));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> setupClient() {
// Returns routers addresses mapped from docker
final InetSocketAddress firstRouterAddress = getRouterAddress(FIRST_ROUTER_CONTAINER_NAME);
final InetSocketAddress secondRouterAddress = getRouterAddress(SECOND_ROUTER_CONTAINER_NAME);
// Create crud client instance and connect to routers
return TarantoolClientFactory.createClient()
.withAddresses(
new TarantoolServerAddress(
firstRouterAddress.getHostName(), firstRouterAddress.getPort()),
new TarantoolServerAddress(
secondRouterAddress.getHostName(), secondRouterAddress.getPort()))
// Two connection groups with different users in one client instance
.withCredentials(USER_1182, USER_1182_PWD)
.withConnections(2)
.withProxyMethodMapping()
.build();
}
}
// --8<-- [end:all]