Search in sources :

Example 1 with ServerCursor

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());
}
Also used : ServerCursor(com.mongodb.ServerCursor) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 2 with ServerCursor

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);
        }
    });
}
Also used : ServerCursor(com.mongodb.ServerCursor) MongoCommandException(com.mongodb.MongoCommandException)

Example 3 with ServerCursor

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;
}
Also used : ServerCursor(com.mongodb.ServerCursor)

Example 4 with ServerCursor

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));
}
Also used : ServerCursor(com.mongodb.ServerCursor) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Aggregations

ServerCursor (com.mongodb.ServerCursor)4 ServerAddress (com.mongodb.ServerAddress)2 Test (org.junit.Test)2 MongoCommandException (com.mongodb.MongoCommandException)1