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;
}
Aggregations