Skip to content

Commit

Permalink
Add connection close
Browse files Browse the repository at this point in the history
Fix connection to multiple instances doesn't shut down EventLoopGroup by finishing the work

Closes #435
  • Loading branch information
iDneprov authored and akudiyar committed Dec 26, 2023
1 parent b4b7f77 commit a6199e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ protected Collection<TarantoolServerAddress> discoverAddresses() {
throw new TarantoolClientException("Cluster discovery task error", e);
}
}

@Override
public void close() {
super.close();
try {
client.close();
} catch (Exception e) {
throw new TarantoolClientException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tarantool.driver.integration;

import io.netty.channel.nio.NioEventLoopGroup;
import io.tarantool.driver.api.TarantoolClientConfig;
import io.tarantool.driver.api.TarantoolClusterAddressProvider;
import io.tarantool.driver.api.TarantoolServerAddress;
Expand All @@ -11,11 +12,13 @@
import io.tarantool.driver.cluster.HTTPDiscoveryClusterAddressProvider;
import io.tarantool.driver.cluster.TarantoolClusterDiscoveryConfig;
import io.tarantool.driver.cluster.TestWrappedClusterAddressProvider;
import io.tarantool.driver.core.AbstractTarantoolClient;
import io.tarantool.driver.core.ClusterTarantoolTupleClient;
import io.tarantool.driver.exceptions.TarantoolClientException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -76,6 +79,23 @@ public void binaryClusterDiscovererTest() {
assertTrue(nodeSet.contains(new TarantoolServerAddress(TEST_ROUTER2_URI)));
}

@Test
public void binaryClusterDiscovererCloseTest() throws IllegalAccessException, NoSuchFieldException {
TarantoolClusterAddressProvider addressProvider = getBinaryProvider();

Field clientField = BinaryDiscoveryClusterAddressProvider.class.getDeclaredField("client");
clientField.setAccessible(true);
AbstractTarantoolClient abstractTarantoolClient = (AbstractTarantoolClient) clientField.get(addressProvider);

Field eventLoopGroupField = AbstractTarantoolClient.class.getDeclaredField("eventLoopGroup");
eventLoopGroupField.setAccessible(true);
NioEventLoopGroup eventLoopGroup = (NioEventLoopGroup) eventLoopGroupField.get(abstractTarantoolClient);

addressProvider.close();

assertTrue(eventLoopGroup.isShuttingDown() || eventLoopGroup.isShutdown());
}

private TarantoolClusterAddressProvider getBinaryProvider() {
TarantoolCredentials credentials = new SimpleTarantoolCredentials(
container.getUsername(), container.getPassword());
Expand Down

0 comments on commit a6199e8

Please sign in to comment.