Skip to content

Commit

Permalink
Ensure all CommandEvents have same order of params
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Oct 9, 2023
1 parent 1d2d782 commit 8614945
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
17 changes: 9 additions & 8 deletions driver-core/src/main/com/mongodb/event/CommandFailedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ public final class CommandFailedEvent extends CommandEvent {
/**
* Construct an instance.
*
* @param requestContext the request context
* @param operationId the operation id
* @param requestId the request id
* @param requestContext the request context
* @param operationId the operation id
* @param requestId the request id
* @param connectionDescription the connection description
* @param commandName the command name
* @param elapsedTimeNanos the non-negative elapsed time in nanoseconds for the operation to complete
* @param throwable the throwable cause of the failure
* @param databaseName the database name
* @param commandName the command name
* @param elapsedTimeNanos the non-negative elapsed time in nanoseconds for the operation to complete
* @param throwable the throwable cause of the failure
* @since 4.11
*/
public CommandFailedEvent(@Nullable final RequestContext requestContext, final long operationId, final int requestId,
final ConnectionDescription connectionDescription, final String commandName,
final String databaseName, final long elapsedTimeNanos, final Throwable throwable) {
final ConnectionDescription connectionDescription, final String databaseName, final String commandName,
final long elapsedTimeNanos, final Throwable throwable) {
super(requestContext, operationId, requestId, connectionDescription, commandName, databaseName);
isTrueArgument("elapsed time is not negative", elapsedTimeNanos >= 0);
this.elapsedTimeNanos = elapsedTimeNanos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public final class CommandSucceededEvent extends CommandEvent {
/**
* Construct an instance.
*
* @param requestContext the request context
* @param operationId the operation id
* @param requestId the request id
* @param requestContext the request context
* @param operationId the operation id
* @param requestId the request id
* @param connectionDescription the connection description
* @param commandName the command name
* @param databaseName the database name
* @param response the command response
* @param elapsedTimeNanos the non-negative elapsed time in nanoseconds for the operation to complete
* @param databaseName the database name
* @param commandName the command name
* @param response the command response
* @param elapsedTimeNanos the non-negative elapsed time in nanoseconds for the operation to complete
* @since 4.11
*/
public CommandSucceededEvent(@Nullable final RequestContext requestContext, final long operationId, final int requestId,
final ConnectionDescription connectionDescription, final String commandName,
final String databaseName, final BsonDocument response, final long elapsedTimeNanos) {
final ConnectionDescription connectionDescription, final String databaseName, final String commandName,
final BsonDocument response, final long elapsedTimeNanos) {
super(requestContext, operationId, requestId, connectionDescription, commandName, databaseName);
this.response = response;
isTrueArgument("elapsed time is not negative", elapsedTimeNanos >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static void sendCommandSucceededEvent(final RequestMessage message, final String
notNull("requestContext", requestContext);
try {
commandListener.commandSucceeded(new CommandSucceededEvent(getRequestContextForEvent(requestContext),
operationContext.getId(), message.getId(), connectionDescription, commandName, databaseName, response,
operationContext.getId(), message.getId(), connectionDescription, databaseName, commandName, response,
elapsedTimeNanos));
} catch (Exception e) {
if (PROTOCOL_EVENT_LOGGER.isWarnEnabled()) {
Expand All @@ -311,7 +311,7 @@ static void sendCommandFailedEvent(final RequestMessage message, final String da
notNull("requestContext", requestContext);
try {
commandListener.commandFailed(new CommandFailedEvent(getRequestContextForEvent(requestContext),
operationContext.getId(), message.getId(), connectionDescription, commandName, databaseName, elapsedTimeNanos,
operationContext.getId(), message.getId(), connectionDescription, databaseName, commandName, elapsedTimeNanos,
throwable));
} catch (Exception e) {
if (PROTOCOL_EVENT_LOGGER.isWarnEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ else if (!observeSensitiveCommands) {
lock.lock();
try {
events.add(new CommandSucceededEvent(event.getRequestContext(), event.getOperationId(), event.getRequestId(),
event.getConnectionDescription(), event.getCommandName(), event.getDatabaseName(),
event.getConnectionDescription(), event.getDatabaseName(), event.getCommandName(),
event.getResponse() == null ? null : event.getResponse().clone(),
event.getElapsedTime(TimeUnit.NANOSECONDS)));
commandCompletedCondition.signal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ class LoggingCommandEventSenderSpecification extends Specification {
[
new CommandStartedEvent(null, context.id, message.getId(), connectionDescription, namespace.databaseName,
commandDocument.getFirstKey(), commandDocument.append('$db', new BsonString(namespace.databaseName))),
new CommandSucceededEvent(null, context.id, message.getId(), connectionDescription, commandDocument.getFirstKey(),
namespace.databaseName, new BsonDocument(), 1),
new CommandSucceededEvent(null, context.id, message.getId(), connectionDescription, commandDocument.getFirstKey(),
namespace.databaseName, replyDocument, 1),
new CommandFailedEvent(null, context.id, message.getId(), connectionDescription, commandDocument.getFirstKey(),
namespace.databaseName, 1, failureException)
new CommandSucceededEvent(null, context.id, message.getId(), connectionDescription, namespace.databaseName,
commandDocument.getFirstKey(), new BsonDocument(), 1),
new CommandSucceededEvent(null, context.id, message.getId(), connectionDescription, namespace.databaseName,
commandDocument.getFirstKey(), replyDocument, 1),
new CommandFailedEvent(null, context.id, message.getId(), connectionDescription, namespace.databaseName,
commandDocument.getFirstKey(), 1, failureException)
])

where:
Expand Down

0 comments on commit 8614945

Please sign in to comment.