Skip to content

Add Smallrye Mutiny support #2471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@
<optional>true</optional>
</dependency>

<!-- SmallRye Mutiny, see:https://smallrye.io/smallrye-mutiny/ -->
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny</artifactId>
<version>${smallrye-mutiny}</version>
<optional>true</optional>
</dependency>

<!-- Querydsl -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import kotlinx.coroutines.flow.Flow;
import kotlinx.coroutines.flow.FlowKt;
import kotlinx.coroutines.reactive.ReactiveFlowKt;
Expand Down Expand Up @@ -104,6 +106,11 @@ public abstract class ReactiveWrapperConverters {
REACTIVE_WRAPPERS.add(FlowWrapper.INSTANCE);
}

if (ReactiveWrappers.isAvailable(ReactiveLibrary.MUTINY)) {
REACTIVE_WRAPPERS.add(UniWrapper.INSTANCE);
REACTIVE_WRAPPERS.add(MultiWrapper.INSTANCE);
}

registerConvertersIn(GENERIC_CONVERSION_SERVICE);
}

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

/**
* Wrapper for SmallRye Mutiny's {@link io.smallrye.mutiny.Uni}.
*/
private enum UniWrapper implements ReactiveTypeWrapper<io.smallrye.mutiny.Uni<?>> {

INSTANCE;

@Override
public Class<? super io.smallrye.mutiny.Uni<?>> getWrapperClass() {
return io.smallrye.mutiny.Uni.class;
}

@Override
public io.smallrye.mutiny.Uni<?> map(Object wrapper, Function<Object, Object> function) {
return ((io.smallrye.mutiny.Uni<?>) wrapper).map(function::apply);
}
}

/**
* Wrapper for SmallRye Mutiny's {@link io.smallrye.mutiny.Multi}.
*/
private enum MultiWrapper implements ReactiveTypeWrapper<io.smallrye.mutiny.Multi<?>> {

INSTANCE;

@Override
public Class<? super io.smallrye.mutiny.Multi<?>> getWrapperClass() {
return io.smallrye.mutiny.Multi.class;
}

@Override
public io.smallrye.mutiny.Multi<?> map(Object wrapper, Function<Object, Object> function) {
return ((io.smallrye.mutiny.Multi<?>) wrapper).map(function::apply);
}
}


// -------------------------------------------------------------------------
// ReactiveStreams converters
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public abstract class ReactiveWrappers {
private static final boolean KOTLIN_COROUTINES_PRESENT = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
ReactiveWrappers.class.getClassLoader());

private static final boolean MUTINY_PRESENT = ClassUtils.isPresent("io.smallrye.mutiny.Multi",
ReactiveWrappers.class.getClassLoader());

private ReactiveWrappers() {}

/**
Expand All @@ -104,7 +107,7 @@ public enum ReactiveLibrary {
* @deprecated since 2.6, use RxJava 3 instead. To be removed with Spring Data 3.0.
*/
@Deprecated
RXJAVA2, RXJAVA3, KOTLIN_COROUTINES;
RXJAVA2, RXJAVA3, KOTLIN_COROUTINES, MUTINY;
}

/**
Expand Down Expand Up @@ -138,6 +141,8 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
return RXJAVA3_PRESENT;
case KOTLIN_COROUTINES:
return PROJECT_REACTOR_PRESENT && KOTLIN_COROUTINES_PRESENT;
case MUTINY:
return MUTINY_PRESENT;
default:
throw new IllegalArgumentException(String.format("Reactive library %s not supported", reactiveLibrary));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static org.assertj.core.api.AssertionsForClassTypes.*;

import io.reactivex.Maybe;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import kotlinx.coroutines.flow.Flow;
import kotlinx.coroutines.flow.FlowKt;
import kotlinx.coroutines.reactive.ReactiveFlowKt;
Expand Down Expand Up @@ -82,6 +84,13 @@ void shouldSupportKotlinFlow() {
assertThat(ReactiveWrapperConverters.supports(io.reactivex.rxjava3.core.Completable.class)).isTrue();
}

@Test
void shouldSupportMutinyTypes() {

assertThat(ReactiveWrapperConverters.supports(Uni.class)).isTrue();
assertThat(ReactiveWrapperConverters.supports(Multi.class)).isTrue();
}

@Test // DATACMNS-836
void toWrapperShouldCastMonoToMono() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void isSingleLikeShouldReportCorrectNoTypes() {
assertThat(ReactiveWrappers.isNoValueType(io.reactivex.rxjava3.core.Maybe.class)).isFalse();
assertThat(ReactiveWrappers.isNoValueType(io.reactivex.rxjava3.core.Flowable.class)).isFalse();
assertThat(ReactiveWrappers.isNoValueType(io.reactivex.rxjava3.core.Observable.class)).isFalse();
assertThat(ReactiveWrappers.isNoValueType(io.smallrye.mutiny.Uni.class)).isFalse();
assertThat(ReactiveWrappers.isNoValueType(io.smallrye.mutiny.Multi.class)).isFalse();
}

@Test // DATACMNS-836, DATACMNS-1653, DATACMNS-1753
Expand All @@ -77,6 +79,8 @@ void isSingleLikeShouldReportCorrectSingleTypes() {
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Maybe.class)).isTrue();
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Flowable.class)).isFalse();
assertThat(ReactiveWrappers.isSingleValueType(io.reactivex.rxjava3.core.Observable.class)).isFalse();
assertThat(ReactiveWrappers.isSingleValueType(io.smallrye.mutiny.Uni.class)).isTrue();
assertThat(ReactiveWrappers.isSingleValueType(io.smallrye.mutiny.Multi.class)).isFalse();
}

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