use of com.mongodb.connection.AsyncConnection in project mongo-java-driver by mongodb.
the class AsyncSingleConnectionBindingTest method shouldReturnTheSameConnection.
@Test
public void shouldReturnTheSameConnection() throws Throwable {
AsyncConnectionSource asyncConnectionSource = getReadConnectionSource(binding);
AsyncConnection asyncConnection = getConnection(asyncConnectionSource);
// Check we get the same connection
for (int i = 0; i < 100; i++) {
AsyncConnectionSource connectionSource = getReadConnectionSource(binding);
AsyncConnection connection = getConnection(connectionSource);
assertEquals(connection.getDescription().getConnectionId(), asyncConnection.getDescription().getConnectionId());
connection.release();
connectionSource.release();
}
asyncConnection.release();
asyncConnectionSource.release();
}
use of com.mongodb.connection.AsyncConnection in project mongo-java-driver by mongodb.
the class AsyncSingleConnectionBindingTest method shouldHaveTheDifferentConnectionForReadsAndWritesWithNonPrimaryReadPreference.
@Test
public void shouldHaveTheDifferentConnectionForReadsAndWritesWithNonPrimaryReadPreference() throws Throwable {
AsyncSingleConnectionBinding binding = new AsyncSingleConnectionBinding(getAsyncCluster(), secondary(), ClusterFixture.TIMEOUT, SECONDS);
AsyncConnectionSource writeSource = getWriteConnectionSource(binding);
AsyncConnection writeConnection = getConnection(writeSource);
AsyncConnectionSource readSource = getReadConnectionSource(binding);
AsyncConnection readConnection = getConnection(readSource);
assertThat(writeConnection.getDescription().getConnectionId(), is(not(readConnection.getDescription().getConnectionId())));
writeConnection.release();
readConnection.release();
writeSource.release();
readSource.release();
binding.release();
}
use of com.mongodb.connection.AsyncConnection in project mongo-java-driver by mongodb.
the class AsyncSingleConnectionBindingTest method shouldHaveTheSameConnectionForReadsAndWritesWithPrimaryReadPreference.
@Test
public void shouldHaveTheSameConnectionForReadsAndWritesWithPrimaryReadPreference() throws Throwable {
AsyncConnectionSource writeSource = getWriteConnectionSource(binding);
AsyncConnection writeConnection = getConnection(writeSource);
AsyncConnectionSource readSource = getReadConnectionSource(binding);
AsyncConnection readConnection = getConnection(readSource);
assertEquals(writeConnection.getDescription().getConnectionId(), readConnection.getDescription().getConnectionId());
writeConnection.release();
readConnection.release();
writeSource.release();
readSource.release();
}
use of com.mongodb.connection.AsyncConnection in project mongo-java-driver by mongodb.
the class MixedBulkWriteOperation method executeAsync.
@Override
public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<BulkWriteResult> callback) {
withConnection(binding, new AsyncCallableWithConnection() {
@Override
public void call(final AsyncConnection connection, final Throwable t) {
final SingleResultCallback<BulkWriteResult> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
if (t != null) {
errHandlingCallback.onResult(null, t);
} else {
validateWriteRequests(connection, bypassDocumentValidation, writeRequests, writeConcern, new AsyncCallableWithConnection() {
@Override
public void call(final AsyncConnection connection, final Throwable t) {
if (t != null) {
releasingCallback(errHandlingCallback, connection).onResult(null, t);
} else {
Iterator<Run> runs = getRunGenerator(connection.getDescription()).iterator();
executeRunsAsync(runs, connection, new BulkWriteBatchCombiner(connection.getDescription().getServerAddress(), ordered, writeConcern), errHandlingCallback);
}
}
});
}
}
});
}
use of com.mongodb.connection.AsyncConnection in project mongo-java-driver by mongodb.
the class OperationHelper method validateWriteRequestCollations.
static void validateWriteRequestCollations(final AsyncConnection connection, final List<? extends WriteRequest> requests, final WriteConcern writeConcern, final AsyncCallableWithConnection callable) {
Collation collation = null;
for (WriteRequest request : requests) {
if (request instanceof UpdateRequest) {
collation = ((UpdateRequest) request).getCollation();
} else if (request instanceof DeleteRequest) {
collation = ((DeleteRequest) request).getCollation();
}
if (collation != null) {
break;
}
}
validateCollationAndWriteConcern(connection, collation, writeConcern, new AsyncCallableWithConnection() {
@Override
public void call(final AsyncConnection connection, final Throwable t) {
callable.call(connection, t);
}
});
}
Aggregations