Skip to content

Commit 057649f

Browse files
rozzastIncMale
andauthored
Implement NettyByteBuf.asReadOnly (#1841)
CompositeByteBuf#duplicate should duplicate underlying buffers JAVA-5982 --------- Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
1 parent 9796f56 commit 057649f

File tree

5 files changed

+431
-546
lines changed

5 files changed

+431
-546
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CompositeByteBuf implements ByteBuf {
4949
limit = components.get(components.size() - 1).endOffset;
5050
}
5151

52-
CompositeByteBuf(final CompositeByteBuf from) {
52+
private CompositeByteBuf(final CompositeByteBuf from) {
5353
components = from.components;
5454
position = from.position();
5555
limit = from.limit();
@@ -58,7 +58,7 @@ class CompositeByteBuf implements ByteBuf {
5858
@Override
5959
public ByteBuf order(final ByteOrder byteOrder) {
6060
if (byteOrder == ByteOrder.BIG_ENDIAN) {
61-
throw new UnsupportedOperationException(format("Only %s is supported", ByteOrder.BIG_ENDIAN));
61+
throw new UnsupportedOperationException(format("Only %s is supported", ByteOrder.LITTLE_ENDIAN));
6262
}
6363
return this;
6464
}

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 this; // TODO: do we need this method really? Netty ByteBuf does not have this concept
254+
return new NettyByteBuf(proxied.asReadOnly().retain(), false);
255255
}
256256

257257
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ 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
2928
import spock.lang.Specification
3029

3130
import java.util.concurrent.CountDownLatch
@@ -44,6 +43,7 @@ class CommandHelperSpecification extends Specification {
4443
InternalConnection connection
4544

4645
def setup() {
46+
InternalStreamConnection.setRecordEverything(true)
4747
connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
4848
new NettyStreamFactory(SocketSettings.builder().build(), getSslSettings()),
4949
getCredentialWithCache(), CLIENT_METADATA, [], LoggerSettings.builder().build(), null, getServerApi())
@@ -55,7 +55,6 @@ class CommandHelperSpecification extends Specification {
5555
connection?.close()
5656
}
5757

58-
@Ignore("JAVA-5982")
5958
def 'should execute command asynchronously'() {
6059
when:
6160
BsonDocument receivedDocument = null

0 commit comments

Comments
 (0)