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));
}
}
}
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;
}
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");
}
}
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);
}
}
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();
}
}
Aggregations