|
| 1 | +package concurrency; |
| 2 | + |
| 3 | +import com.arangodb.config.HostDescription; |
| 4 | +import com.arangodb.internal.InternalRequest; |
| 5 | +import com.arangodb.internal.InternalResponse; |
| 6 | +import com.arangodb.internal.config.ArangoConfig; |
| 7 | +import com.arangodb.internal.net.Connection; |
| 8 | +import com.arangodb.internal.net.ConnectionFactory; |
| 9 | +import com.arangodb.internal.net.ConnectionPool; |
| 10 | +import com.arangodb.internal.net.ConnectionPoolImpl; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | + |
| 13 | +import java.io.IOException; |
| 14 | +import java.util.Collections; |
| 15 | +import java.util.List; |
| 16 | +import java.util.concurrent.*; |
| 17 | + |
| 18 | +public class ConnectionPoolConcurrencyTest { |
| 19 | + |
| 20 | + private final ArangoConfig cfg = new ArangoConfig(); |
| 21 | + |
| 22 | + { |
| 23 | + cfg.setMaxConnections(10_000); |
| 24 | + } |
| 25 | + |
| 26 | + private final ConnectionFactory cf = (config, host) -> new Connection() { |
| 27 | + @Override |
| 28 | + public void setJwt(String jwt) { |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public CompletableFuture<InternalResponse> executeAsync(InternalRequest request) { |
| 33 | + throw new UnsupportedOperationException(); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void close() { |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + @Test |
| 42 | + void foo() throws InterruptedException, ExecutionException, IOException { |
| 43 | + ConnectionPool cp = new ConnectionPoolImpl(HostDescription.parse("127.0.0.1:8529"), cfg, cf); |
| 44 | + ExecutorService es = Executors.newCachedThreadPool(); |
| 45 | + |
| 46 | + List<? extends Future<?>> futures = es.invokeAll(Collections.nCopies(8, (Callable<?>) () -> { |
| 47 | + for (int i = 0; i < 10_000; i++) { |
| 48 | + cp.createConnection(HostDescription.parse("127.0.0.1:8529")); |
| 49 | + cp.connection(); |
| 50 | + cp.setJwt("foo"); |
| 51 | + } |
| 52 | + return null; |
| 53 | + })); |
| 54 | + |
| 55 | + for (Future<?> future : futures) { |
| 56 | + future.get(); |
| 57 | + } |
| 58 | + cp.close(); |
| 59 | + es.shutdown(); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments