Skip to content

Commit 1f0c2bf

Browse files
authored
Merge branch 'main' into fix-github-release-notes
2 parents f4ec15e + ff7ebe9 commit 1f0c2bf

File tree

10 files changed

+245
-119
lines changed

10 files changed

+245
-119
lines changed

driver-core/src/main/com/mongodb/internal/connection/netty/NettyByteBuf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public ByteBuf limit(final int newLimit) {
251251

252252
@Override
253253
public ByteBuf asReadOnly() {
254-
return new NettyByteBuf(proxied.asReadOnly().retain(), false);
254+
return this;
255255
}
256256

257257
@Override

driver-core/src/test/functional/com/mongodb/internal/connection/CommandHelperSpecification.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.mongodb.connection.SocketSettings
2525
import com.mongodb.internal.connection.netty.NettyStreamFactory
2626
import org.bson.BsonDocument
2727
import org.bson.BsonInt32
28+
import spock.lang.Ignore
2829
import spock.lang.Specification
2930

3031
import java.util.concurrent.CountDownLatch
@@ -52,9 +53,11 @@ class CommandHelperSpecification extends Specification {
5253
}
5354

5455
def cleanup() {
56+
InternalStreamConnection.setRecordEverything(false)
5557
connection?.close()
5658
}
5759

60+
@Ignore("JAVA-5982")
5861
def 'should execute command asynchronously'() {
5962
when:
6063
BsonDocument receivedDocument = null

driver-core/src/test/unit/com/mongodb/internal/TimeoutContextTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,10 @@ static Stream<Arguments> shouldChooseTimeoutMsWhenItIsLessThenConnectTimeoutMS()
331331
);
332332
}
333333

334-
@ParameterizedTest
335-
@MethodSource
336334
@DisplayName("should choose timeoutMS when timeoutMS is less than connectTimeoutMS")
335+
@ParameterizedTest(name = "should choose timeoutMS when timeoutMS is less than connectTimeoutMS. "
336+
+ "Parameters: connectTimeoutMS: {0}, timeoutMS: {1}, expected: {2}")
337+
@MethodSource
337338
void shouldChooseTimeoutMsWhenItIsLessThenConnectTimeoutMS(final Long connectTimeoutMS,
338339
final Long timeoutMS,
339340
final long expected) {
@@ -345,7 +346,7 @@ void shouldChooseTimeoutMsWhenItIsLessThenConnectTimeoutMS(final Long connectTim
345346
0));
346347

347348
long calculatedTimeoutMS = timeoutContext.getConnectTimeoutMs();
348-
assertTrue(expected - calculatedTimeoutMS <= 1);
349+
assertTrue(expected - calculatedTimeoutMS <= 2);
349350
}
350351

351352
private TimeoutContextTest() {

driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/TimeoutHelper.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,29 @@ public static <T> MongoCollection<T> collectionWithTimeout(final MongoCollection
5555

5656
public static <T> Mono<MongoCollection<T>> collectionWithTimeoutMono(final MongoCollection<T> collection,
5757
@Nullable final Timeout timeout) {
58+
return collectionWithTimeoutMono(collection, timeout, DEFAULT_TIMEOUT_MESSAGE);
59+
}
60+
61+
public static <T> Mono<MongoCollection<T>> collectionWithTimeoutMono(final MongoCollection<T> collection,
62+
@Nullable final Timeout timeout,
63+
final String message) {
5864
try {
59-
return Mono.just(collectionWithTimeout(collection, timeout));
65+
return Mono.just(collectionWithTimeout(collection, timeout, message));
6066
} catch (MongoOperationTimeoutException e) {
6167
return Mono.error(e);
6268
}
6369
}
6470

6571
public static <T> Mono<MongoCollection<T>> collectionWithTimeoutDeferred(final MongoCollection<T> collection,
6672
@Nullable final Timeout timeout) {
67-
return Mono.defer(() -> collectionWithTimeoutMono(collection, timeout));
73+
return collectionWithTimeoutDeferred(collection, timeout, DEFAULT_TIMEOUT_MESSAGE);
6874
}
6975

76+
public static <T> Mono<MongoCollection<T>> collectionWithTimeoutDeferred(final MongoCollection<T> collection,
77+
@Nullable final Timeout timeout,
78+
final String message) {
79+
return Mono.defer(() -> collectionWithTimeoutMono(collection, timeout, message));
80+
}
7081

7182
public static MongoDatabase databaseWithTimeout(final MongoDatabase database,
7283
@Nullable final Timeout timeout) {

driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/gridfs/GridFSUploadPublisherImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
*/
5555
public final class GridFSUploadPublisherImpl implements GridFSUploadPublisher<Void> {
5656

57-
private static final String TIMEOUT_ERROR_MESSAGE = "Saving chunks exceeded the timeout limit.";
57+
private static final String TIMEOUT_ERROR_MESSAGE_CHUNKS_SAVING = "Saving chunks exceeded the timeout limit.";
58+
private static final String TIMEOUT_ERROR_MESSAGE_UPLOAD_CANCELLATION = "Upload cancellation exceeded the timeout limit.";
5859
private static final Document PROJECTION = new Document("_id", 1);
5960
private static final Document FILES_INDEX = new Document("filename", 1).append("uploadDate", 1);
6061
private static final Document CHUNKS_INDEX = new Document("files_id", 1).append("n", 1);
@@ -226,8 +227,8 @@ private Mono<Long> createSaveChunksMono(final AtomicBoolean terminated, @Nullabl
226227
.append("data", data);
227228

228229
Publisher<InsertOneResult> insertOnePublisher = clientSession == null
229-
? collectionWithTimeout(chunksCollection, timeout, TIMEOUT_ERROR_MESSAGE).insertOne(chunkDocument)
230-
: collectionWithTimeout(chunksCollection, timeout, TIMEOUT_ERROR_MESSAGE)
230+
? collectionWithTimeout(chunksCollection, timeout, TIMEOUT_ERROR_MESSAGE_CHUNKS_SAVING).insertOne(chunkDocument)
231+
: collectionWithTimeout(chunksCollection, timeout, TIMEOUT_ERROR_MESSAGE_CHUNKS_SAVING)
231232
.insertOne(clientSession, chunkDocument);
232233

233234
return Mono.from(insertOnePublisher).thenReturn(data.length());
@@ -270,7 +271,8 @@ private Mono<InsertOneResult> createSaveFileDataMono(final AtomicBoolean termina
270271
}
271272

272273
private Mono<DeleteResult> createCancellationMono(final AtomicBoolean terminated, @Nullable final Timeout timeout) {
273-
Mono<MongoCollection<Document>> chunksCollectionMono = collectionWithTimeoutDeferred(chunksCollection, timeout);
274+
Mono<MongoCollection<Document>> chunksCollectionMono = collectionWithTimeoutDeferred(chunksCollection, timeout,
275+
TIMEOUT_ERROR_MESSAGE_UPLOAD_CANCELLATION);
274276
if (terminated.compareAndSet(false, true)) {
275277
if (clientSession != null) {
276278
return chunksCollectionMono.flatMap(collection -> Mono.from(collection

0 commit comments

Comments
 (0)