Skip to content

Commit 9d71549

Browse files
committed
Polishing
(cherry picked from commit 6e5af9d)
1 parent 24893d0 commit 9d71549

File tree

13 files changed

+125
-131
lines changed

13 files changed

+125
-131
lines changed

integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,8 +60,8 @@ void failsWhenJdkProxyAndScheduledMethodNotPresentOnInterface() {
6060
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
6161
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class);
6262
assertThatExceptionOfType(BeanCreationException.class)
63-
.isThrownBy(ctx::refresh)
64-
.withCauseInstanceOf(IllegalStateException.class);
63+
.isThrownBy(ctx::refresh)
64+
.withCauseInstanceOf(IllegalStateException.class);
6565
}
6666

6767
@Test
@@ -70,7 +70,7 @@ void succeedsWhenSubclassProxyAndScheduledMethodNotPresentOnInterface() throws I
7070
ctx.register(Config.class, SubclassProxyTxConfig.class, RepoConfigA.class);
7171
ctx.refresh();
7272

73-
Thread.sleep(100); // allow @Scheduled method to be called several times
73+
Thread.sleep(200); // allow @Scheduled method to be called several times
7474

7575
MyRepository repository = ctx.getBean(MyRepository.class);
7676
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
@@ -85,7 +85,7 @@ void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws Interru
8585
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigB.class);
8686
ctx.refresh();
8787

88-
Thread.sleep(100); // allow @Scheduled method to be called several times
88+
Thread.sleep(200); // allow @Scheduled method to be called several times
8989

9090
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
9191
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
@@ -100,7 +100,7 @@ void withAspectConfig() throws InterruptedException {
100100
ctx.register(AspectConfig.class, MyRepositoryWithScheduledMethodImpl.class);
101101
ctx.refresh();
102102

103-
Thread.sleep(100); // allow @Scheduled method to be called several times
103+
Thread.sleep(200); // allow @Scheduled method to be called several times
104104

105105
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
106106
assertThat(AopUtils.isCglibProxy(repository)).isTrue();

spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,9 +77,7 @@ public void testCorrectHandlerUsed() throws Throwable {
7777
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
7878
given(mi.getThis()).willReturn(new Object());
7979
given(mi.proceed()).willThrow(ex);
80-
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() ->
81-
ti.invoke(mi))
82-
.isSameAs(ex);
80+
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
8381
assertThat(th.getCalls()).isEqualTo(1);
8482
assertThat(th.getCalls("ioException")).isEqualTo(1);
8583
}
@@ -92,9 +90,7 @@ public void testCorrectHandlerUsedForSubclass() throws Throwable {
9290
ConnectException ex = new ConnectException("");
9391
MethodInvocation mi = mock(MethodInvocation.class);
9492
given(mi.proceed()).willThrow(ex);
95-
assertThatExceptionOfType(ConnectException.class).isThrownBy(() ->
96-
ti.invoke(mi))
97-
.isSameAs(ex);
93+
assertThatExceptionOfType(ConnectException.class).isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
9894
assertThat(th.getCalls()).isEqualTo(1);
9995
assertThat(th.getCalls("remoteException")).isEqualTo(1);
10096
}
@@ -117,9 +113,7 @@ public void afterThrowing(RemoteException ex) throws Throwable {
117113
ConnectException ex = new ConnectException("");
118114
MethodInvocation mi = mock(MethodInvocation.class);
119115
given(mi.proceed()).willThrow(ex);
120-
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
121-
ti.invoke(mi))
122-
.isSameAs(t);
116+
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> ti.invoke(mi)).isSameAs(t);
123117
assertThat(th.getCalls()).isEqualTo(1);
124118
assertThat(th.getCalls("remoteException")).isEqualTo(1);
125119
}

spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -114,7 +114,7 @@ void schedulerWithTaskExecutor() throws Exception {
114114
trigger.setName("myTrigger");
115115
trigger.setJobDetail(jobDetail);
116116
trigger.setStartDelay(1);
117-
trigger.setRepeatInterval(500);
117+
trigger.setRepeatInterval(100);
118118
trigger.setRepeatCount(1);
119119
trigger.afterPropertiesSet();
120120

@@ -126,14 +126,14 @@ void schedulerWithTaskExecutor() throws Exception {
126126
bean.start();
127127

128128
Thread.sleep(500);
129-
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
129+
assertThat(DummyJob.count).as("DummyJob should have been executed at least once.").isGreaterThan(0);
130130
assertThat(taskExecutor.count).isEqualTo(DummyJob.count);
131131

132132
bean.destroy();
133133
}
134134

135135
@Test
136-
@SuppressWarnings({ "unchecked", "rawtypes" })
136+
@SuppressWarnings({"unchecked", "rawtypes"})
137137
void jobDetailWithRunnableInsteadOfJob() {
138138
JobDetailImpl jobDetail = new JobDetailImpl();
139139
assertThatIllegalArgumentException().isThrownBy(() ->
@@ -156,7 +156,7 @@ void schedulerWithQuartzJobBean() throws Exception {
156156
trigger.setName("myTrigger");
157157
trigger.setJobDetail(jobDetail);
158158
trigger.setStartDelay(1);
159-
trigger.setRepeatInterval(500);
159+
trigger.setRepeatInterval(100);
160160
trigger.setRepeatCount(1);
161161
trigger.afterPropertiesSet();
162162

@@ -168,7 +168,7 @@ void schedulerWithQuartzJobBean() throws Exception {
168168

169169
Thread.sleep(500);
170170
assertThat(DummyJobBean.param).isEqualTo(10);
171-
assertThat(DummyJobBean.count > 0).isTrue();
171+
assertThat(DummyJobBean.count).isGreaterThan(0);
172172

173173
bean.destroy();
174174
}
@@ -190,7 +190,7 @@ void schedulerWithSpringBeanJobFactory() throws Exception {
190190
trigger.setName("myTrigger");
191191
trigger.setJobDetail(jobDetail);
192192
trigger.setStartDelay(1);
193-
trigger.setRepeatInterval(500);
193+
trigger.setRepeatInterval(100);
194194
trigger.setRepeatCount(1);
195195
trigger.afterPropertiesSet();
196196

@@ -203,7 +203,7 @@ void schedulerWithSpringBeanJobFactory() throws Exception {
203203

204204
Thread.sleep(500);
205205
assertThat(DummyJob.param).isEqualTo(10);
206-
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
206+
assertThat(DummyJob.count).as("DummyJob should have been executed at least once.").isGreaterThan(0);
207207

208208
bean.destroy();
209209
}
@@ -225,7 +225,7 @@ void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Except
225225
trigger.setName("myTrigger");
226226
trigger.setJobDetail(jobDetail);
227227
trigger.setStartDelay(1);
228-
trigger.setRepeatInterval(500);
228+
trigger.setRepeatInterval(100);
229229
trigger.setRepeatCount(1);
230230
trigger.afterPropertiesSet();
231231

@@ -239,7 +239,7 @@ void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Except
239239

240240
Thread.sleep(500);
241241
assertThat(DummyJob.param).isEqualTo(0);
242-
assertThat(DummyJob.count == 0).isTrue();
242+
assertThat(DummyJob.count).isEqualTo(0);
243243

244244
bean.destroy();
245245
}
@@ -260,7 +260,7 @@ void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
260260
trigger.setName("myTrigger");
261261
trigger.setJobDetail(jobDetail);
262262
trigger.setStartDelay(1);
263-
trigger.setRepeatInterval(500);
263+
trigger.setRepeatInterval(100);
264264
trigger.setRepeatCount(1);
265265
trigger.afterPropertiesSet();
266266

@@ -273,7 +273,7 @@ void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
273273

274274
Thread.sleep(500);
275275
assertThat(DummyJobBean.param).isEqualTo(10);
276-
assertThat(DummyJobBean.count > 0).isTrue();
276+
assertThat(DummyJobBean.count).isGreaterThan(0);
277277

278278
bean.destroy();
279279
}
@@ -292,7 +292,7 @@ void schedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception {
292292

293293
Thread.sleep(500);
294294
assertThat(DummyJob.param).isEqualTo(10);
295-
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
295+
assertThat(DummyJob.count).as("DummyJob should have been executed at least once.").isGreaterThan(0);
296296

297297
bean.destroy();
298298
}

spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -329,8 +329,8 @@ protected void registerBeanDefinition(BeanDefinitionHolder definitionHolder, Bea
329329
* @return {@code true} if the bean can be registered as-is;
330330
* {@code false} if it should be skipped because there is an
331331
* existing, compatible bean definition for the specified name
332-
* @throws ConflictingBeanDefinitionException if an existing, incompatible
333-
* bean definition has been found for the specified name
332+
* @throws IllegalStateException if an existing, incompatible bean definition
333+
* has been found for the specified name
334334
*/
335335
protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException {
336336
if (!this.registry.containsBeanDefinition(beanName)) {
@@ -354,16 +354,16 @@ protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition)
354354
* the given existing bean definition.
355355
* <p>The default implementation considers them as compatible when the existing
356356
* bean definition comes from the same source or from a non-scanning source.
357-
* @param newDefinition the new bean definition, originated from scanning
358-
* @param existingDefinition the existing bean definition, potentially an
357+
* @param newDef the new bean definition, originated from scanning
358+
* @param existingDef the existing bean definition, potentially an
359359
* explicitly defined one or a previously generated one from scanning
360360
* @return whether the definitions are considered as compatible, with the
361361
* new definition to be skipped in favor of the existing definition
362362
*/
363-
protected boolean isCompatible(BeanDefinition newDefinition, BeanDefinition existingDefinition) {
364-
return (!(existingDefinition instanceof ScannedGenericBeanDefinition) || // explicitly registered overriding bean
365-
(newDefinition.getSource() != null && newDefinition.getSource().equals(existingDefinition.getSource())) || // scanned same file twice
366-
newDefinition.equals(existingDefinition)); // scanned equivalent class twice
363+
protected boolean isCompatible(BeanDefinition newDef, BeanDefinition existingDef) {
364+
return (!(existingDef instanceof ScannedGenericBeanDefinition) || // explicitly registered overriding bean
365+
(newDef.getSource() != null && newDef.getSource().equals(existingDef.getSource())) || // scanned same file twice
366+
newDef.equals(existingDef)); // scanned equivalent class twice
367367
}
368368

369369

spring-context/src/test/java/org/springframework/context/annotation/ClassPathBeanDefinitionScannerTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void testSimpleScanWithDefaultFiltersAndOverridingBean() {
197197
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
198198
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
199199
scanner.setIncludeAnnotationConfig(false);
200+
200201
// should not fail!
201202
scanner.scan(BASE_PACKAGE);
202203
}
@@ -207,6 +208,7 @@ public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
207208
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
208209
scanner.setIncludeAnnotationConfig(false);
209210
scanner.scan("org.springframework.context.annotation3");
211+
210212
assertThatIllegalStateException().isThrownBy(() -> scanner.scan(BASE_PACKAGE))
211213
.withMessageContaining("stubFooDao")
212214
.withMessageContaining(StubFooDao.class.getName());

spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,6 @@
2424
import java.util.concurrent.CompletionStage;
2525
import java.util.function.Function;
2626

27-
import kotlinx.coroutines.CompletableDeferredKt;
28-
import kotlinx.coroutines.Deferred;
2927
import org.reactivestreams.Publisher;
3028
import reactor.blockhound.BlockHound;
3129
import reactor.blockhound.integration.BlockHoundIntegration;
@@ -39,13 +37,14 @@
3937
import org.springframework.util.ReflectionUtils;
4038

4139
/**
42-
* A registry of adapters to adapt Reactive Streams {@link Publisher} to/from
43-
* various async/reactive types such as {@code CompletableFuture}, RxJava
44-
* {@code Flowable}, and others.
40+
* A registry of adapters to adapt Reactive Streams {@link Publisher} to/from various
41+
* async/reactive types such as {@code CompletableFuture}, RxJava {@code Flowable}, etc.
42+
* This is designed to complement Spring's Reactor {@code Mono}/{@code Flux} support while
43+
* also being usable without Reactor, e.g. just for {@code org.reactivestreams} bridging.
4544
*
46-
* <p>By default, depending on classpath availability, adapters are registered
47-
* for Reactor, RxJava 3, {@link CompletableFuture}, {@code Flow.Publisher},
48-
* and Kotlin Coroutines' {@code Deferred} and {@code Flow}.
45+
* <p>By default, depending on classpath availability, adapters are registered for Reactor
46+
* (including {@code CompletableFuture} and {@code Flow.Publisher} adapters), RxJava 3,
47+
* Kotlin Coroutines' {@code Deferred} (bridged via Reactor) and SmallRye Mutiny 1.x.
4948
*
5049
* <p><strong>Note:</strong> As of Spring Framework 5.3.11, support for
5150
* RxJava 1.x and 2.x is deprecated in favor of RxJava 3.
@@ -401,9 +400,9 @@ private static class CoroutinesRegistrar {
401400
@SuppressWarnings("KotlinInternalInJava")
402401
void registerAdapters(ReactiveAdapterRegistry registry) {
403402
registry.registerReactiveType(
404-
ReactiveTypeDescriptor.singleOptionalValue(Deferred.class,
405-
() -> CompletableDeferredKt.CompletableDeferred(null)),
406-
source -> CoroutinesUtils.deferredToMono((Deferred<?>) source),
403+
ReactiveTypeDescriptor.singleOptionalValue(kotlinx.coroutines.Deferred.class,
404+
() -> kotlinx.coroutines.CompletableDeferredKt.CompletableDeferred(null)),
405+
source -> CoroutinesUtils.deferredToMono((kotlinx.coroutines.Deferred<?>) source),
407406
source -> CoroutinesUtils.monoToDeferred(Mono.from(source)));
408407

409408
registry.registerReactiveType(

spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public final class ReactiveTypeDescriptor {
3737
private final boolean noValue;
3838

3939
@Nullable
40-
private final Supplier<?> emptyValueSupplier;
40+
private final Supplier<?> emptySupplier;
4141

4242
private final boolean deferred;
4343

@@ -55,7 +55,7 @@ private ReactiveTypeDescriptor(Class<?> reactiveType, boolean multiValue, boolea
5555
this.reactiveType = reactiveType;
5656
this.multiValue = multiValue;
5757
this.noValue = noValue;
58-
this.emptyValueSupplier = emptySupplier;
58+
this.emptySupplier = emptySupplier;
5959
this.deferred = deferred;
6060
}
6161

@@ -89,16 +89,16 @@ public boolean isNoValue() {
8989
* Return {@code true} if the reactive type can complete with no values.
9090
*/
9191
public boolean supportsEmpty() {
92-
return (this.emptyValueSupplier != null);
92+
return (this.emptySupplier != null);
9393
}
9494

9595
/**
9696
* Return an empty-value instance for the underlying reactive or async type.
97-
* Use of this type implies {@link #supportsEmpty()} is {@code true}.
97+
* <p>Use of this type implies {@link #supportsEmpty()} is {@code true}.
9898
*/
9999
public Object getEmptyValue() {
100-
Assert.state(this.emptyValueSupplier != null, "Empty values not supported");
101-
return this.emptyValueSupplier.get();
100+
Assert.state(this.emptySupplier != null, "Empty values not supported");
101+
return this.emptySupplier.get();
102102
}
103103

104104
/**

0 commit comments

Comments
 (0)