1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .scheduling .concurrent ;
18
18
19
+ import java .util .concurrent .BlockingQueue ;
20
+ import java .util .concurrent .LinkedBlockingQueue ;
21
+ import java .util .concurrent .SynchronousQueue ;
19
22
import java .util .concurrent .TimeUnit ;
20
23
21
24
import org .junit .jupiter .api .Test ;
22
25
23
26
import org .springframework .core .task .AsyncListenableTaskExecutor ;
24
27
25
28
import static org .assertj .core .api .Assertions .assertThat ;
29
+ import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
26
30
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
31
+ import static org .assertj .core .api .InstanceOfAssertFactories .type ;
27
32
28
33
/**
34
+ * Unit tests for {@link ThreadPoolTaskExecutor}.
35
+ *
29
36
* @author Juergen Hoeller
37
+ * @author Sam Brannen
30
38
* @since 5.0.5
31
39
*/
32
40
class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
@@ -50,8 +58,8 @@ void modifyCorePoolSizeWhileRunning() {
50
58
51
59
executor .setCorePoolSize (0 );
52
60
53
- assertThat (executor .getCorePoolSize ()).isEqualTo ( 0 );
54
- assertThat (executor .getThreadPoolExecutor ().getCorePoolSize ()).isEqualTo ( 0 );
61
+ assertThat (executor .getCorePoolSize ()).isZero ( );
62
+ assertThat (executor .getThreadPoolExecutor ().getCorePoolSize ()).isZero ( );
55
63
}
56
64
57
65
@ Test
@@ -112,4 +120,37 @@ void modifyKeepAliveSecondsWithInvalidValueWhileRunning() {
112
120
assertThat (executor .getThreadPoolExecutor ().getKeepAliveTime (TimeUnit .SECONDS )).isEqualTo (60 );
113
121
}
114
122
123
+ @ Test
124
+ void queueCapacityDefault () {
125
+ assertThat (executor .getQueueCapacity ()).isEqualTo (Integer .MAX_VALUE );
126
+ assertThat (executor .getThreadPoolExecutor ().getQueue ())
127
+ .asInstanceOf (type (LinkedBlockingQueue .class ))
128
+ .extracting (BlockingQueue ::remainingCapacity ).isEqualTo (Integer .MAX_VALUE );
129
+ }
130
+
131
+ @ Test
132
+ void queueCapacityZero () {
133
+ executor .setQueueCapacity (0 );
134
+ executor .afterPropertiesSet ();
135
+
136
+ assertThat (executor .getQueueCapacity ()).isZero ();
137
+ assertThat (executor .getThreadPoolExecutor ().getQueue ())
138
+ .asInstanceOf (type (SynchronousQueue .class ))
139
+ .extracting (BlockingQueue ::remainingCapacity ).isEqualTo (0 );
140
+ }
141
+
142
+ @ Test
143
+ void queueSize () {
144
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor ();
145
+
146
+ assertThatIllegalStateException ().isThrownBy (executor ::getThreadPoolExecutor );
147
+ assertThat (executor .getQueueSize ()).isZero ();
148
+
149
+ executor .afterPropertiesSet ();
150
+
151
+ assertThat (executor .getThreadPoolExecutor ()).isNotNull ();
152
+ assertThat (executor .getThreadPoolExecutor ().getQueue ()).isEmpty ();
153
+ assertThat (executor .getQueueSize ()).isZero ();
154
+ }
155
+
115
156
}
0 commit comments