use of com.mongodb.ServerCursor in project spring-data-mongodb by spring-projects.
the class CursorReadingTaskUnitTests method stopTaskWhileEmittingMessages.
// DATAMONGO-1803
@Test
public void stopTaskWhileEmittingMessages() throws Throwable {
when(cursor.getServerCursor()).thenReturn(new ServerCursor(10, new ServerAddress("mock")));
when(cursor.tryNext()).thenReturn("hooyah");
runOnce(new MultithreadedStopRunningWhileEmittingMessages(task, cursor));
verify(listener, times(task.getValues().size())).onMessage(any());
}
use of com.mongodb.ServerCursor in project mongo-java-driver by mongodb.
the class QueryBatchCursor method getMore.
private void getMore() {
ServerCursor serverCursor = assertNotNull(resourceManager.serverCursor());
resourceManager.executeWithConnection(connection -> {
ServerCursor nextServerCursor;
if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) {
try {
nextServerCursor = initFromCommandResult(connection.command(namespace.getDatabaseName(), asGetMoreCommandDocument(serverCursor), NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), CommandResultDocumentCodec.create(decoder, "nextBatch"), resourceManager.sessionContext(), serverApi, resourceManager.requestContext()));
} catch (MongoCommandException e) {
throw translateCommandException(e, serverCursor);
}
} else {
QueryResult<T> getMore = connection.getMore(namespace, serverCursor.getId(), getNumberToReturn(limit, batchSize, count), decoder, resourceManager.requestContext());
nextServerCursor = initFromQueryResult(getMore);
}
resourceManager.setServerCursor(nextServerCursor);
if (limitReached()) {
resourceManager.releaseServerAndClientResources(connection);
}
});
}
use of com.mongodb.ServerCursor in project mongo-java-driver by mongodb.
the class AsyncQueryBatchCursor method getCursorForNext.
private ServerCursor getCursorForNext() {
ServerCursor localCursor;
synchronized (lock) {
localCursor = cursor.get();
if (localCursor == null) {
isClosed.getAndSet(true);
connectionSource.release();
} else {
connectionSource.retain();
}
}
return localCursor;
}
use of com.mongodb.ServerCursor in project spring-data-mongodb by spring-projects.
the class CursorReadingTaskUnitTests method stopRunningTask.
// DATAMONGO-1803
@Test
public void stopRunningTask() throws Throwable {
when(cursor.getServerCursor()).thenReturn(new ServerCursor(10, new ServerAddress("mock")));
runOnce(new MultithreadedStopRunning(task, cursor));
}
Aggregations