-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Remove dead code in ReplyHeader #1231
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,6 @@ | |
import org.bson.io.BsonInput; | ||
import org.bson.io.ByteBufferBsonInput; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.lang.String.format; | ||
|
||
/** | ||
|
@@ -35,50 +32,24 @@ | |
*/ | ||
public class ReplyMessage<T> { | ||
|
||
private final ReplyHeader replyHeader; | ||
private final List<T> documents; | ||
private final T document; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In practice this is always a list of exactly 1, so get rid of the list |
||
|
||
public ReplyMessage(final ResponseBuffers responseBuffers, final Decoder<T> decoder, final long requestId) { | ||
this(responseBuffers.getReplyHeader(), requestId); | ||
|
||
if (replyHeader.getNumberReturned() > 0) { | ||
try (BsonInput bsonInput = new ByteBufferBsonInput(responseBuffers.getBodyByteBuffer().duplicate())) { | ||
while (documents.size() < replyHeader.getNumberReturned()) { | ||
try (BsonBinaryReader reader = new BsonBinaryReader(bsonInput)) { | ||
documents.add(decoder.decode(reader, DecoderContext.builder().build())); | ||
} | ||
} | ||
} finally { | ||
responseBuffers.reset(); | ||
} | ||
} | ||
} | ||
|
||
ReplyMessage(final ReplyHeader replyHeader, final long requestId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor was only used by a test, so removed it and refactored the test to use the remaining constructor. |
||
if (requestId != replyHeader.getResponseTo()) { | ||
if (requestId != responseBuffers.getReplyHeader().getResponseTo()) { | ||
throw new MongoInternalException(format("The responseTo (%d) in the response does not match the requestId (%d) in the " | ||
+ "request", replyHeader.getResponseTo(), requestId)); | ||
+ "request", responseBuffers.getReplyHeader().getResponseTo(), requestId)); | ||
} | ||
this.replyHeader = replyHeader; | ||
|
||
documents = new ArrayList<>(replyHeader.getNumberReturned()); | ||
} | ||
|
||
/** | ||
* Gets the reply header. | ||
* | ||
* @return the reply header | ||
*/ | ||
public ReplyHeader getReplyHeader() { | ||
return replyHeader; | ||
try (BsonInput bsonInput = new ByteBufferBsonInput(responseBuffers.getBodyByteBuffer().duplicate())) { | ||
try (BsonBinaryReader reader = new BsonBinaryReader(bsonInput)) { | ||
document = decoder.decode(reader, DecoderContext.builder().build()); | ||
} | ||
} finally { | ||
responseBuffers.reset(); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the documents. | ||
* | ||
* @return the documents | ||
*/ | ||
public List<T> getDocuments() { | ||
return documents; | ||
public T getDocument() { | ||
return document; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ import com.mongodb.internal.session.SessionContext | |
import com.mongodb.internal.validator.NoOpFieldNameValidator | ||
import org.bson.BsonArray | ||
import org.bson.BsonBinary | ||
import org.bson.BsonBinaryReader | ||
import org.bson.BsonDocument | ||
import org.bson.BsonInt32 | ||
import org.bson.BsonMaximumSizeExceededException | ||
|
@@ -37,10 +36,7 @@ import org.bson.BsonTimestamp | |
import org.bson.ByteBuf | ||
import org.bson.ByteBufNIO | ||
import org.bson.codecs.BsonDocumentCodec | ||
import org.bson.codecs.DecoderContext | ||
import org.bson.io.BasicOutputBuffer | ||
import org.bson.io.BsonInput | ||
import org.bson.io.ByteBufferBsonInput | ||
import spock.lang.Specification | ||
|
||
import java.nio.ByteBuffer | ||
|
@@ -63,7 +59,7 @@ class CommandMessageSpecification extends Specification { | |
.serverType(serverType as ServerType) | ||
.sessionSupported(true) | ||
.build(), | ||
responseExpected, exhaustAllowed, null, null, clusterConnectionMode, null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to test this flag bit since the driver never uses it. |
||
responseExpected, null, null, clusterConnectionMode, null) | ||
def output = new BasicOutputBuffer() | ||
|
||
when: | ||
|
@@ -76,8 +72,7 @@ class CommandMessageSpecification extends Specification { | |
messageHeader.opCode == OpCode.OP_MSG.value | ||
replyHeader.requestId < RequestMessage.currentGlobalId | ||
replyHeader.responseTo == 0 | ||
((replyHeader.opMsgFlagBits & (1 << 16)) != 0) == exhaustAllowed | ||
((replyHeader.opMsgFlagBits & (1 << 1)) == 0) == responseExpected | ||
replyHeader.hasMoreToCome() != responseExpected | ||
|
||
def expectedCommandDocument = command.clone() | ||
.append('$db', new BsonString(namespace.databaseName)) | ||
|
@@ -97,7 +92,7 @@ class CommandMessageSpecification extends Specification { | |
getCommandDocument(byteBuf, replyHeader) == expectedCommandDocument | ||
|
||
where: | ||
[readPreference, serverType, clusterConnectionMode, sessionContext, responseExpected, exhaustAllowed] << [ | ||
[readPreference, serverType, clusterConnectionMode, sessionContext, responseExpected] << [ | ||
[ReadPreference.primary(), ReadPreference.secondary()], | ||
[ServerType.REPLICA_SET_PRIMARY, ServerType.SHARD_ROUTER], | ||
[ClusterConnectionMode.SINGLE, ClusterConnectionMode.MULTIPLE], | ||
|
@@ -126,7 +121,6 @@ class CommandMessageSpecification extends Specification { | |
getReadConcern() >> ReadConcern.DEFAULT | ||
} | ||
], | ||
[true, false], | ||
[true, false] | ||
].combinations() | ||
} | ||
|
@@ -372,12 +366,6 @@ class CommandMessageSpecification extends Specification { | |
} | ||
|
||
private static BsonDocument getCommandDocument(ByteBufNIO byteBuf, ReplyHeader replyHeader) { | ||
new ReplyMessage<BsonDocument>(new ResponseBuffers(replyHeader, byteBuf), new BsonDocumentCodec(), 0).documents.get(0) | ||
} | ||
|
||
private static BsonDocument getCommandDocument(ByteBufNIO byteBuf) { | ||
BsonInput bsonInput = new ByteBufferBsonInput(byteBuf) | ||
BsonBinaryReader reader = new BsonBinaryReader(bsonInput) | ||
new BsonDocumentCodec().decode(reader, DecoderContext.builder().build()) | ||
new ReplyMessage<BsonDocument>(new ResponseBuffers(replyHeader, byteBuf), new BsonDocumentCodec(), 0).document | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to store all the flag bigs since we only ever examine this one.