|
1 | 1 | package io.tarantool.driver.integration; |
2 | 2 |
|
3 | | -import java.lang.reflect.InvocationTargetException; |
4 | | -import java.lang.reflect.Method; |
5 | 3 | import java.util.ArrayList; |
6 | 4 | import java.util.Arrays; |
7 | 5 | import java.util.Collections; |
|
12 | 10 | import java.util.concurrent.ExecutionException; |
13 | 11 | import java.util.concurrent.ExecutorService; |
14 | 12 | import java.util.concurrent.Executors; |
15 | | -import java.util.concurrent.atomic.AtomicInteger; |
16 | 13 |
|
17 | 14 | import org.junit.jupiter.api.BeforeAll; |
18 | 15 | import org.junit.jupiter.api.BeforeEach; |
19 | 16 | import org.junit.jupiter.api.Test; |
20 | | -import org.testcontainers.shaded.org.apache.commons.lang3.reflect.FieldUtils; |
21 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 18 | import static org.junit.jupiter.api.Assertions.assertFalse; |
23 | 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
32 | 28 | import io.tarantool.driver.api.TarantoolResult; |
33 | 29 | import io.tarantool.driver.api.TarantoolServerAddress; |
34 | 30 | import io.tarantool.driver.api.conditions.Conditions; |
| 31 | +import io.tarantool.driver.api.connection.TarantoolConnection; |
35 | 32 | import io.tarantool.driver.api.metadata.TarantoolIndexMetadata; |
36 | 33 | import io.tarantool.driver.api.metadata.TarantoolIndexType; |
37 | 34 | import io.tarantool.driver.api.metadata.TarantoolMetadataOperations; |
|
52 | 49 | import io.tarantool.driver.core.ClusterTarantoolTupleClient; |
53 | 50 | import io.tarantool.driver.core.ProxyTarantoolTupleClient; |
54 | 51 | import io.tarantool.driver.core.RetryingTarantoolTupleClient; |
55 | | -import io.tarantool.driver.core.connection.TarantoolClusterConnectionManager; |
56 | 52 | import io.tarantool.driver.core.tuple.TarantoolTupleImpl; |
57 | 53 | import io.tarantool.driver.exceptions.TarantoolInternalException; |
58 | 54 | import io.tarantool.driver.exceptions.TarantoolNoSuchProcedureException; |
@@ -84,9 +80,7 @@ public class ProxyTarantoolClientIT extends SharedCartridgeContainer { |
84 | 80 | private static final String PK_FIELD_NAME = "profile_id"; |
85 | 81 | private static final String BUCKET_ID_FIELD_NAME = "bucket_id"; |
86 | 82 | private static final int DEFAULT_TIMEOUT = 5 * 1000; |
87 | | - private static TestWrappedClusterAddressProvider addressProvider; |
88 | | - private static Method getAliveConnections; |
89 | | - private static TarantoolClusterConnectionManager connectionManager; |
| 83 | + private static List<TarantoolConnection> connections = new ArrayList<>(); |
90 | 84 |
|
91 | 85 | @BeforeAll |
92 | 86 | public static void setUp() throws Exception { |
@@ -152,6 +146,10 @@ public static void initClient() { |
152 | 146 | .builder(10, thr -> thr instanceof TarantoolNoSuchProcedureException) |
153 | 147 | .withDelay(100) |
154 | 148 | .build()); |
| 149 | + client.getConnectionListeners().add(conn -> { |
| 150 | + connections.add(conn); |
| 151 | + return CompletableFuture.completedFuture(conn); |
| 152 | + }); |
155 | 153 | } |
156 | 154 |
|
157 | 155 | @Test |
@@ -706,37 +704,7 @@ public void test_should_reconnect_ifReconnectIsInvoked() throws Exception { |
706 | 704 | }); |
707 | 705 | } |
708 | 706 |
|
709 | | - private static int getAliveConnections() throws IllegalAccessException, NoSuchMethodException { |
710 | | - if (addressProvider == null) { |
711 | | - ClusterTarantoolTupleClient |
712 | | - innerClient = (ClusterTarantoolTupleClient) FieldUtils.readField( |
713 | | - FieldUtils.readField(client, "client", true), |
714 | | - "client", true); |
715 | | - connectionManager = |
716 | | - (TarantoolClusterConnectionManager) FieldUtils.readField(innerClient, "connectionManager", true); |
717 | | - |
718 | | - getAliveConnections = |
719 | | - connectionManager.getClass().getSuperclass() |
720 | | - .getDeclaredMethod("getAliveConnections", TarantoolServerAddress.class); |
721 | | - getAliveConnections.setAccessible(true); |
722 | | - |
723 | | - addressProvider = |
724 | | - (TestWrappedClusterAddressProvider) FieldUtils.readField(innerClient, "addressProvider", true); |
725 | | - } |
726 | | - |
727 | | - return getAliveConnectionsAux(); |
728 | | - } |
729 | | - |
730 | | - private static int getAliveConnectionsAux() { |
731 | | - AtomicInteger res = new AtomicInteger(); |
732 | | - addressProvider.getAddresses().forEach(r -> { |
733 | | - try { |
734 | | - res.addAndGet(((List<?>) getAliveConnections.invoke(connectionManager, r)).size()); |
735 | | - } catch (IllegalAccessException | InvocationTargetException e) { |
736 | | - throw new RuntimeException(e); |
737 | | - } |
738 | | - }); |
739 | | - |
740 | | - return res.get(); |
| 707 | + private static long getAliveConnections() throws IllegalAccessException, NoSuchMethodException { |
| 708 | + return connections.stream().filter(TarantoolConnection::isConnected).count(); |
741 | 709 | } |
742 | 710 | } |
0 commit comments