Skip to content

Commit 6e5af9d

Browse files
committed
Polishing
1 parent 4a81814 commit 6e5af9d

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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();
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();
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -133,7 +133,7 @@ void schedulerWithTaskExecutor() throws Exception {
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

@@ -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

@@ -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

@@ -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

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.concurrent.Flow;
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.adapter.JdkFlowAdapter;
3129
import reactor.blockhound.BlockHound;
@@ -38,13 +36,14 @@
3836
import org.springframework.util.ConcurrentReferenceHashMap;
3937

4038
/**
41-
* A registry of adapters to adapt Reactive Streams {@link Publisher} to/from
42-
* various async/reactive types such as {@code CompletableFuture}, RxJava
43-
* {@code Flowable}, and others.
39+
* A registry of adapters to adapt Reactive Streams {@link Publisher} to/from various
40+
* async/reactive types such as {@code CompletableFuture}, RxJava {@code Flowable}, etc.
41+
* This is designed to complement Spring's Reactor {@code Mono}/{@code Flux} support while
42+
* also being usable without Reactor, e.g. just for {@code org.reactivestreams} bridging.
4443
*
45-
* <p>By default, depending on classpath availability, adapters are registered
46-
* for Reactor, RxJava 3, {@link CompletableFuture}, {@code Flow.Publisher},
47-
* and Kotlin Coroutines' {@code Deferred} and {@code Flow}.
44+
* <p>By default, depending on classpath availability, adapters are registered for Reactor
45+
* (including {@code CompletableFuture} and {@code Flow.Publisher} adapters), RxJava 3,
46+
* Kotlin Coroutines' {@code Deferred} (bridged via Reactor) and SmallRye Mutiny 1.x.
4847
*
4948
* @author Rossen Stoyanchev
5049
* @author Sebastien Deleuze
@@ -304,9 +303,9 @@ private static class CoroutinesRegistrar {
304303
@SuppressWarnings("KotlinInternalInJava")
305304
void registerAdapters(ReactiveAdapterRegistry registry) {
306305
registry.registerReactiveType(
307-
ReactiveTypeDescriptor.singleOptionalValue(Deferred.class,
308-
() -> CompletableDeferredKt.CompletableDeferred(null)),
309-
source -> CoroutinesUtils.deferredToMono((Deferred<?>) source),
306+
ReactiveTypeDescriptor.singleOptionalValue(kotlinx.coroutines.Deferred.class,
307+
() -> kotlinx.coroutines.CompletableDeferredKt.CompletableDeferred(null)),
308+
source -> CoroutinesUtils.deferredToMono((kotlinx.coroutines.Deferred<?>) source),
310309
source -> CoroutinesUtils.monoToDeferred(Mono.from(source)));
311310

312311
registry.registerReactiveType(

spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.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.
@@ -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.
9797
* <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
/**

spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222
import java.util.concurrent.CompletableFuture;
23+
import java.util.concurrent.Flow;
2324

2425
import io.smallrye.mutiny.Multi;
2526
import io.smallrye.mutiny.Uni;
2627
import kotlinx.coroutines.Deferred;
2728
import org.junit.jupiter.api.Nested;
2829
import org.junit.jupiter.api.Test;
2930
import org.reactivestreams.Publisher;
31+
import reactor.adapter.JdkFlowAdapter;
3032
import reactor.core.CoreSubscriber;
3133
import reactor.core.publisher.Flux;
3234
import reactor.core.publisher.Mono;
@@ -112,6 +114,16 @@ void toMono() {
112114
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
113115
}
114116

117+
@Test
118+
void toFlowPublisher() {
119+
List<Integer> sequence = Arrays.asList(1, 2, 3);
120+
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence);
121+
Object target = getAdapter(Flow.Publisher.class).fromPublisher(source);
122+
assertThat(target).isInstanceOf(Flow.Publisher.class);
123+
assertThat(JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher<Integer>) target)
124+
.collectList().block(ONE_SECOND)).isEqualTo(sequence);
125+
}
126+
115127
@Test
116128
void toCompletableFuture() throws Exception {
117129
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3});

0 commit comments

Comments
 (0)