Skip to content

Commit 5355bc1

Browse files
dkasimovskiyclaude
andcommitted
refactor(tests): simplify TimerShutdownHook body and drop Supplier indirection
Per PR #99 review feedback: Timer.stop() already cancels all pending tasks (per Netty 4.2 javadoc), so the explicit pending.forEach(cancel) pass in the shutdown hook body is dead work. After stop() returns the worker thread is dead, so cancel() on the returned handles is a no-op, and stop() never returns null. Also drop the Supplier<Timer> wrapper at every call site — the timer reference is a static field, stable for the JVM lifetime. Body collapses to one line per module: Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name)); Net diff: -56 LOC across 8 files. box-integration profile passes (Tarantool 2.11.8). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b6b7f4a commit 5355bc1

8 files changed

Lines changed: 12 additions & 69 deletions

File tree

tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientWithRetryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ private void execute() {
100100
private static final Timer timerService = new HashedWheelTimer();
101101

102102
static {
103-
TimerShutdownHook.register(
104-
() -> timerService, "tarantool-crud-client-retry-test-timer-shutdown");
103+
TimerShutdownHook.register(timerService, "tarantool-crud-client-retry-test-timer-shutdown");
105104
}
106105

107106
@BeforeAll

tarantool-client/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,12 @@
55

66
package io.tarantool.client.integration;
77

8-
import java.util.Set;
9-
import java.util.function.Supplier;
10-
11-
import io.netty.util.Timeout;
128
import io.netty.util.Timer;
139

1410
public final class TimerShutdownHook {
1511
private TimerShutdownHook() {}
1612

17-
public static void register(Supplier<Timer> timerRef, String name) {
18-
Runtime.getRuntime()
19-
.addShutdownHook(
20-
new Thread(
21-
() -> {
22-
Timer t = timerRef.get();
23-
if (t != null) {
24-
Set<Timeout> pending = t.stop();
25-
if (pending != null) pending.forEach(Timeout::cancel);
26-
}
27-
},
28-
name));
13+
public static void register(Timer timer, String name) {
14+
Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name));
2915
}
3016
}

tarantool-core/src/test/java/io/tarantool/core/integration/BaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public abstract class BaseTest {
6363
protected static ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService);
6464

6565
static {
66-
TimerShutdownHook.register(() -> timerService, "base-test-timer-shutdown");
66+
TimerShutdownHook.register(timerService, "base-test-timer-shutdown");
6767
}
6868

6969
protected static ArrayValue decodeTuple(IProtoClient client, ArrayValue arrayValue)

tarantool-core/src/test/java/io/tarantool/core/integration/TimerShutdownHook.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,12 @@
55

66
package io.tarantool.core.integration;
77

8-
import java.util.Set;
9-
import java.util.function.Supplier;
10-
11-
import io.netty.util.Timeout;
128
import io.netty.util.Timer;
139

1410
public final class TimerShutdownHook {
1511
private TimerShutdownHook() {}
1612

17-
public static void register(Supplier<Timer> timerRef, String name) {
18-
Runtime.getRuntime()
19-
.addShutdownHook(
20-
new Thread(
21-
() -> {
22-
Timer t = timerRef.get();
23-
if (t != null) {
24-
Set<Timeout> pending = t.stop();
25-
if (pending != null) pending.forEach(Timeout::cancel);
26-
}
27-
},
28-
name));
13+
public static void register(Timer timer, String name) {
14+
Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name));
2915
}
3016
}

tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/BaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public abstract class BaseTest {
4949
protected static final ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService);
5050

5151
static {
52-
TimerShutdownHook.register(() -> timerService, "jackson-mapping-base-test-timer-shutdown");
52+
TimerShutdownHook.register(timerService, "jackson-mapping-base-test-timer-shutdown");
5353
}
5454
}

tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/integration/TimerShutdownHook.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,12 @@
55

66
package io.tarantool.mapping.integration;
77

8-
import java.util.Set;
9-
import java.util.function.Supplier;
10-
11-
import io.netty.util.Timeout;
128
import io.netty.util.Timer;
139

1410
public final class TimerShutdownHook {
1511
private TimerShutdownHook() {}
1612

17-
public static void register(Supplier<Timer> timerRef, String name) {
18-
Runtime.getRuntime()
19-
.addShutdownHook(
20-
new Thread(
21-
() -> {
22-
Timer t = timerRef.get();
23-
if (t != null) {
24-
Set<Timeout> pending = t.stop();
25-
if (pending != null) pending.forEach(Timeout::cancel);
26-
}
27-
},
28-
name));
13+
public static void register(Timer timer, String name) {
14+
Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name));
2915
}
3016
}

tarantool-schema/src/test/java/io/tarantool/client/integration/TarantoolSchemaFetcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class TarantoolSchemaFetcherTest {
7676
private static final ConnectionFactory factory = new ConnectionFactory(bootstrap, timerService);
7777

7878
static {
79-
TimerShutdownHook.register(() -> timerService, "tarantool-schema-fetcher-test-timer-shutdown");
79+
TimerShutdownHook.register(timerService, "tarantool-schema-fetcher-test-timer-shutdown");
8080
}
8181

8282
private static TarantoolContainer<?> tt;

tarantool-schema/src/test/java/io/tarantool/client/integration/TimerShutdownHook.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,12 @@
55

66
package io.tarantool.client.integration;
77

8-
import java.util.Set;
9-
import java.util.function.Supplier;
10-
11-
import io.netty.util.Timeout;
128
import io.netty.util.Timer;
139

1410
public final class TimerShutdownHook {
1511
private TimerShutdownHook() {}
1612

17-
public static void register(Supplier<Timer> timerRef, String name) {
18-
Runtime.getRuntime()
19-
.addShutdownHook(
20-
new Thread(
21-
() -> {
22-
Timer t = timerRef.get();
23-
if (t != null) {
24-
Set<Timeout> pending = t.stop();
25-
if (pending != null) pending.forEach(Timeout::cancel);
26-
}
27-
},
28-
name));
13+
public static void register(Timer timer, String name) {
14+
Runtime.getRuntime().addShutdownHook(new Thread(timer::stop, name));
2915
}
3016
}

0 commit comments

Comments
 (0)