Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE-5369] fíx ConnectionPoolImpl concurrency #570

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.arangodb.ArangoDBException;
import com.arangodb.config.HostDescription;
import com.arangodb.internal.config.ArangoConfig;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -79,7 +80,7 @@ public synchronized Connection connection() {
}

@Override
public void setJwt(String jwt) {
public synchronized void setJwt(String jwt) {
if (jwt != null) {
this.jwt = jwt;
for (Connection connection : connections) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}

}