-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarantoolCallCartridgeDriverExample.java
More file actions
66 lines (51 loc) · 2.25 KB
/
TarantoolCallCartridgeDriverExample.java
File metadata and controls
66 lines (51 loc) · 2.25 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
/*
* Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY
* All Rights Reserved.
*/
package client;
// --8<-- [start:all]
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import testcontainers.utils.TarantoolSingleNodeConfigUtils;
import io.tarantool.driver.api.TarantoolClient;
import io.tarantool.driver.api.TarantoolClientFactory;
import io.tarantool.driver.api.TarantoolResult;
import io.tarantool.driver.api.tuple.TarantoolTuple;
public class TarantoolCallCartridgeDriverExample extends TarantoolCallEvalAbstractExample {
@Test
@SuppressWarnings("unchecked")
void simpleCall() {
try (TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client = setupClient()) {
loadFunctions();
final List<?> helloWorldReturns = client.call(HELLO_WORLD_FUNCTION).join();
Assertions.assertEquals(1, helloWorldReturns.size());
Assertions.assertEquals(HELLO_WORLD_FUNCTION_RETURNS, helloWorldReturns.get(0));
// convert returning lua map into Java pojo representing as map
final String name = "Petya";
final int age = 25;
final List<?> resultAsMap = client.call(SOME_MAP_FUNCTION, Arrays.asList(name, age)).join();
Assertions.assertEquals(1, resultAsMap.size());
Assertions.assertInstanceOf(Map.class, resultAsMap.get(0));
final Map<String, Object> castedResult = (Map<String, Object>) resultAsMap.get(0);
Assertions.assertEquals(name, castedResult.get("name"));
Assertions.assertEquals(age, castedResult.get("age"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> setupClient() {
// Получаем адрес и порт из докера
// Gets address and port from docker
final InetSocketAddress nodeAddress = CONTAINER.mappedAddress();
return TarantoolClientFactory.createClient()
.withAddress(nodeAddress.getHostName(), nodeAddress.getPort())
.withCredentials(
TarantoolSingleNodeConfigUtils.LOGIN, TarantoolSingleNodeConfigUtils.PWD.toString())
.build();
}
}
// --8<-- [end:all]