use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testIndexClosed.
@Test
public void testIndexClosed() throws IOException {
StateBackend mockBackend = mock(StateBackend.class);
PersistentGlobalState initialState = new PersistentGlobalState();
when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
MockBackendGlobalState.stateBackend = mockBackend;
BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
backendGlobalState.createIndex("test_index");
IndexState state1 = backendGlobalState.getIndex("test_index");
IndexState state2 = backendGlobalState.getIndex("test_index");
assertSame(state1, state2);
backendGlobalState.indexClosed("test_index");
IndexState state3 = backendGlobalState.getIndex("test_index");
assertNotSame(state1, state3);
verify(mockBackend, times(1)).loadOrCreateGlobalState();
ArgumentCaptor<PersistentGlobalState> stateArgumentCaptor = ArgumentCaptor.forClass(PersistentGlobalState.class);
verify(mockBackend, times(1)).commitGlobalState(stateArgumentCaptor.capture());
PersistentGlobalState committedState = stateArgumentCaptor.getValue();
assertEquals(1, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index"));
verifyNoMoreInteractions(mockBackend);
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class DocCollectorTest method testQueryOverridesDefaultTimeout.
@Test
public void testQueryOverridesDefaultTimeout() {
IndexState indexState = Mockito.mock(IndexState.class);
when(indexState.getDefaultSearchTimeoutSec()).thenReturn(3.0);
when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(0);
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setTimeoutSec(2.0).build();
TestDocCollector docCollector = new TestDocCollector(request, indexState);
assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
assertEquals(2.0, cutoffWrapper.getTimeoutSec(), 0.0);
assertEquals(0, cutoffWrapper.getCheckEvery());
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class DocCollectorTest method testUsesDefaultTimeoutCheckEvery.
@Test
public void testUsesDefaultTimeoutCheckEvery() {
IndexState indexState = Mockito.mock(IndexState.class);
when(indexState.getDefaultSearchTimeoutSec()).thenReturn(6.0);
when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(10);
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).build();
TestDocCollector docCollector = new TestDocCollector(request, indexState);
assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
assertEquals(6.0, cutoffWrapper.getTimeoutSec(), 0.0);
assertEquals(10, cutoffWrapper.getCheckEvery());
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class TerminateAfterWrapperTest method testOverrideDefaultTerminateAfter.
@Test
public void testOverrideDefaultTerminateAfter() throws IOException {
IndexState indexState = getGlobalState().getIndex(DEFAULT_TEST_INDEX);
try {
indexState.setDefaultTerminateAfter(15);
SearchResponse response = doQuery(5, 0.0, false);
assertEquals(5, response.getHitsCount());
assertTrue(response.getTerminatedEarly());
} finally {
indexState.setDefaultTerminateAfter(0);
}
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class FacetTopDocs method facetTopDocsSample.
/**
* Compute facet aggregations based on a sample of the query's top ranked documents. Only
* processes facets that have sampleTopDocs set to a value greater than zero.
*
* @param topDocs top documents from query
* @param facets facet definition grpc messages
* @param indexState state for index
* @param searcher searcher for query
* @param diagnostics diagnostics builder for storing facet timing
* @return results for facets over top docs
* @throws IOException if error reading doc values
* @throws IllegalArgumentException if top docs facet field is not indexable or does not have doc
* values enabled
*/
public static Iterable<FacetResult> facetTopDocsSample(TopDocs topDocs, List<Facet> facets, IndexState indexState, IndexSearcher searcher, Diagnostics.Builder diagnostics) throws IOException {
List<Facet> sampleFacets = facets.stream().filter(facet -> facet.getSampleTopDocs() > 0).collect(Collectors.toList());
if (sampleFacets.isEmpty()) {
return Collections.emptyList();
}
List<FacetResult> facetResults = new ArrayList<>(sampleFacets.size());
for (Facet facet : sampleFacets) {
long startNS = System.nanoTime();
facetResults.add(facetFromTopDocs(topDocs, facet, indexState, searcher));
long endNS = System.nanoTime();
diagnostics.putFacetTimeMs(facet.getName(), (endNS - startNS) / 1000000.0);
}
return facetResults;
}
Aggregations