10000 ConnectionLoadBalanceTest · arangodb/arangodb-java-driver@19af90b · GitHub
[go: up one dir, main page]

Skip to content

Commit 19af90b

Browse files
committed
ConnectionLoadBalanceTest
1 parent 9b8e9c6 commit 19af90b

File tree

4 files changed

+109
-7
lines changed

4 files changed

+109
-7
lines changed

docker/start_db.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ docker run -d \
6666
--starter.address="${GW}" \
6767
--docker.image="${DOCKER_IMAGE}" \
6868
--starter.local --starter.mode=${STARTER_MODE} --all.log.level=debug --all.log.output=+ --log.verbose \
69-
--all.server.descriptors-minimum=1024 --all.javascript.allow-admin-execute=true
69+
--all.server.descriptors-minimum=1024 --all.javascript.allow-admin-execute=true --all.server.maximal-threads=128
7070

7171

7272
wait_server() {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package concurrency;
2+
3+
import com.arangodb.*;
4+
import com.arangodb.config.ArangoConfigProperties;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.Arguments;
7+
import org.junit.jupiter.params.provider.MethodSource;
8+
import util.TestUtils;
9+
10+
import java.time.Duration;
11+
import java.util.Map;
12+
import java.util.concurrent.CompletableFuture;
13+
import java.util.stream.IntStream;
14+
import java.util.stream.Stream;
15+
16+
import static org.awaitility.Awaitility.await;
17+
18+
public class ConnectionLoadBalanceTest {
19+
20+
public static Stream<Arguments> configs() {
21+
return Stream.of(
22+
// FIXME: DE-1017
23+
// new Config(Protocol.VST, 1),
24+
// new Config(Protocol.VST, 2),
25+
new Config(Protocol.HTTP_JSON, 10),
26+
new Config(Protocol.HTTP_JSON, 20),
27+
new Config(Protocol.HTTP2_JSON, 1),
28+
new Config(Protocol.HTTP2_JSON, 2)
29+
).map(Arguments::of);
30+
}
31+
32+
// Test the requests load balancing across different connections, when all the slots except 1 are busy
33+
@MethodSource("configs")
34+
@ParameterizedTest
35+
void loadBalanceToFreeConnection(Config cfg) throws InterruptedException {
36+
doTestLoadBalance(cfg, 1);
37+
}
38+
39+
// Test the requests load balancing across different connections, when all the slots are busy
40+
@MethodSource("configs")
41+
@ParameterizedTest
42+
void loadBalanceAllBusy(Config cfg) throws InterruptedException {
43+
doTestLoadBalance(cfg, 2);
44+
}
45+
46+
void doTestLoadBalance(Config cfg, int sleepCycles) throws InterruptedException {
47+
int longTasksCount = cfg.maxStreams() * cfg.maxConnections * sleepCycles - 1;
48+
int shortTasksCount = 10;
49+
long sleepDuration = 2;
50+
51+
ArangoDatabaseAsync db = new ArangoDB.Builder()
52+
.loadProperties(ArangoConfigProperties.fromFile())
53+
.protocol(cfg.protocol)
54+
.serde(TestUtils.createSerde(cfg.protocol))
55+
.maxConnections(cfg.maxConnections)
56+
.build().async().db();
57+
58+
CompletableFuture<Void> longRunningTasks = CompletableFuture.allOf(
59+
IntStream.range(0, longTasksCount)
60+
.mapToObj(__ ->
61+
db.query("RETURN SLEEP(@duration)", Void.class, Map.of("duration", sleepDuration)))
62+
.toArray(CompletableFuture[]::new)
63+
);
64+
65+
Thread.sleep(100);
66+< D7AE /span>
67+
CompletableFuture<Void> shortRunningTasks = CompletableFuture.allOf(
68+
IntStream.range(0, shortTasksCount)
69+
.mapToObj(__ -> db.query("RETURN 1", Integer.class))
70+
.toArray(CompletableFuture[]::new)
71+
);
72+
73+
await()
74+
.timeout(Duration.ofSeconds(sleepDuration * sleepCycles - 1L))
75+
.until(shortRunningTasks::isDone);
76+
77+
await()
78+
.timeout(Duration.ofSeconds(sleepDuration * sleepCycles + 1L))
79+
.until(longRunningTasks::isDone);
80+
81+
shortRunningTasks.join();
82+
longRunningTasks.join();
83+
db.arango().shutdown();
84+
}
85+
86+
private record Config(
87+
Protocol protocol,
88+
int maxConnections
89+
) {
90+
int maxStreams() {
91+
return switch (protocol) {
92+
case HTTP_JSON, HTTP_VPACK -> 1;
93+
default -> 32;
94+
};
95+
}
96+
}
97+
}

test-parent/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
<artifactId>assertj-core</artifactId>
6161
<scope>test</scope>
6262
</dependency>
63+
<dependency>
64+
<groupId>org.awaitility</groupId>
65+
<artifactId>awaitility</artifactId>
66+
<scope>test</scope>
67+
</dependency>
6368
</dependencies>
6469

6570
<dependencyManagement>
@@ -93,6 +98,12 @@
9398
<artifactId>assertj-core</artifactId>
9499
<version>3.25.3</version>
95100
</dependency>
101+
<dependency>
102+
<groupId>org.awaitility</groupId>
103+
<artifactId>awaitility</artifactId>
104+
<version>4.2.1</version>
105+
<scope>test</scope>
106+
</dependency>
96107
<dependency>
97108
<groupId>com.tngtech.archunit</groupId>
98109
<artifactId>archunit-junit5</artifactId>

test-resilience/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
<version>2.1.7</version>
3030
<scope>test</scope>
3131
</dependency>
32-
<dependency>
33-
<groupId>org.awaitility</groupId>
34-
<artifactId>awaitility</artifactId>
35-
<version>4.2.0</version>
36-
<scope>test</scope>
37-
</dependency>
3832
<dependency>
3933
<groupId>ch.qos.logback</groupId>
4034
<artifactId>logback-classic</artifactId>

0 commit comments

Comments
 (0)
0