Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Bugfixes
- Fix lack of closing when greeting fails ([#379](https://github.com/tarantool/cartridge-java/pull/379))

## [0.11.1] - 2023-04-24
### Bugfixes
- Fix hasMetadata logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public CompletableFuture<TarantoolConnection> singleConnection(
return result.handle((connection, ex) -> {
if (ex != null) {
logger.warn("Connection failed: {}", ex.getMessage());
future.channel().close();
}
return connection;
});
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/io/tarantool/driver/integration/ConnectionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import io.tarantool.driver.exceptions.TarantoolClientException;
import io.tarantool.driver.exceptions.TarantoolConnectionException;
import io.tarantool.driver.exceptions.TarantoolInternalException;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,6 +26,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand All @@ -48,6 +51,11 @@ public class ConnectionIT extends SharedTarantoolContainer {
private static final String EXISTING_USER_WITHOUT_PASSWORD = "empty_password_user";
private static final Logger log = LoggerFactory.getLogger(ConnectionIT.class);

@BeforeAll
public static void setUp() {
startContainer();
}

@Test
public void connectAndCheckMetadata() throws Exception {
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
Expand Down Expand Up @@ -311,6 +319,23 @@ public void testIncorrectPassword_multipleRequestsShouldNotHang() {
});
}

@Test
public void testIncorrectPassword_shouldCloseConnection() throws Exception {
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
container.getUsername(), "incorrect");
TarantoolServerAddress serverAddress = new TarantoolServerAddress(
container.getHost(), container.getPort());
ClusterTarantoolTupleClient client = new ClusterTarantoolTupleClient(credentials, serverAddress);
for (int i = 0; i < 100; i++) {
assertThrows(TarantoolClientException.class, () -> {
client.getVersion();
});
}
Map netStat = (Map) container.executeCommand("return box.stat.net()").join().get(0);
Map connections = (Map) netStat.get("CONNECTIONS");
assertTrue((Integer) connections.get("current") <= 2); // one for container one for static test client
}

@Test
public void testClientClosing_clientWithoutConnectionsShouldNotHang() throws Exception {
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@ protected static void startContainer() {
}

protected static void initClient() {
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
container.getUsername(), container.getPassword());

TarantoolServerAddress serverAddress = new TarantoolServerAddress(
container.getHost(), container.getPort());

TarantoolClientConfig config = new TarantoolClientConfig.Builder()
.withCredentials(credentials)
.withConnectTimeout(1000 * 5)
.withReadTimeout(1000 * 5)
.withRequestTimeout(1000 * 5)
.build();

logger.info("Attempting connect to Tarantool");
client = new ClusterTarantoolTupleClient(config, serverAddress);
logger.info("Successfully connected to Tarantool, version = {}", client.getVersion());
if (client == null) {
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
container.getUsername(), container.getPassword());

TarantoolServerAddress serverAddress = new TarantoolServerAddress(
container.getHost(), container.getPort());

TarantoolClientConfig config = new TarantoolClientConfig.Builder()
.withCredentials(credentials)
.withConnectTimeout(1000 * 5)
.withReadTimeout(1000 * 5)
.withRequestTimeout(1000 * 5)
.build();

logger.info("Attempting connect to Tarantool");
client = new ClusterTarantoolTupleClient(config, serverAddress);
logger.info("Successfully connected to Tarantool, version = {}", client.getVersion());
}
}
}