Merge branch '5.3.x'

This commit is contained in:
Sam Brannen
2022-06-08 16:40:23 +02:00
2 changed files with 70 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
package org.springframework.scheduling.concurrent;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@@ -23,10 +26,15 @@ import org.junit.jupiter.api.Test;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
/**
* Unit tests for {@link ThreadPoolTaskExecutor}.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 5.0.5
*/
class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
@@ -50,8 +58,8 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
executor.setCorePoolSize(0);
assertThat(executor.getCorePoolSize()).isEqualTo(0);
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(0);
assertThat(executor.getCorePoolSize()).isZero();
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isZero();
}
@Test
@@ -112,4 +120,37 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
}
@Test
void queueCapacityDefault() {
assertThat(executor.getQueueCapacity()).isEqualTo(Integer.MAX_VALUE);
assertThat(executor.getThreadPoolExecutor().getQueue())
.asInstanceOf(type(LinkedBlockingQueue.class))
.extracting(BlockingQueue::remainingCapacity).isEqualTo(Integer.MAX_VALUE);
}
@Test
void queueCapacityZero() {
executor.setQueueCapacity(0);
executor.afterPropertiesSet();
assertThat(executor.getQueueCapacity()).isZero();
assertThat(executor.getThreadPoolExecutor().getQueue())
.asInstanceOf(type(SynchronousQueue.class))
.extracting(BlockingQueue::remainingCapacity).isEqualTo(0);
}
@Test
void queueSize() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
assertThatIllegalStateException().isThrownBy(executor::getThreadPoolExecutor);
assertThat(executor.getQueueSize()).isZero();
executor.afterPropertiesSet();
assertThat(executor.getThreadPoolExecutor()).isNotNull();
assertThat(executor.getThreadPoolExecutor().getQueue()).isEmpty();
assertThat(executor.getQueueSize()).isZero();
}
}