Search in sources :

Example 11 with CommandEvent

use of com.mongodb.event.CommandEvent in project mongo-java-driver by mongodb.

the class AbstractChangeStreamsTest method checkExpectations.

private void checkExpectations() {
    if (definition.containsKey("expectations") && !definition.isNull("expectations") && definition.getArray("expectations").size() > 0) {
        String database = definition.getString("target").getValue().equals("client") ? "admin" : namespace.getDatabaseName();
        List<CommandEvent> expectedEvents = getExpectedEvents(definition.getArray("expectations"), database, new BsonDocument());
        List<CommandEvent> events = filterCommandStartedEvents();
        for (int i = 0; i < expectedEvents.size(); i++) {
            CommandEvent expectedEvent = expectedEvents.get(i);
            CommandEvent event = events.get(i);
            assertEventsEquality(singletonList(expectedEvent), singletonList(event));
        }
    }
}
Also used : BsonDocument(org.bson.BsonDocument) CommandEvent(com.mongodb.event.CommandEvent) BsonString(org.bson.BsonString)

Example 12 with CommandEvent

use of com.mongodb.event.CommandEvent in project mongo-java-driver by mongodb.

the class AbstractChangeStreamsTest method filterCommandStartedEvents.

private List<CommandEvent> filterCommandStartedEvents() {
    List<CommandEvent> events = commandListener.getEvents();
    List<CommandEvent> filteredEvents = new ArrayList<CommandEvent>();
    for (int i = 0; i < events.size(); i++) {
        CommandEvent event = events.get(i);
        if (event instanceof CommandStartedEvent && !event.getCommandName().toLowerCase().equals("killcursors")) {
            filteredEvents.add(event);
        }
    }
    return filteredEvents;
}
Also used : CommandStartedEvent(com.mongodb.event.CommandStartedEvent) CommandEvent(com.mongodb.event.CommandEvent) ArrayList(java.util.ArrayList)

Example 13 with CommandEvent

use of com.mongodb.event.CommandEvent in project mongo-java-driver by mongodb.

the class AbstractClientSideEncryptionDeadlockTest method assertEventEquality.

private void assertEventEquality(final TestCommandListener commandListener, final List<ExpectedEvent> expectedStartEvents) {
    List<CommandEvent> actualStartedEvents = commandListener.getCommandStartedEvents();
    assertEquals(expectedStartEvents.size(), actualStartedEvents.size());
    for (int i = 0; i < expectedStartEvents.size(); i++) {
        ExpectedEvent expectedEvent = expectedStartEvents.get(i);
        CommandStartedEvent actualEvent = (CommandStartedEvent) actualStartedEvents.get(i);
        assertEquals(expectedEvent.getDatabase(), actualEvent.getDatabaseName(), "Database name");
        assertEquals(expectedEvent.getCommandName(), actualEvent.getCommandName(), "Command name");
    }
}
Also used : CommandStartedEvent(com.mongodb.event.CommandStartedEvent) CommandEvent(com.mongodb.event.CommandEvent)

Example 14 with CommandEvent

use of com.mongodb.event.CommandEvent in project mongo-java-driver by mongodb.

the class TestCommandListener method eventsWereDelivered.

public void eventsWereDelivered(final List<CommandEvent> expectedEvents) {
    assertEquals(expectedEvents.size(), events.size());
    int currentlyExpectedRequestId = 0;
    for (int i = 0; i < events.size(); i++) {
        CommandEvent actual = events.get(i);
        CommandEvent expected = expectedEvents.get(i);
        if (actual instanceof CommandStartedEvent) {
            currentlyExpectedRequestId = actual.getRequestId();
        } else {
            assertEquals(currentlyExpectedRequestId, actual.getRequestId());
        }
        assertEventEquivalence(actual, expected);
    }
}
Also used : CommandStartedEvent(com.mongodb.event.CommandStartedEvent) CommandEvent(com.mongodb.event.CommandEvent)

Example 15 with CommandEvent

use of com.mongodb.event.CommandEvent in project mongo-java-driver by mongodb.

the class TestCommandListener method eventsWereDelivered.

public void eventsWereDelivered(final List<CommandEvent> expectedEvents) {
    lock.lock();
    try {
        assertEquals(expectedEvents.size(), events.size());
        int currentlyExpectedRequestId = 0;
        for (int i = 0; i < events.size(); i++) {
            CommandEvent actual = events.get(i);
            CommandEvent expected = expectedEvents.get(i);
            if (actual instanceof CommandStartedEvent) {
                currentlyExpectedRequestId = actual.getRequestId();
            } else {
                assertEquals(currentlyExpectedRequestId, actual.getRequestId());
            }
            assertEventEquivalence(actual, expected);
        }
    } finally {
        lock.unlock();
    }
}
Also used : CommandStartedEvent(com.mongodb.event.CommandStartedEvent) CommandEvent(com.mongodb.event.CommandEvent)

Aggregations

CommandEvent (com.mongodb.event.CommandEvent)18 CommandStartedEvent (com.mongodb.event.CommandStartedEvent)13 BsonDocument (org.bson.BsonDocument)12 Test (org.junit.Test)9 BsonString (org.bson.BsonString)8 BsonValue (org.bson.BsonValue)6 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)5 ArrayList (java.util.ArrayList)5 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)4 JsonTestServerVersionChecker.skipTest (com.mongodb.JsonTestServerVersionChecker.skipTest)3 MongoNamespace (com.mongodb.MongoNamespace)3 CollectionHelper (com.mongodb.client.test.CollectionHelper)3 MongoClientSettings (com.mongodb.MongoClientSettings)2 MongoCommandException (com.mongodb.MongoCommandException)2 MongoWriteConcernException (com.mongodb.MongoWriteConcernException)2 WriteConcern (com.mongodb.WriteConcern)2 Fixture.getMongoClient (com.mongodb.client.Fixture.getMongoClient)2 TestCommandListener (com.mongodb.internal.connection.TestCommandListener)2 TestConnectionPoolListener (com.mongodb.internal.connection.TestConnectionPoolListener)2 Nullable (com.mongodb.lang.Nullable)2