public void testThreadPoolCanNotOverrideThreadPoolType() throws InterruptedException { String threadPoolName = randomThreadPoolName(); ThreadPool.ThreadPoolType incorrectThreadPoolType = randomIncorrectThreadPoolType(threadPoolName); ThreadPool.ThreadPoolType correctThreadPoolType = ThreadPool.THREAD_POOL_TYPES.get(threadPoolName); ThreadPool threadPool = null; try { threadPool = new ThreadPool( Settings.builder() .put("node.name", "testThreadPoolCanNotOverrideThreadPoolType") .put("threadpool." + threadPoolName + ".type", incorrectThreadPoolType.getType()) .build()); terminate(threadPool); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat( e.getMessage(), is( "setting threadpool." + threadPoolName + ".type to " + incorrectThreadPoolType.getType() + " is not permitted; must be " + correctThreadPoolType.getType())); } finally { terminateThreadPoolIfNeeded(threadPool); } }
public void testUpdateSettingsCanNotChangeThreadPoolType() throws InterruptedException { String threadPoolName = randomThreadPoolName(); ThreadPool.ThreadPoolType invalidThreadPoolType = randomIncorrectThreadPoolType(threadPoolName); ThreadPool.ThreadPoolType validThreadPoolType = ThreadPool.THREAD_POOL_TYPES.get(threadPoolName); ThreadPool threadPool = null; try { threadPool = new ThreadPool( Settings.builder() .put("node.name", "testUpdateSettingsCanNotChangeThreadPoolType") .build()); ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); clusterSettings.applySettings( Settings.builder() .put("threadpool." + threadPoolName + ".type", invalidThreadPoolType.getType()) .build()); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertEquals( "illegal value can't update [threadpool.] from [{}] to [{" + threadPoolName + ".type=" + invalidThreadPoolType.getType() + "}]", e.getMessage()); assertThat( e.getCause().getMessage(), is( "setting threadpool." + threadPoolName + ".type to " + invalidThreadPoolType.getType() + " is not permitted; must be " + validThreadPoolType.getType())); } finally { terminateThreadPoolIfNeeded(threadPool); } }
public void testCorrectThreadPoolTypePermittedInSettings() throws InterruptedException { String threadPoolName = randomThreadPoolName(); ThreadPool.ThreadPoolType correctThreadPoolType = ThreadPool.THREAD_POOL_TYPES.get(threadPoolName); ThreadPool threadPool = null; try { threadPool = new ThreadPool( Settings.builder() .put("node.name", "testCorrectThreadPoolTypePermittedInSettings") .put("threadpool." + threadPoolName + ".type", correctThreadPoolType.getType()) .build()); ThreadPool.Info info = info(threadPool, threadPoolName); if (ThreadPool.Names.SAME.equals(threadPoolName)) { assertNull(info); // we don't report on the "same" threadpool } else { // otherwise check we have the expected type assertEquals(info.getThreadPoolType(), correctThreadPoolType); } } finally { terminateThreadPoolIfNeeded(threadPool); } }
private ThreadPool.ThreadPoolType randomIncorrectThreadPoolType(String threadPoolName) { Set<ThreadPool.ThreadPoolType> set = new HashSet<>(); set.addAll(Arrays.asList(ThreadPool.ThreadPoolType.values())); set.remove(ThreadPool.THREAD_POOL_TYPES.get(threadPoolName)); return randomFrom(set.toArray(new ThreadPool.ThreadPoolType[set.size()])); }