Skip to content

Commit 5c07c71

Browse files
rozzastIncMale
andcommitted
Implement NettyByteBuf.asReadOnly (#1841)
CompositeByteBuf#duplicate should duplicate underlying buffers JAVA-5982 --------- Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
1 parent 2dc0652 commit 5c07c71

File tree

5 files changed

+431
-544
lines changed

5 files changed

+431
-544
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CommandHelperSpecification extends Specification {
4343
InternalConnection connection
4444

4545
def setup() {
46+
InternalStreamConnection.setRecordEverything(true)
4647
connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
4748
new NettyStreamFactory(SocketSettings.builder().build(), getSslSettings()),
4849
getCredentialWithCache(), CLIENT_METADATA, [], LoggerSettings.builder().build(), null, getServerApi())

0 commit comments

Comments
 (0)