diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java index eb814a3..29709e4 100644 --- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java +++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java @@ -99,6 +99,10 @@ private void execute() { private static final Person personInstance = new Person(1, true, "Roman"); private static final Timer timerService = new HashedWheelTimer(); + static { + TimerShutdownHook.register(timerService, "tarantool-crud-client-retry-test-timer-shutdown"); + } + @BeforeAll public static void setUp() throws Exception { if (isCartridgeAvailable()) { diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java new file mode 100644 index 0000000..6cb4da5 --- /dev/null +++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY + * All Rights Reserved. + */ + +package io.tarantool.client.integration; + +import io.netty.util.Timer; + +public final class TimerShutdownHook { + private TimerShutdownHook() {} + + public static void register(Timer timer, String name) { + Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name)); + } +} diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/BaseTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/BaseTest.java index 3a54dea..c4778f2 100644 --- a/tarantool-core/src/test/java/io/tarantool/core/integration/BaseTest.java +++ b/tarantool-core/src/test/java/io/tarantool/core/integration/BaseTest.java @@ -58,9 +58,13 @@ public abstract class BaseTest { } }; - protected Timer timerService = new HashedWheelTimer(); + protected static Timer timerService = new HashedWheelTimer(); - protected ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService); + protected static ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService); + + static { + TimerShutdownHook.register(timerService, "base-test-timer-shutdown"); + } protected static ArrayValue decodeTuple(IProtoClient client, ArrayValue arrayValue) throws IOException { diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java index 212d7fc..f6ca247 100644 --- a/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java +++ b/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import io.netty.util.HashedWheelTimer; +import io.netty.util.Timer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -68,6 +69,7 @@ import io.tarantool.core.IProtoClient; import io.tarantool.core.IProtoClientImpl; import io.tarantool.core.IProtoFeature; +import io.tarantool.core.connection.ConnectionFactory; import io.tarantool.core.exceptions.BoxError; import io.tarantool.core.exceptions.BoxErrorStackItem; import io.tarantool.core.exceptions.ClientException; @@ -1514,17 +1516,23 @@ public void testPing() throws Exception { } @Test - public void testTimeoutCancel() throws Exception { - IProtoClient client = createClientAndConnect(address, true); + public void testLocalTimerHasNoPending() throws Exception { + Timer localTimer = new HashedWheelTimer(); + IProtoClient client = + new IProtoClientImpl( + new ConnectionFactory(bootstrap, localTimer), + localTimer, + DEFAULT_WATCHER_OPTS, + null, + null, + true); + client.connect(address, 3_000).get(); client.authorize(API_USER, CREDS.get(API_USER)).join(); IProtoMessage message = client.ping().get(); checkMessageHeader(message, IPROTO_OK, 4); assertEquals(0, message.getBody().map().size()); - Set timers = timerService.stop(); - assertTrue(timers.isEmpty()); - - timerService = new HashedWheelTimer(); + assertTrue(localTimer.stop().isEmpty()); } @Test diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/TimerShutdownHook.java b/tarantool-core/src/test/java/io/tarantool/core/integration/TimerShutdownHook.java new file mode 100644 index 0000000..1e1c8dd --- /dev/null +++ b/tarantool-core/src/test/java/io/tarantool/core/integration/TimerShutdownHook.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY + * All Rights Reserved. + */ + +package io.tarantool.core.integration; + +import io.netty.util.Timer; + +public final class TimerShutdownHook { + private TimerShutdownHook() {} + + public static void register(Timer timer, String name) { + Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name)); + } +} diff --git a/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/BaseTest.java b/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/BaseTest.java index 79ed68a..7ec6c26 100644 --- a/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/BaseTest.java +++ b/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/BaseTest.java @@ -47,4 +47,8 @@ public abstract class BaseTest { .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000); protected static final Timer timerService = new HashedWheelTimer(); protected static final ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService); + + static { + TimerShutdownHook.register(timerService, "jackson-mapping-base-test-timer-shutdown"); + } } diff --git a/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/TimerShutdownHook.java b/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/TimerShutdownHook.java new file mode 100644 index 0000000..275519d --- /dev/null +++ b/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/TimerShutdownHook.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY + * All Rights Reserved. + */ + +package io.tarantool.mapping.integration; + +import io.netty.util.Timer; + +public final class TimerShutdownHook { + private TimerShutdownHook() {} + + public static void register(Timer timer, String name) { + Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name)); + } +} diff --git a/tarantool-schema/src/test/java/io/tarantool/client/integration/TarantoolSchemaFetcherTest.java b/tarantool-schema/src/test/java/io/tarantool/client/integration/TarantoolSchemaFetcherTest.java index 9c45259..55d1877 100644 --- a/tarantool-schema/src/test/java/io/tarantool/client/integration/TarantoolSchemaFetcherTest.java +++ b/tarantool-schema/src/test/java/io/tarantool/client/integration/TarantoolSchemaFetcherTest.java @@ -75,6 +75,10 @@ public class TarantoolSchemaFetcherTest { private static final Timer timerService = new HashedWheelTimer(); private static final ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService); + static { + TimerShutdownHook.register(timerService, "tarantool-schema-fetcher-test-timer-shutdown"); + } + private static TarantoolContainer tt; private Long spacePersonId; diff --git a/tarantool-schema/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java b/tarantool-schema/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java new file mode 100644 index 0000000..6cb4da5 --- /dev/null +++ b/tarantool-schema/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY + * All Rights Reserved. + */ + +package io.tarantool.client.integration; + +import io.netty.util.Timer; + +public final class TimerShutdownHook { + private TimerShutdownHook() {} + + public static void register(Timer timer, String name) { + Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name)); + } +}