DATAMONGO-2603 - Adopt to Reactor 3.4 changes.
Align with ContextView and changes in other operators.
This commit is contained in:
@@ -15,11 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.util.Assert;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.reactivestreams.client.ClientSession;
|
||||
|
||||
/**
|
||||
@@ -29,7 +33,7 @@ import com.mongodb.reactivestreams.client.ClientSession;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 2.1
|
||||
* @see Mono#subscriberContext()
|
||||
* @see Mono#deferContextual(Function)
|
||||
* @see Context
|
||||
*/
|
||||
public class ReactiveMongoContext {
|
||||
@@ -46,8 +50,14 @@ public class ReactiveMongoContext {
|
||||
*/
|
||||
public static Mono<ClientSession> getSession() {
|
||||
|
||||
return Mono.subscriberContext().filter(ctx -> ctx.hasKey(SESSION_KEY))
|
||||
.flatMap(ctx -> ctx.<Mono<ClientSession>> get(SESSION_KEY));
|
||||
return Mono.deferContextual(ctx -> {
|
||||
|
||||
if (ctx.hasKey(SESSION_KEY)) {
|
||||
return ctx.<Mono<ClientSession>> get(SESSION_KEY);
|
||||
}
|
||||
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -572,7 +572,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
ReactiveMongoTemplate.this);
|
||||
|
||||
return Flux.from(action.doInSession(operations)) //
|
||||
.subscriberContext(ctx -> ReactiveMongoContext.setSession(ctx, Mono.just(session)));
|
||||
.contextWrite(ctx -> ReactiveMongoContext.setSession(ctx, Mono.just(session)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.reactivestreams.client.MongoClients;
|
||||
import reactor.util.retry.Retry;
|
||||
|
||||
/**
|
||||
* Utility to create (and reuse) imperative and reactive {@code MongoClient} instances.
|
||||
@@ -160,7 +161,7 @@ public class MongoTestUtils {
|
||||
.withWriteConcern(WriteConcern.MAJORITY).withReadPreference(ReadPreference.primary());
|
||||
|
||||
Mono.from(database.getCollection(collectionName).drop()) //
|
||||
.delayElement(getTimeout()).retryBackoff(3, Duration.ofMillis(250)) //
|
||||
.delayElement(getTimeout()).retryWhen(Retry.backoff(3, Duration.ofMillis(250))) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user