Skip to content

Commit ca5d198

Browse files
committed
format code
1 parent 9551ea9 commit ca5d198

5 files changed

Lines changed: 46 additions & 28 deletions

File tree

test/test-core/src/test/java/org/dromara/dynamictp/test/core/converter/ExecutorConverterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void testToMetricsPoolSize() {
135135
ExecutorWrapper wrapper = ExecutorWrapper.of(dtpExecutor);
136136
ThreadPoolStats stats = ExecutorConverter.toMetrics(wrapper);
137137

138+
assertNotNull(stats);
138139
assertEquals(3, stats.getCorePoolSize());
139140
assertEquals(6, stats.getMaximumPoolSize());
140141
assertEquals(0, stats.getActiveCount());

test/test-core/src/test/java/org/dromara/dynamictp/test/core/selector/ExecutorSelectorTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Arrays;
2525
import java.util.List;
2626
import java.util.concurrent.Executor;
27+
import java.util.concurrent.ExecutorService;
2728
import java.util.concurrent.Executors;
2829

2930
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -41,9 +42,9 @@ class ExecutorSelectorTest {
4142
@Test
4243
void testHashedSelectConsistent() {
4344
HashedExecutorSelector selector = new HashedExecutorSelector();
44-
Executor e1 = Executors.newSingleThreadExecutor();
45-
Executor e2 = Executors.newSingleThreadExecutor();
46-
Executor e3 = Executors.newSingleThreadExecutor();
45+
ExecutorService e1 = Executors.newSingleThreadExecutor();
46+
ExecutorService e2 = Executors.newSingleThreadExecutor();
47+
ExecutorService e3 = Executors.newSingleThreadExecutor();
4748
List<Executor> executors = Arrays.asList(e1, e2, e3);
4849

4950
// Same arg should always select the same executor
@@ -52,18 +53,17 @@ void testHashedSelectConsistent() {
5253
Executor second = selector.select(executors, key);
5354
assertEquals(first, second);
5455

55-
e1.toString(); e2.toString(); e3.toString();
5656
// cleanup
57-
((java.util.concurrent.ExecutorService) e1).shutdownNow();
58-
((java.util.concurrent.ExecutorService) e2).shutdownNow();
59-
((java.util.concurrent.ExecutorService) e3).shutdownNow();
57+
e1.shutdownNow();
58+
e2.shutdownNow();
59+
e3.shutdownNow();
6060
}
6161

6262
@Test
6363
void testHashedSelectDifferentKeys() {
6464
HashedExecutorSelector selector = new HashedExecutorSelector();
65-
Executor e1 = Executors.newSingleThreadExecutor();
66-
Executor e2 = Executors.newSingleThreadExecutor();
65+
ExecutorService e1 = Executors.newSingleThreadExecutor();
66+
ExecutorService e2 = Executors.newSingleThreadExecutor();
6767
List<Executor> executors = Arrays.asList(e1, e2);
6868

6969
// Different keys should still return valid executors
@@ -74,15 +74,15 @@ void testHashedSelectDifferentKeys() {
7474
assertTrue(executors.contains(r1));
7575
assertTrue(executors.contains(r2));
7676

77-
((java.util.concurrent.ExecutorService) e1).shutdownNow();
78-
((java.util.concurrent.ExecutorService) e2).shutdownNow();
77+
e1.shutdownNow();
78+
e2.shutdownNow();
7979
}
8080

8181
@Test
8282
void testHashedNegativeHashCode() {
8383
HashedExecutorSelector selector = new HashedExecutorSelector();
84-
Executor e1 = Executors.newSingleThreadExecutor();
85-
Executor e2 = Executors.newSingleThreadExecutor();
84+
ExecutorService e1 = Executors.newSingleThreadExecutor();
85+
ExecutorService e2 = Executors.newSingleThreadExecutor();
8686
List<Executor> executors = Arrays.asList(e1, e2);
8787

8888
// Object with negative hashCode
@@ -96,16 +96,16 @@ public int hashCode() {
9696
assertNotNull(result);
9797
assertTrue(executors.contains(result));
9898

99-
((java.util.concurrent.ExecutorService) e1).shutdownNow();
100-
((java.util.concurrent.ExecutorService) e2).shutdownNow();
99+
e1.shutdownNow();
100+
e2.shutdownNow();
101101
}
102102

103103
@Test
104104
void testRandomSelectReturnsValid() {
105105
RandomExecutorSelector selector = new RandomExecutorSelector();
106-
Executor e1 = Executors.newSingleThreadExecutor();
107-
Executor e2 = Executors.newSingleThreadExecutor();
108-
Executor e3 = Executors.newSingleThreadExecutor();
106+
ExecutorService e1 = Executors.newSingleThreadExecutor();
107+
ExecutorService e2 = Executors.newSingleThreadExecutor();
108+
ExecutorService e3 = Executors.newSingleThreadExecutor();
109109
List<Executor> executors = Arrays.asList(e1, e2, e3);
110110

111111
// Run multiple times to verify it always returns a valid executor
@@ -115,8 +115,8 @@ void testRandomSelectReturnsValid() {
115115
assertTrue(executors.contains(selected));
116116
}
117117

118-
((java.util.concurrent.ExecutorService) e1).shutdownNow();
119-
((java.util.concurrent.ExecutorService) e2).shutdownNow();
120-
((java.util.concurrent.ExecutorService) e3).shutdownNow();
118+
e1.shutdownNow();
119+
e2.shutdownNow();
120+
e3.shutdownNow();
121121
}
122122
}

test/test-core/src/test/java/org/dromara/dynamictp/test/core/support/DtpLifecycleSupportTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class DtpLifecycleSupportTest {
4141
void testInternalShutdownGraceful() {
4242
ExecutorService executor = Executors.newFixedThreadPool(2);
4343
executor.submit(() -> {
44-
try { Thread.sleep(200); } catch (InterruptedException ignored) { }
44+
try {
45+
Thread.sleep(200);
46+
} catch (InterruptedException ignored) {
47+
}
4548
});
4649

4750
DtpLifecycleSupport.internalShutdown(executor, "test-graceful", true, 5);
@@ -54,7 +57,10 @@ void testInternalShutdownGraceful() {
5457
void testInternalShutdownImmediate() {
5558
ExecutorService executor = Executors.newFixedThreadPool(2);
5659
executor.submit(() -> {
57-
try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
60+
try {
61+
Thread.sleep(5000);
62+
} catch (InterruptedException ignored) {
63+
}
5864
});
5965

6066
DtpLifecycleSupport.internalShutdown(executor, "test-immediate", false, 1);
@@ -81,7 +87,10 @@ void testInternalShutdownZeroAwait() {
8187
void testCancelRemainingTaskWithFuture() throws Exception {
8288
ExecutorService executor = Executors.newSingleThreadExecutor();
8389
Future<?> future = executor.submit(() -> {
84-
try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
90+
try {
91+
Thread.sleep(5000);
92+
} catch (InterruptedException ignored) {
93+
}
8594
});
8695

8796
// shutdownNow returns remaining tasks
@@ -97,7 +106,10 @@ void testCancelRemainingTaskWithFuture() throws Exception {
97106
void testShutdownGracefulAsync() throws InterruptedException {
98107
ExecutorService executor = Executors.newFixedThreadPool(2);
99108
executor.submit(() -> {
100-
try { Thread.sleep(200); } catch (InterruptedException ignored) { }
109+
try {
110+
Thread.sleep(200);
111+
} catch (InterruptedException ignored) {
112+
}
101113
});
102114

103115
DtpLifecycleSupport.shutdownGracefulAsync(executor, "test-async", 5);
@@ -112,7 +124,10 @@ void testShutdownAlreadyTerminated() {
112124
ExecutorService executor = Executors.newSingleThreadExecutor();
113125
executor.submit(() -> { });
114126
executor.shutdown();
115-
try { executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException ignored) { }
127+
try {
128+
executor.awaitTermination(5, TimeUnit.SECONDS);
129+
} catch (InterruptedException ignored) {
130+
}
116131

117132
assertTrue(executor.isTerminated());
118133
// Should not throw when called on already terminated executor

test/test-core/src/test/java/org/dromara/dynamictp/test/core/support/ExecutorWrapperTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import static org.junit.jupiter.api.Assertions.assertEquals;
3131
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
3233
import static org.junit.jupiter.api.Assertions.assertNotNull;
3334
import static org.junit.jupiter.api.Assertions.assertNotSame;
3435
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -130,7 +131,7 @@ void testCaptureReturnsSnapshot() {
130131

131132
assertEquals(original.getThreadPoolName(), captured.getThreadPoolName());
132133
assertNotNull(captured.getExecutor());
133-
assertTrue(captured.getExecutor() instanceof CapturedExecutor);
134+
assertInstanceOf(CapturedExecutor.class, captured.getExecutor());
134135
// captured executor is a different object
135136
assertNotSame(original.getExecutor(), captured.getExecutor());
136137
}

test/test-core/src/test/java/org/dromara/dynamictp/test/core/support/task/wrapper/TaskWrappersTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static org.junit.jupiter.api.Assertions.assertEquals;
2929
import static org.junit.jupiter.api.Assertions.assertNotNull;
30+
import static org.junit.jupiter.api.Assertions.assertSame;
3031
import static org.junit.jupiter.api.Assertions.assertTrue;
3132

3233
/**
@@ -47,7 +48,7 @@ void testGetInstanceNotNull() {
4748
void testGetInstanceSingleton() {
4849
TaskWrappers a = TaskWrappers.getInstance();
4950
TaskWrappers b = TaskWrappers.getInstance();
50-
assertTrue(a == b);
51+
assertSame(a, b);
5152
}
5253

5354
@Test

0 commit comments

Comments
 (0)