Browse Source

Polishing

pull/32754/head
Juergen Hoeller 2 years ago
parent
commit
51d70dcf34
  1. 3
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java
  2. 8
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
  3. 8
      spring-context/src/test/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutorTests.java
  4. 8
      spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java

3
spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -177,6 +177,7 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
* @see Clock#systemDefaultZone() * @see Clock#systemDefaultZone()
*/ */
public void setClock(Clock clock) { public void setClock(Clock clock) {
Assert.notNull(clock, "Clock must not be null");
this.clock = clock; this.clock = clock;
} }

8
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,8 +45,9 @@ import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureTask; import org.springframework.util.concurrent.ListenableFutureTask;
/** /**
* Implementation of Spring's {@link TaskScheduler} interface, wrapping * A standard implementation of Spring's {@link TaskScheduler} interface, wrapping
* a native {@link java.util.concurrent.ScheduledThreadPoolExecutor}. * a native {@link java.util.concurrent.ScheduledThreadPoolExecutor} and providing
* all applicable configuration options for it.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Mark Fisher * @author Mark Fisher
@ -154,6 +155,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
* @see Clock#systemDefaultZone() * @see Clock#systemDefaultZone()
*/ */
public void setClock(Clock clock) { public void setClock(Clock clock) {
Assert.notNull(clock, "Clock must not be null");
this.clock = clock; this.clock = clock;
} }

8
spring-context/src/test/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@
package org.springframework.scheduling.concurrent; package org.springframework.scheduling.concurrent;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -52,8 +52,8 @@ class ConcurrentTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
@AfterEach @AfterEach
void shutdownExecutor() { void shutdownExecutor() {
for (Runnable task : concurrentExecutor.shutdownNow()) { for (Runnable task : concurrentExecutor.shutdownNow()) {
if (task instanceof RunnableFuture) { if (task instanceof Future) {
((RunnableFuture<?>) task).cancel(true); ((Future<?>) task).cancel(true);
} }
} }
} }

8
spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Sam Brannen * @author Sam Brannen
* @since 3.0 * @since 3.0
*/ */
public class ThreadPoolTaskSchedulerTests extends AbstractSchedulingTaskExecutorTests { class ThreadPoolTaskSchedulerTests extends AbstractSchedulingTaskExecutorTests {
private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
@ -97,7 +97,7 @@ public class ThreadPoolTaskSchedulerTests extends AbstractSchedulingTaskExecutor
} }
@Test @Test
void scheduleOneTimeFailingTaskWithoutErrorHandler() throws Exception { void scheduleOneTimeFailingTaskWithoutErrorHandler() {
TestTask task = new TestTask(this.testName, 0); TestTask task = new TestTask(this.testName, 0);
Future<?> future = scheduler.schedule(task, new Date()); Future<?> future = scheduler.schedule(task, new Date());
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS)); assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS));
@ -149,7 +149,7 @@ public class ThreadPoolTaskSchedulerTests extends AbstractSchedulingTaskExecutor
catch (InterruptedException ex) { catch (InterruptedException ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} }
assertThat(latch.getCount()).as("latch did not count down,").isEqualTo(0); assertThat(latch.getCount()).as("latch did not count down").isEqualTo(0);
} }

Loading…
Cancel
Save