Skip to content

Commit d182757

Browse files
hantsymp911de
authored andcommitted
Add Smallrye Mutiny support.
Closes #2471
1 parent 03de599 commit d182757

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@
148148
<optional>true</optional>
149149
</dependency>
150150

151+
<!-- SmallRye Mutiny, see:https://smallrye.io/smallrye-mutiny/ -->
152+
<dependency>
153+
<groupId>io.smallrye.reactive</groupId>
154+
<artifactId>mutiny</artifactId>
155+
<version>${smallrye-mutiny}</version>
156+
<optional>true</optional>
157+
</dependency>
158+
151159
<!-- Querydsl -->
152160

153161
<dependency>

src/main/java/org/springframework/data/repository/util/ReactiveWrapperConverters.java

+44
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import io.reactivex.Flowable;
1919
import io.reactivex.Maybe;
20+
import io.smallrye.mutiny.Multi;
21+
import io.smallrye.mutiny.Uni;
2022
import kotlinx.coroutines.flow.Flow;
2123
import kotlinx.coroutines.flow.FlowKt;
2224
import kotlinx.coroutines.reactive.ReactiveFlowKt;
@@ -104,6 +106,11 @@ public abstract class ReactiveWrapperConverters {
104106
REACTIVE_WRAPPERS.add(FlowWrapper.INSTANCE);
105107
}
106108

109+
if (ReactiveWrappers.isAvailable(ReactiveLibrary.MUTINY)) {
110+
REACTIVE_WRAPPERS.add(UniWrapper.INSTANCE);
111+
REACTIVE_WRAPPERS.add(MultiWrapper.INSTANCE);
112+
}
113+
107114
registerConvertersIn(GENERIC_CONVERSION_SERVICE);
108115
}
109116

@@ -527,6 +534,43 @@ public io.reactivex.rxjava3.core.Flowable<?> map(Object wrapper, Function<Object
527534
}
528535
}
529536

537+
/**
538+
* Wrapper for SmallRye Mutiny's {@link io.smallrye.mutiny.Uni}.
539+
*/
540+
private enum UniWrapper implements ReactiveTypeWrapper<io.smallrye.mutiny.Uni<?>> {
541+
542+
INSTANCE;
543+
544+
@Override
545+
public Class<? super io.smallrye.mutiny.Uni<?>> getWrapperClass() {
546+
return io.smallrye.mutiny.Uni.class;
547+
}
548+
549+
@Override
550+
public io.smallrye.mutiny.Uni<?> map(Object wrapper, Function<Object, Object> function) {
551+
return ((io.smallrye.mutiny.Uni<?>) wrapper).map(function::apply);
552+
}
553+
}
554+
555+
/**
556+
* Wrapper for SmallRye Mutiny's {@link io.smallrye.mutiny.Multi}.
557+
*/
558+
private enum MultiWrapper implements ReactiveTypeWrapper<io.smallrye.mutiny.Multi<?>> {
559+
560+
INSTANCE;
561+
562+
@Override
563+
public Class<? super io.smallrye.mutiny.Multi<?>> getWrapperClass() {
564+
return io.smallrye.mutiny.Multi.class;
565+
}
566+
567+
@Override
568+
public io.smallrye.mutiny.Multi<?> map(Object wrapper, Function<Object, Object> function) {
569+
return ((io.smallrye.mutiny.Multi<?>) wrapper).map(function::apply);
570+
}
571+
}
572+
573+
530574
// -------------------------------------------------------------------------
531575
// ReactiveStreams converters
532576
// -------------------------------------------------------------------------

src/main/java/org/springframework/data/repository/util/ReactiveWrappers.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public abstract class ReactiveWrappers {
8383
private static final boolean KOTLIN_COROUTINES_PRESENT = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
8484
ReactiveWrappers.class.getClassLoader());
8585

86+
private static final boolean MUTINY_PRESENT = ClassUtils.isPresent("io.smallrye.mutiny.Multi",
87+
ReactiveWrappers.class.getClassLoader());
88+
8689
private ReactiveWrappers() {}
8790

