-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathConnectionPoolConcurrencyTest.java
62 lines (50 loc) · 1.79 KB
/
ConnectionPoolConcurrencyTest.java
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
package concurrency;
import com.arangodb.config.HostDescription;
import com.arangodb.internal.InternalRequest;
import com.arangodb.internal.InternalResponse;
import com.arangodb.internal.config.ArangoConfig;
import com.arangodb.internal.net.Connection;
import com.arangodb.internal.net.ConnectionFactory;
import com.arangodb.internal.net.ConnectionPool;
import com.arangodb.internal.net.ConnectionPoolImpl;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
public class ConnectionPoolConcurrencyTest {
private final ArangoConfig cfg = new ArangoConfig();
{
cfg.setMaxConnections(10_000);
}
private final ConnectionFactory cf = (config, host) -> new Connection() {
@Override
public void setJwt(String jwt) {
}
@Override
public CompletableFuture<InternalResponse> executeAsync(InternalRequest request) {
throw new UnsupportedOperationException();
}
@Override
public void close() {
}
};
@Test
void foo() throws InterruptedException, ExecutionException, IOException {
ConnectionPool cp = new ConnectionPoolImpl(HostDescription.parse("127.0.0.1:8529"), cfg, cf);
ExecutorService es = Executors.newCachedThreadPool();
List<? extends Future<?>> futures = es.invokeAll(Collections.nCopies(8, (Callable<?>) () -> {
for (int i = 0; i < 10_000; i++) {
cp.createConnection(HostDescription.parse("127.0.0.1:8529"));
cp.connection();
cp.setJwt("foo");
}
return null;
}));
for (Future<?> future : futures) {
future.get();
}
cp.close();
es.shutdown();
}
}