@@ -211,6 +211,14 @@ public void testCachedExecutorType() throws InterruptedException {
211211 }
212212 }
213213
214+ private static int getExpectedThreadPoolSize (Settings settings , String name , int size ) {
215+ if (name .equals (ThreadPool .Names .BULK ) || name .equals (ThreadPool .Names .INDEX )) {
216+ return Math .min (size , EsExecutors .boundedNumberOfProcessors (settings ));
217+ } else {
218+ return size ;
219+ }
220+ }
221+
214222 public void testFixedExecutorType () throws InterruptedException {
215223 String threadPoolName = randomThreadPool (ThreadPool .ThreadPoolType .FIXED );
216224 ThreadPool threadPool = null ;
@@ -225,12 +233,14 @@ public void testFixedExecutorType() throws InterruptedException {
225233 Settings settings = clusterSettings .applySettings (settingsBuilder ()
226234 .put ("threadpool." + threadPoolName + ".size" , "15" )
227235 .build ());
236+
237+ int expectedSize = getExpectedThreadPoolSize (nodeSettings , threadPoolName , 15 );
228238 assertEquals (info (threadPool , threadPoolName ).getThreadPoolType (), ThreadPool .ThreadPoolType .FIXED );
229239 assertThat (threadPool .executor (threadPoolName ), instanceOf (EsThreadPoolExecutor .class ));
230- assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getCorePoolSize (), equalTo (15 ));
231- assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getMaximumPoolSize (), equalTo (15 ));
232- assertThat (info (threadPool , threadPoolName ).getMin (), equalTo (15 ));
233- assertThat (info (threadPool , threadPoolName ).getMax (), equalTo (15 ));
240+ assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getCorePoolSize (), equalTo (expectedSize ));
241+ assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getMaximumPoolSize (), equalTo (expectedSize ));
242+ assertThat (info (threadPool , threadPoolName ).getMin (), equalTo (expectedSize ));
243+ assertThat (info (threadPool , threadPoolName ).getMax (), equalTo (expectedSize ));
234244 // keep alive does not apply to fixed thread pools
235245 assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getKeepAliveTime (TimeUnit .MINUTES ), equalTo (0L ));
236246
@@ -240,20 +250,23 @@ public void testFixedExecutorType() throws InterruptedException {
240250 // Make sure keep alive value is not used
241251 assertThat (info (threadPool , threadPoolName ).getKeepAlive (), nullValue ());
242252 // Make sure keep pool size value were reused
243- assertThat (info (threadPool , threadPoolName ).getMin (), equalTo (15 ));
244- assertThat (info (threadPool , threadPoolName ).getMax (), equalTo (15 ));
253+ assertThat (info (threadPool , threadPoolName ).getMin (), equalTo (expectedSize ));
254+ assertThat (info (threadPool , threadPoolName ).getMax (), equalTo (expectedSize ));
245255 assertThat (threadPool .executor (threadPoolName ), instanceOf (EsThreadPoolExecutor .class ));
246- assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getCorePoolSize (), equalTo (15 ));
247- assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getMaximumPoolSize (), equalTo (15 ));
256+ assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getCorePoolSize (), equalTo (expectedSize ));
257+ assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getMaximumPoolSize (), equalTo (expectedSize ));
248258
249259 // Change size
250260 Executor oldExecutor = threadPool .executor (threadPoolName );
251261 settings = clusterSettings .applySettings (settingsBuilder ().put (settings ).put ("threadpool." + threadPoolName + ".size" , "10" ).build ());
262+
263+ expectedSize = getExpectedThreadPoolSize (nodeSettings , threadPoolName , 10 );
264+
252265 // Make sure size values changed
253- assertThat (info (threadPool , threadPoolName ).getMax (), equalTo (10 ));
254- assertThat (info (threadPool , threadPoolName ).getMin (), equalTo (10 ));
255- assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getMaximumPoolSize (), equalTo (10 ));
256- assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getCorePoolSize (), equalTo (10 ));
266+ assertThat (info (threadPool , threadPoolName ).getMax (), equalTo (expectedSize ));
267+ assertThat (info (threadPool , threadPoolName ).getMin (), equalTo (expectedSize ));
268+ assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getMaximumPoolSize (), equalTo (expectedSize ));
269+ assertThat (((EsThreadPoolExecutor ) threadPool .executor (threadPoolName )).getCorePoolSize (), equalTo (expectedSize ));
257270 // Make sure executor didn't change
258271 assertEquals (info (threadPool , threadPoolName ).getThreadPoolType (), ThreadPool .ThreadPoolType .FIXED );
259272 assertThat (threadPool .executor (threadPoolName ), sameInstance (oldExecutor ));
0 commit comments