Search in sources :

Example 1 with TestCommandListener

use of com.mongodb.internal.connection.TestCommandListener in project mongo-java-driver by mongodb.

the class CommandMonitoringTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    commandListener = new TestCommandListener();
    mongoClient = MongoClients.create(getMongoClientSettingsBuilder().retryWrites(false).addCommandListener(commandListener).build());
}
Also used : TestCommandListener(com.mongodb.internal.connection.TestCommandListener) BeforeClass(org.junit.BeforeClass)

Example 2 with TestCommandListener

use of com.mongodb.internal.connection.TestCommandListener in project mongo-java-driver by mongodb.

the class ReadConcernTest method setUp.

@Before
public void setUp() {
    assumeTrue(canRunTests());
    commandListener = new TestCommandListener();
    mongoClient = MongoClients.create(getMongoClientSettingsBuilder().addCommandListener(commandListener).applyToSocketSettings(new Block<SocketSettings.Builder>() {

        @Override
        public void apply(final SocketSettings.Builder builder) {
            builder.readTimeout(5, TimeUnit.SECONDS);
        }
    }).build());
}
Also used : TestCommandListener(com.mongodb.internal.connection.TestCommandListener) Fixture.getMongoClientSettingsBuilder(com.mongodb.client.Fixture.getMongoClientSettingsBuilder) Block(com.mongodb.Block) SocketSettings(com.mongodb.connection.SocketSettings) Before(org.junit.Before)

Example 3 with TestCommandListener

use of com.mongodb.internal.connection.TestCommandListener in project mongo-java-driver by mongodb.

the class UnifiedTest method executeAssertLsidOnLastTwoCommands.

private OperationResult executeAssertLsidOnLastTwoCommands(final BsonDocument operation, final boolean same) {
    TestCommandListener listener = entities.getClientCommandListener(operation.getDocument("arguments").getString("client").getValue());
    List<CommandEvent> events = lastTwoCommandEvents(listener);
    String eventsJson = listener.getCommandStartedEvents().stream().map(e -> ((CommandStartedEvent) e).getCommand().toJson()).collect(Collectors.joining(", "));
    BsonDocument expected = ((CommandStartedEvent) events.get(0)).getCommand().getDocument("lsid");
    BsonDocument actual = ((CommandStartedEvent) events.get(1)).getCommand().getDocument("lsid");
    if (same) {
        assertEquals(eventsJson, expected, actual);
    } else {
        assertNotEquals(eventsJson, expected, actual);
    }
    return OperationResult.NONE;
}
Also used : GridFSBucket(com.mongodb.client.gridfs.GridFSBucket) JsonPoweredTestHelper.getTestFiles(util.JsonPoweredTestHelper.getTestFiles) URISyntaxException(java.net.URISyntaxException) MongoDatabase(com.mongodb.client.MongoDatabase) BsonValue(org.bson.BsonValue) BsonArray(org.bson.BsonArray) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) CommandEvent(com.mongodb.event.CommandEvent) CollectionHelper(com.mongodb.client.test.CollectionHelper) Fixture.getMongoClientSettings(com.mongodb.client.Fixture.getMongoClientSettings) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ClusterFixture.getServerVersion(com.mongodb.ClusterFixture.getServerVersion) Assert.assertFalse(org.junit.Assert.assertFalse) TestConnectionPoolListener(com.mongodb.internal.connection.TestConnectionPoolListener) Assume.assumeTrue(org.junit.Assume.assumeTrue) MongoClientSettings(com.mongodb.MongoClientSettings) NotNull(org.jetbrains.annotations.NotNull) JsonPoweredTestHelper.getTestDocument(util.JsonPoweredTestHelper.getTestDocument) MongoClient(com.mongodb.client.MongoClient) BsonBoolean(org.bson.BsonBoolean) RunWith(org.junit.runner.RunWith) BsonString(org.bson.BsonString) BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) Filters(com.mongodb.client.model.Filters) TestCommandListener(com.mongodb.internal.connection.TestCommandListener) Fixture.getMongoClient(com.mongodb.client.Fixture.getMongoClient) Before(org.junit.Before) AssumptionViolatedException(org.junit.AssumptionViolatedException) MongoNamespace(com.mongodb.MongoNamespace) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BsonDouble(org.bson.BsonDouble) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) RunOnRequirementsMatcher.runOnRequirementsMet(com.mongodb.client.unified.RunOnRequirementsMatcher.runOnRequirementsMet) ClientSession(com.mongodb.client.ClientSession) Nullable(com.mongodb.lang.Nullable) WriteConcern(com.mongodb.WriteConcern) Collections(java.util.Collections) CommandStartedEvent(com.mongodb.event.CommandStartedEvent) Assert.assertEquals(org.junit.Assert.assertEquals) BsonDocument(org.bson.BsonDocument) TestCommandListener(com.mongodb.internal.connection.TestCommandListener) CommandEvent(com.mongodb.event.CommandEvent) BsonString(org.bson.BsonString)

Example 4 with TestCommandListener

use of com.mongodb.internal.connection.TestCommandListener in project mongo-java-driver by mongodb.

the class BatchCursorFluxTest method setUp.

@BeforeEach
public void setUp() {
    commandListener = new TestCommandListener(singletonList("commandStartedEvent"), asList("insert", "killCursors"));
    MongoClientSettings mongoClientSettings = getMongoClientBuilderFromConnectionString().addCommandListener(commandListener).build();
    client = MongoClients.create(mongoClientSettings);
    collection = client.getDatabase(getDefaultDatabaseName()).getCollection(getClass().getName());
    drop(collection.getNamespace());
}
Also used : TestCommandListener(com.mongodb.internal.connection.TestCommandListener) MongoClientSettings(com.mongodb.MongoClientSettings) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with TestCommandListener

use of com.mongodb.internal.connection.TestCommandListener in project mongo-java-driver by mongodb.

the class ReadConcernTest method setUp.

@Before
public void setUp() {
    assumeTrue(canRunTests());
    commandListener = new TestCommandListener();
    mongoClient = MongoClients.create(getMongoClientBuilderFromConnectionString().addCommandListener(commandListener).build());
}
Also used : TestCommandListener(com.mongodb.internal.connection.TestCommandListener) Before(org.junit.Before)

Aggregations

TestCommandListener (com.mongodb.internal.connection.TestCommandListener)16 BsonDocument (org.bson.BsonDocument)11 BsonString (org.bson.BsonString)10 Before (org.junit.Before)9 MongoClientSettings (com.mongodb.MongoClientSettings)5 HashMap (java.util.HashMap)5 BsonArray (org.bson.BsonArray)5 TestConnectionPoolListener (com.mongodb.internal.connection.TestConnectionPoolListener)4 Map (java.util.Map)4 BsonInt32 (org.bson.BsonInt32)4 BsonValue (org.bson.BsonValue)4 Fixture.getMongoClientSettingsBuilder (com.mongodb.client.Fixture.getMongoClientSettingsBuilder)3 ArrayList (java.util.ArrayList)3 BsonBoolean (org.bson.BsonBoolean)3 ClusterFixture.getMultiMongosConnectionString (com.mongodb.ClusterFixture.getMultiMongosConnectionString)2 ClusterFixture.isSharded (com.mongodb.ClusterFixture.isSharded)2 MongoNamespace (com.mongodb.MongoNamespace)2 CreateCollectionOptions (com.mongodb.client.model.CreateCollectionOptions)2 ValidationOptions (com.mongodb.client.model.ValidationOptions)2 ConnectionCheckOutFailedEvent (com.mongodb.event.ConnectionCheckOutFailedEvent)2