8891
/**
@@ -104,7 +107,7 @@ public enum ReactiveLibrary {
104107
* @deprecated since 2.6, use RxJava 3 instead. To be removed with Spring Data 3.0.
105108
*/
106109
@Deprecated
107-
RXJAVA2, RXJAVA3, KOTLIN_COROUTINES;
110+
RXJAVA2, RXJAVA3, KOTLIN_COROUTINES, MUTINY;
108111
}
109112

110113
/**
@@ -138,6 +141,8 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
138141
return RXJAVA3_PRESENT;
139142
case KOTLIN_COROUTINES:
140143
return PROJECT_REACTOR_PRESENT && KOTLIN_COROUTINES_PRESENT;
144+
case MUTINY:
145+
return MUTINY_PRESENT;
141146
default:
142147
throw new IllegalArgumentException(String.format("Reactive library %s not supported", reactiveLibrary));
143148
}

src/test/java/org/springframework/data/repository/util/ReactiveWrapperConvertersUnitTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import static org.assertj.core.api.AssertionsForClassTypes.*;
1919

2020
import io.reactivex.Maybe;
21+
import io.smallrye.mutiny.Multi;
22+
import io.smallrye.mutiny.Uni;
2123
import kotlinx.coroutines.flow.Flow;
2224
import kotlinx.coroutines.flow.FlowKt;
2325
import kotlinx.coroutines.reactive.ReactiveFlowKt;
@@ -82,6 +84,13 @@ void shouldSupportKotlinFlow() {
8284
assertThat(ReactiveWrapperConverters.supports(io.reactivex.rxjava3.core.Completable.class)).isTrue();
8385
}
8486

87+
@Test
88+
void shouldSupportMutinyTypes() {
89+
90+
assertThat(ReactiveWrapperConverters.supports(Uni.class)).isTrue();
91+
assertThat(ReactiveWrapperConverters.supports(Multi.class)).isTrue();
92+
}
93+
8594
@Test // DATACMNS-836
8695
void toWrapperShouldCastMonoToMono() {
8796

src/test/java/org/springframework/data/repository/util/ReactiveWrappersUnitTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void isSingleLikeShouldReportCorrectNoTypes() {
5555
assertThat(ReactiveWrappers.isNoValueType(io.reactivex.rxjava3.core.Maybe.class)).isFalse();
5656
assertThat(ReactiveWrappers.isNoValueType(io.reactivex.rxjava3.core.Flowable.class)).isFalse();
5757
assertThat(ReactiveWrappers.isNoValueType(io.reactivex.rxjava3.core.Observable.class)).isFalse();
58+
assertThat(ReactiveWrappers.isNoValueType(io.smallrye.mutiny.Uni.class)).isFalse();
59+
assertThat(ReactiveWrappers.isNoValueType(io.smallrye.mutiny.Multi.class)).isFalse();
5860
}
5961

6062
@Test // DATACMNS-836, DATACMNS-1653, DATACMNS-1753
@@ -77,6 +79,8 @@ void isSingleLikeShouldReportCorrectSingleTypes() {
7779
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Maybe.class)).isTrue();
7880
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Flowable.class)).isFalse();
7981
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Observable.class)).isFalse();
82+
assertThat(ReactiveWrappers.isSingleValueType(io.smallrye.mutiny.Uni.class)).isTrue();
83+
assertThat(ReactiveWrappers.isSingleValueType(io.smallrye.mutiny.Multi.class)).isFalse();
8084
}
8185

8286
@Test // DATACMNS-836, DATACMNS-1653, DATACMNS-1753
@@ -97,5 +101,7 @@ void isCollectionLikeShouldReportCorrectCollectionTypes() {
97101
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Completable.class)).isFalse();
98102
assertThat(ReactiveWrappers.isMultiValueType(io.reactivex.rxjava3.core.Flowable.class)).isTrue();
99103
assertThat(ReactiveWrappers.isMultiValueType(io.reactivex.rxjava3.core.Observable.class)).isTrue();
104+
assertThat(ReactiveWrappers.isMultiValueType(io.smallrye.mutiny.Uni.class)).isFalse();
105+
assertThat(ReactiveWrappers.isMultiValueType(io.smallrye.mutiny.Multi.class)).isTrue();
100106
}
101107
}

0 commit comments

Comments
 (0)