Search in sources :

Example 1 with CommandFailedEvent

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

the class CommandMonitoringTest method getExpectedEvents.

private List<CommandEvent> getExpectedEvents(final BsonArray expectedEventDocuments) {
    List<CommandEvent> expectedEvents = new ArrayList<CommandEvent>(expectedEventDocuments.size());
    for (Iterator<BsonValue> iterator = expectedEventDocuments.iterator(); iterator.hasNext(); ) {
        BsonDocument curExpectedEventDocument = iterator.next().asDocument();
        String eventType = curExpectedEventDocument.keySet().iterator().next();
        BsonDocument eventDescriptionDocument = curExpectedEventDocument.getDocument(eventType);
        CommandEvent commandEvent;
        if (eventType.equals("command_started_event")) {
            commandEvent = new CommandStartedEvent(1, null, databaseName, eventDescriptionDocument.getString("command_name").getValue(), eventDescriptionDocument.getDocument("command"));
        } else if (eventType.equals("command_succeeded_event")) {
            BsonDocument replyDocument = eventDescriptionDocument.get("reply").asDocument();
            commandEvent = new CommandSucceededEvent(1, null, eventDescriptionDocument.getString("command_name").getValue(), replyDocument, 1);
        } else if (eventType.equals("command_failed_event")) {
            commandEvent = new CommandFailedEvent(1, null, eventDescriptionDocument.getString("command_name").getValue(), 1, null);
        } else {
            throw new UnsupportedOperationException("Unsupported command event type: " + eventType);
        }
        expectedEvents.add(commandEvent);
    }
    return expectedEvents;
}
Also used : CommandFailedEvent(com.mongodb.event.CommandFailedEvent) CommandSucceededEvent(com.mongodb.event.CommandSucceededEvent) BsonDocument(org.bson.BsonDocument) CommandStartedEvent(com.mongodb.event.CommandStartedEvent) ArrayList(java.util.ArrayList) CommandEvent(com.mongodb.event.CommandEvent) BsonString(org.bson.BsonString) BsonValue(org.bson.BsonValue)

Aggregations

CommandEvent (com.mongodb.event.CommandEvent)1 CommandFailedEvent (com.mongodb.event.CommandFailedEvent)1 CommandStartedEvent (com.mongodb.event.CommandStartedEvent)1 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)1 ArrayList (java.util.ArrayList)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 BsonValue (org.bson.BsonValue)1