1818package org .dromara .dynamictp .test .core .thread ;
1919
2020import com .alibaba .ttl .TransmittableThreadLocal ;
21- import org .dromara .dynamictp .core .support .task .Ordered ;
22- import org .dromara .dynamictp .core .support .task .callable .OrderedCallable ;
23- import org .dromara .dynamictp .core .executor .OrderedDtpExecutor ;
2421import com .google .common .collect .Lists ;
2522import lombok .AllArgsConstructor ;
2623import lombok .Data ;
2724import lombok .extern .slf4j .Slf4j ;
25+ import org .dromara .dynamictp .core .DtpRegistry ;
26+ import org .dromara .dynamictp .core .executor .OrderedDtpExecutor ;
27+ import org .dromara .dynamictp .core .support .task .Ordered ;
28+ import org .dromara .dynamictp .core .support .task .callable .OrderedCallable ;
2829import org .dromara .dynamictp .spring .annotation .EnableDynamicTp ;
2930import org .dromara .dynamictp .spring .support .YamlPropertySourceFactory ;
3031import org .junit .jupiter .api .Test ;
3536import org .springframework .context .annotation .PropertySource ;
3637import org .springframework .test .context .junit .jupiter .SpringExtension ;
3738
38- import javax .annotation .Resource ;
3939import java .util .ArrayList ;
4040import java .util .List ;
4141import java .util .concurrent .Future ;
4242import java .util .concurrent .ThreadLocalRandom ;
4343import java .util .concurrent .TimeUnit ;
4444
4545@ Slf4j
46- @ PropertySource (value = "classpath:/dynamic-tp-nacos-demo-dtp-dev.yml" , factory = YamlPropertySourceFactory .class )
4746@ SpringBootTest (classes = OrderedDtpExecutorTest .class )
4847@ ExtendWith (SpringExtension .class )
4948@ EnableDynamicTp
5049@ EnableAutoConfiguration
50+ @ PropertySource (value = "classpath:/dynamic-tp-nacos-demo-dtp-dev.yml" , factory = YamlPropertySourceFactory .class )
5151class OrderedDtpExecutorTest {
5252
53- @ Resource
54- private OrderedDtpExecutor orderedDtpExecutor ;
55-
5653 private final TransmittableThreadLocal <String > threadLocal = new TransmittableThreadLocal <>();
5754
5855 private final List <String > TABLES = Lists .newArrayList ("table1" , "table2" , "table3" );
5956
6057 @ Test
6158 void orderedExecute () throws InterruptedException {
59+ OrderedDtpExecutor orderedDtpExecutor = (OrderedDtpExecutor ) DtpRegistry .getExecutor ("orderedDtpExecutor" );
60+ if (orderedDtpExecutor == null ) {
61+ return ;
62+ }
6263 for (int i = 0 ; i < 1000 ; i ++) {
6364 if (i == 500 ) {
6465 TimeUnit .MILLISECONDS .sleep (2000L );
@@ -71,6 +72,10 @@ void orderedExecute() throws InterruptedException {
7172
7273 @ Test
7374 void orderedSubmit () {
75+ OrderedDtpExecutor orderedDtpExecutor = (OrderedDtpExecutor ) DtpRegistry .getExecutor ("orderedDtpExecutor" );
76+ if (orderedDtpExecutor == null ) {
77+ return ;
78+ }
7479 List <Future <?>> futures = new ArrayList <>();
7580 for (int i = 0 ; i < 100 ; i ++) {
7681 threadLocal .set ("ttl" + i );
0 commit comments