17
17
18
18
import io .github .resilience4j .bulkhead .BulkheadConfig ;
19
19
import io .github .resilience4j .bulkhead .ThreadPoolBulkheadConfig ;
20
+ import io .github .resilience4j .common .CompositeCustomizer ;
20
21
import io .github .resilience4j .core .ConfigurationNotFoundException ;
21
- import io .vavr .Tuple ;
22
- import io .vavr .Tuple2 ;
23
22
import org .junit .Test ;
24
23
25
24
import java .time .Duration ;
25
+ import java .util .Collections ;
26
26
import java .util .HashMap ;
27
27
import java .util .Map ;
28
28
@@ -46,21 +46,21 @@ public void tesFixedThreadPoolBulkHeadProperties() {
46
46
ThreadPoolBulkheadConfigurationProperties bulkheadConfigurationProperties = new ThreadPoolBulkheadConfigurationProperties ();
47
47
bulkheadConfigurationProperties .getBackends ().put ("backend1" , backendProperties1 );
48
48
bulkheadConfigurationProperties .getBackends ().put ("backend2" , backendProperties2 );
49
- Map <String ,String > tags = new HashMap <>();
50
- tags .put ("testKey1" ,"testKet2" );
49
+ Map <String , String > tags = new HashMap <>();
50
+ tags .put ("testKey1" , "testKet2" );
51
51
bulkheadConfigurationProperties .setTags (tags );
52
52
53
53
//Then
54
54
assertThat (bulkheadConfigurationProperties .getTags ()).isNotEmpty ();
55
55
assertThat (bulkheadConfigurationProperties .getBackends ().size ()).isEqualTo (2 );
56
56
assertThat (bulkheadConfigurationProperties .getInstances ().size ()).isEqualTo (2 );
57
57
ThreadPoolBulkheadConfig bulkhead1 = bulkheadConfigurationProperties
58
- .createThreadPoolBulkheadConfig ("backend1" );
58
+ .createThreadPoolBulkheadConfig ("backend1" , compositeThreadPoolBulkheadCustomizer () );
59
59
assertThat (bulkhead1 ).isNotNull ();
60
60
assertThat (bulkhead1 .getCoreThreadPoolSize ()).isEqualTo (1 );
61
61
62
62
ThreadPoolBulkheadConfig bulkhead2 = bulkheadConfigurationProperties
63
- .createThreadPoolBulkheadConfig ("backend2" );
63
+ .createThreadPoolBulkheadConfig ("backend2" , compositeThreadPoolBulkheadCustomizer () );
64
64
assertThat (bulkhead2 ).isNotNull ();
65
65
assertThat (bulkhead2 .getCoreThreadPoolSize ()).isEqualTo (2 );
66
66
@@ -102,19 +102,22 @@ public void testCreateThreadPoolBulkHeadPropertiesWithSharedConfigs() {
102
102
assertThat (bulkheadConfigurationProperties .getBackends ().size ()).isEqualTo (2 );
103
103
// Should get default config and core number
104
104
ThreadPoolBulkheadConfig bulkhead1 = bulkheadConfigurationProperties
105
- .createThreadPoolBulkheadConfig ("backendWithDefaultConfig" );
105
+ .createThreadPoolBulkheadConfig ("backendWithDefaultConfig" ,
106
+ compositeThreadPoolBulkheadCustomizer ());
106
107
assertThat (bulkhead1 ).isNotNull ();
107
108
assertThat (bulkhead1 .getCoreThreadPoolSize ()).isEqualTo (3 );
108
109
assertThat (bulkhead1 .getQueueCapacity ()).isEqualTo (1 );
109
110
// Should get shared config and overwrite core number
110
111
ThreadPoolBulkheadConfig bulkhead2 = bulkheadConfigurationProperties
111
- .createThreadPoolBulkheadConfig ("backendWithSharedConfig" );
112
+ .createThreadPoolBulkheadConfig ("backendWithSharedConfig" ,
113
+ compositeThreadPoolBulkheadCustomizer ());
112
114
assertThat (bulkhead2 ).isNotNull ();
113
115
assertThat (bulkhead2 .getCoreThreadPoolSize ()).isEqualTo (4 );
114
116
assertThat (bulkhead2 .getQueueCapacity ()).isEqualTo (2 );
115
117
// Unknown backend should get default config of Registry
116
118
ThreadPoolBulkheadConfig bulkhead3 = bulkheadConfigurationProperties
117
- .createThreadPoolBulkheadConfig ("unknownBackend" );
119
+ .createThreadPoolBulkheadConfig ("unknownBackend" ,
120
+ compositeThreadPoolBulkheadCustomizer ());
118
121
assertThat (bulkhead3 ).isNotNull ();
119
122
assertThat (bulkhead3 .getCoreThreadPoolSize ())
120
123
.isEqualTo (ThreadPoolBulkheadConfig .DEFAULT_CORE_THREAD_POOL_SIZE );
@@ -140,19 +143,19 @@ public void testBulkHeadProperties() {
140
143
BulkheadConfigurationProperties bulkheadConfigurationProperties = new BulkheadConfigurationProperties ();
141
144
bulkheadConfigurationProperties .getInstances ().put ("backend1" , instanceProperties1 );
142
145
bulkheadConfigurationProperties .getInstances ().put ("backend2" , instanceProperties2 );
143
- Map <String ,String > globalTags = new HashMap <>();
144
- globalTags .put ("testKey1" ,"testKet2" );
146
+ Map <String , String > globalTags = new HashMap <>();
147
+ globalTags .put ("testKey1" , "testKet2" );
145
148
bulkheadConfigurationProperties .setTags (globalTags );
146
149
//Then
147
150
assertThat (bulkheadConfigurationProperties .getInstances ().size ()).isEqualTo (2 );
148
151
assertThat (bulkheadConfigurationProperties .getTags ()).isNotEmpty ();
149
152
BulkheadConfig bulkhead1 = bulkheadConfigurationProperties
150
- .createBulkheadConfig (instanceProperties1 );
153
+ .createBulkheadConfig (instanceProperties1 , compositeBulkheadCustomizer (), "backend1" );
151
154
assertThat (bulkhead1 ).isNotNull ();
152
155
assertThat (bulkhead1 .getMaxConcurrentCalls ()).isEqualTo (3 );
153
156
154
157
BulkheadConfig bulkhead2 = bulkheadConfigurationProperties
155
- .createBulkheadConfig (instanceProperties2 );
158
+ .createBulkheadConfig (instanceProperties2 , compositeBulkheadCustomizer (), "backend2" );
156
159
assertThat (bulkhead2 ).isNotNull ();
157
160
assertThat (bulkhead2 .getMaxConcurrentCalls ()).isEqualTo (2 );
158
161
@@ -196,21 +199,24 @@ public void testCreateBulkHeadPropertiesWithSharedConfigs() {
196
199
197
200
// Should get default config and overwrite max calls and wait time
198
201
BulkheadConfig bulkhead1 = bulkheadConfigurationProperties
199
- .createBulkheadConfig (backendWithDefaultConfig );
202
+ .createBulkheadConfig (backendWithDefaultConfig , compositeBulkheadCustomizer (),
203
+ "backendWithDefaultConfig" );
200
204
assertThat (bulkhead1 ).isNotNull ();
201
205
assertThat (bulkhead1 .getMaxConcurrentCalls ()).isEqualTo (3 );
202
206
assertThat (bulkhead1 .getMaxWaitDuration ().toMillis ()).isEqualTo (200L );
203
207
204
208
// Should get shared config and overwrite wait time
205
209
BulkheadConfig bulkhead2 = bulkheadConfigurationProperties
206
- .createBulkheadConfig (backendWithSharedConfig );
210
+ .createBulkheadConfig (backendWithSharedConfig , compositeBulkheadCustomizer (),
211
+ "backendWithSharedConfig" );
207
212
assertThat (bulkhead2 ).isNotNull ();
208
213
assertThat (bulkhead2 .getMaxConcurrentCalls ()).isEqualTo (2 );
209
214
assertThat (bulkhead2 .getMaxWaitDuration ().toMillis ()).isEqualTo (300L );
210
215
211
216
// Unknown backend should get default config of Registry
212
217
BulkheadConfig bulkhead3 = bulkheadConfigurationProperties
213
- .createBulkheadConfig (new BulkheadConfigurationProperties .InstanceProperties ());
218
+ .createBulkheadConfig (new BulkheadConfigurationProperties .InstanceProperties (),
219
+ compositeBulkheadCustomizer (), "unknown" );
214
220
assertThat (bulkhead3 ).isNotNull ();
215
221
assertThat (bulkhead3 .getMaxWaitDuration ().toMillis ()).isEqualTo (0L );
216
222
@@ -226,7 +232,8 @@ public void testCreateBulkHeadPropertiesWithUnknownConfig() {
226
232
227
233
//When
228
234
assertThatThrownBy (
229
- () -> bulkheadConfigurationProperties .createBulkheadConfig (instanceProperties ))
235
+ () -> bulkheadConfigurationProperties .createBulkheadConfig (instanceProperties ,
236
+ compositeBulkheadCustomizer (), "unknownConfig" ))
230
237
.isInstanceOf (ConfigurationNotFoundException .class )
231
238
.hasMessage ("Configuration with name 'unknownConfig' does not exist" );
232
239
}
@@ -255,4 +262,12 @@ public void testThreadPoolBulkheadIllegalArgumentOnEventConsumerBufferSize() {
255
262
defaultProperties .setEventConsumerBufferSize (-1 );
256
263
}
257
264
265
+ private CompositeCustomizer <BulkheadConfigCustomizer > compositeBulkheadCustomizer () {
266
+ return new CompositeCustomizer <>(Collections .emptyList ());
267
+ }
268
+
269
+ private CompositeCustomizer <ThreadPoolBulkheadConfigCustomizer > compositeThreadPoolBulkheadCustomizer () {
270
+ return new CompositeCustomizer <>(Collections .emptyList ());
271
+ }
272
+
258
273
}
0 commit comments