Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import com.mongodb.ServerApi;
import com.mongodb.connection.ClusterConnectionMode;
import com.mongodb.internal.TimeoutContext;
import com.mongodb.internal.VisibleForTesting;

import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;

import com.mongodb.internal.async.SingleResultCallback;
import com.mongodb.internal.validator.NoOpFieldNameValidator;
import com.mongodb.lang.Nullable;
Expand All @@ -38,8 +42,10 @@
*/
public final class CommandHelper {

static final String HELLO = "hello";
static final String LEGACY_HELLO = "isMaster";
@VisibleForTesting(otherwise = PRIVATE)
public static final String HELLO = "hello";
@VisibleForTesting(otherwise = PRIVATE)
public static final String LEGACY_HELLO = "isMaster";
static final String LEGACY_HELLO_LOWER = LEGACY_HELLO.toLowerCase(Locale.ROOT);

static BsonDocument executeCommand(final String database, final BsonDocument command, final ClusterConnectionMode clusterConnectionMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
import com.mongodb.event.ConnectionClosedEvent;
import com.mongodb.event.ConnectionCreatedEvent;
import com.mongodb.event.ConnectionReadyEvent;

import static com.mongodb.internal.connection.CommandHelper.HELLO;
import static com.mongodb.internal.connection.CommandHelper.LEGACY_HELLO;

import com.mongodb.internal.connection.InternalStreamConnection;
import com.mongodb.internal.connection.ServerHelper;
import com.mongodb.internal.connection.TestCommandListener;
Expand Down Expand Up @@ -1051,8 +1055,7 @@ public void shouldUseConnectTimeoutMsWhenEstablishingConnectionInBackground() {
} finally {
InternalStreamConnection.setRecordEverything(false);
}

List<CommandFailedEvent> commandFailedEvents = commandListener.getCommandFailedEvents("isMaster");
List<CommandFailedEvent> commandFailedEvents = commandListener.getCommandFailedEvents(getHandshakeCommandName());
assertFalse(commandFailedEvents.isEmpty());
assertInstanceOf(MongoOperationTimeoutException.class, commandFailedEvents.get(0).getThrowable());
}
Expand Down Expand Up @@ -1136,8 +1139,15 @@ private MongoClient createMongoClient(final MongoClientSettings.Builder builder)
return createMongoClient(builder.build());
}

private long msElapsedSince(final long t1) {
private long msElapsedSince(final long t1) {
return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t1);
}

/**
* Get the handshake command name based on the server API version.
* @return the handshake command name
*/
private String getHandshakeCommandName() {
return ClusterFixture.getServerApi() == null ? LEGACY_HELLO : HELLO;
}
}