|
|
|
@ -45,18 +45,19 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
abstract class AbstractSchedulingTaskExecutorTests { |
|
|
|
abstract class AbstractSchedulingTaskExecutorTests { |
|
|
|
|
|
|
|
|
|
|
|
static final String THREAD_NAME_PREFIX = "test-"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AsyncListenableTaskExecutor executor; |
|
|
|
private AsyncListenableTaskExecutor executor; |
|
|
|
|
|
|
|
|
|
|
|
protected String testName; |
|
|
|
protected String testName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected String threadNamePrefix; |
|
|
|
|
|
|
|
|
|
|
|
private volatile Object outcome; |
|
|
|
private volatile Object outcome; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
@BeforeEach |
|
|
|
void setUp(TestInfo testInfo) { |
|
|
|
void setUp(TestInfo testInfo) { |
|
|
|
this.testName = testInfo.getTestMethod().get().getName(); |
|
|
|
this.testName = testInfo.getTestMethod().get().getName(); |
|
|
|
|
|
|
|
this.threadNamePrefix = this.testName + "-"; |
|
|
|
this.executor = buildExecutor(); |
|
|
|
this.executor = buildExecutor(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -173,7 +174,7 @@ abstract class AbstractSchedulingTaskExecutorTests { |
|
|
|
TestCallable task = new TestCallable(this.testName, 1); |
|
|
|
TestCallable task = new TestCallable(this.testName, 1); |
|
|
|
Future<String> future = executor.submit(task); |
|
|
|
Future<String> future = executor.submit(task); |
|
|
|
String result = future.get(1000, TimeUnit.MILLISECONDS); |
|
|
|
String result = future.get(1000, TimeUnit.MILLISECONDS); |
|
|
|
assertThat(result.substring(0, THREAD_NAME_PREFIX.length())).isEqualTo(THREAD_NAME_PREFIX); |
|
|
|
assertThat(result.substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -216,7 +217,7 @@ abstract class AbstractSchedulingTaskExecutorTests { |
|
|
|
.atMost(1, TimeUnit.SECONDS) |
|
|
|
.atMost(1, TimeUnit.SECONDS) |
|
|
|
.pollInterval(10, TimeUnit.MILLISECONDS) |
|
|
|
.pollInterval(10, TimeUnit.MILLISECONDS) |
|
|
|
.until(() -> future.isDone() && outcome != null); |
|
|
|
.until(() -> future.isDone() && outcome != null); |
|
|
|
assertThat(outcome.toString().substring(0, THREAD_NAME_PREFIX.length())).isEqualTo(THREAD_NAME_PREFIX); |
|
|
|
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -246,8 +247,8 @@ abstract class AbstractSchedulingTaskExecutorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assertThreadNamePrefix(TestTask task) { |
|
|
|
protected void assertThreadNamePrefix(TestTask task) { |
|
|
|
assertThat(task.lastThread.getName().substring(0, THREAD_NAME_PREFIX.length())).isEqualTo(THREAD_NAME_PREFIX); |
|
|
|
assertThat(task.lastThread.getName().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void await(TestTask task) { |
|
|
|
private void await(TestTask task) { |
|
|
|
|