-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTest.java
More file actions
81 lines (67 loc) · 2.87 KB
/
BaseTest.java
File metadata and controls
81 lines (67 loc) · 2.87 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
81
/*
* Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY
* All Rights Reserved.
*/
package io.tarantool.balancer.integration;
import java.util.HashMap;
import java.util.Map;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.MultiThreadIoEventLoopGroup;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.msgpack.value.ArrayValue;
import org.msgpack.value.ValueFactory;
import io.tarantool.core.ManagedResource;
import io.tarantool.core.connection.ConnectionFactory;
import io.tarantool.pool.HeartbeatOpts;
public abstract class BaseTest {
protected static final Bootstrap bootstrap =
new Bootstrap()
.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()))
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000);
protected static final Timer timerService = new HashedWheelTimer();
protected static final ManagedResource<Timer> timerResource =
ManagedResource.external(timerService);
protected static ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService);
protected static final int MAX_CONNECTION_COUNT = 20;
protected static final int MIN_CONNECTION_COUNT = 10;
protected static int count1;
protected static int count2;
protected static final String API_USER = "api_user";
protected static final Map<String, String> CREDS =
new HashMap<String, String>() {
{
put(API_USER, "secret");
}
};
protected static final Map<String, String> ENV_MAP =
new HashMap<String, String>() {
{
put("TARANTOOL_USER_NAME", API_USER);
put("TARANTOOL_USER_PASSWORD", CREDS.get(API_USER));
}
};
protected static final int PING_INTERVAL = 500;
protected static final int WINDOW_SIZE = 4;
protected static final long TIMER_ERROR_MS = 100;
protected static final int INVALID_PINGS = 2;
protected static final long INVALIDATION_TIMEOUT =
((long) (INVALID_PINGS + 1) * (PING_INTERVAL + TIMER_ERROR_MS));
/** Longer wait for invalidation (e.g. Tarantool 3 with more connections). */
protected static final long EXTENDED_INVALIDATION_TIMEOUT = INVALIDATION_TIMEOUT * 3;
protected static final long RESTORE_TIMEOUT =
(WINDOW_SIZE + 1) * (PING_INTERVAL + TIMER_ERROR_MS);
protected static final ArrayValue emptyArgs = ValueFactory.emptyArray();
protected static final HeartbeatOpts HEARTBEAT_OPTS =
HeartbeatOpts.getDefault()
.withPingInterval(PING_INTERVAL)
.withInvalidationThreshold(INVALID_PINGS)
.withWindowSize(WINDOW_SIZE);
}