Skip to content

Commit

Permalink
HSEARCH-3323 Test basic scrolling with mapper orm
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Jul 31, 2020
1 parent 4a023bf commit a491e38
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
Expand Up @@ -79,16 +79,7 @@ protected final <T> void testLoading(
hitDocumentReferencesContributor.accept( documentReferenceCollector );
List<DocumentReference> hitDocumentReferences = documentReferenceCollector.collected;

backendMock.expectSearchObjects(
targetIndexes,
b -> { },
StubSearchWorkBehavior.of(
hitDocumentReferences.size(),
hitDocumentReferences
)
);

List<T> loadedEntities = query.fetchAllHits();
List<T> loadedEntities = getHits( targetIndexes, query, hitDocumentReferences );

softAssertions.assertThat( loadedEntities )
.as(
Expand Down Expand Up @@ -125,6 +116,19 @@ protected final <T> void testLoading(
} );
}

protected <T> List<T> getHits(List<String> targetIndexes, SearchQuery<T> query, List<DocumentReference> hitDocumentReferences) {
backendMock.expectSearchObjects(
targetIndexes,
b -> { },
StubSearchWorkBehavior.of(
hitDocumentReferences.size(),
hitDocumentReferences
)
);

return query.fetchAllHits();
}

// This cast is fine as long as T is not a proxy interface
@SuppressWarnings("unchecked")
private <T> List<T> unproxyAll(List<T> entityList) {
Expand Down
@@ -0,0 +1,46 @@
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.integrationtest.mapper.orm.search.loading;

import java.util.List;

import org.hibernate.search.engine.backend.common.DocumentReference;
import org.hibernate.search.engine.search.query.SearchQuery;
import org.hibernate.search.engine.search.query.SearchScroll;
import org.hibernate.search.engine.search.query.SearchScrollResult;
import org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior;

public class SearchQueryEntityLoadingScrollingIT extends SearchQueryEntityLoadingBaseIT {

public SearchQueryEntityLoadingScrollingIT(SingleTypeLoadingModelPrimitives primitives) {
super( primitives );
}

@Override
protected <T> List<T> getHits(List<String> targetIndexes, SearchQuery<T> query, List<DocumentReference> hitDocumentReferences) {
backendMock.expectScrollObjects(
targetIndexes,
hitDocumentReferences.size(),
b -> { }
);

backendMock.expectNextScroll(
targetIndexes,
StubSearchWorkBehavior.of(
hitDocumentReferences.size(),
hitDocumentReferences
)
);

backendMock.expectCloseScroll( targetIndexes );

try ( SearchScroll<T> scroll = query.scroll( hitDocumentReferences.size() ) ) {
SearchScrollResult<T> next = scroll.next();
return next.hits();
}
}
}

0 comments on commit a491e38

Please sign in to comment.