Search in sources :

Example 11 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class WarmerTest method testWarmFromS3_parallel.

@Test
public void testWarmFromS3_parallel() throws IOException, SearchHandler.SearchHandlerException, InterruptedException {
    Path warmingQueriesDir = folder.newFolder("warming_queries").toPath();
    int warmingCountPerQuery = 10;
    try (BufferedWriter writer = Files.newBufferedWriter(warmingQueriesDir.resolve("warming_queries.txt"))) {
        List<String> testSearchRequestsJson = getTestSearchRequestsAsJsonStrings();
        List<String> moreTestSearchRequestsJson = new ArrayList<>();
        for (int i = 0; i < warmingCountPerQuery; i++) {
            moreTestSearchRequestsJson.addAll(testSearchRequestsJson);
        }
        for (String line : moreTestSearchRequestsJson) {
            writer.write(line);
            writer.newLine();
        }
        writer.flush();
    }
    String versionHash = archiver.upload(service, resource, warmingQueriesDir, List.of(), List.of(), false);
    archiver.blessVersion(service, resource, versionHash);
    IndexState mockIndexState = mock(IndexState.class);
    SearchHandler mockSearchHandler = mock(SearchHandler.class);
    warmer.warmFromS3(mockIndexState, 3, mockSearchHandler);
    for (SearchRequest testRequest : getTestSearchRequests()) {
        verify(mockSearchHandler, times(warmingCountPerQuery)).handle(mockIndexState, testRequest);
    }
    verifyNoMoreInteractions(mockSearchHandler);
}
Also used : Path(java.nio.file.Path) SearchHandler(com.yelp.nrtsearch.server.luceneserver.SearchHandler) SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) ArrayList(java.util.ArrayList) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 12 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class WarmerTest method testWarmFromS3.

@Test
public void testWarmFromS3() throws IOException, SearchHandler.SearchHandlerException, InterruptedException {
    Path warmingQueriesDir = folder.newFolder("warming_queries").toPath();
    try (BufferedWriter writer = Files.newBufferedWriter(warmingQueriesDir.resolve("warming_queries.txt"))) {
        List<String> testSearchRequestsJson = getTestSearchRequestsAsJsonStrings();
        for (String line : testSearchRequestsJson) {
            writer.write(line);
            writer.newLine();
        }
        writer.flush();
    }
    String versionHash = archiver.upload(service, resource, warmingQueriesDir, List.of(), List.of(), false);
    archiver.blessVersion(service, resource, versionHash);
    IndexState mockIndexState = mock(IndexState.class);
    SearchHandler mockSearchHandler = mock(SearchHandler.class);
    warmer.warmFromS3(mockIndexState, 0, mockSearchHandler);
    for (SearchRequest testRequest : getTestSearchRequests()) {
        verify(mockSearchHandler).handle(mockIndexState, testRequest);
    }
    verifyNoMoreInteractions(mockSearchHandler);
}
Also used : Path(java.nio.file.Path) SearchHandler(com.yelp.nrtsearch.server.luceneserver.SearchHandler) SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 13 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class WarmerTest method testWarmFromS3_multiple.

@Test
public void testWarmFromS3_multiple() throws IOException, SearchHandler.SearchHandlerException, InterruptedException {
    Path warmingQueriesDir = folder.newFolder("warming_queries").toPath();
    try (BufferedWriter writer = Files.newBufferedWriter(warmingQueriesDir.resolve("warming_queries.txt"))) {
        List<String> testSearchRequestsJson = getTestSearchRequestsAsJsonStrings();
        for (String line : testSearchRequestsJson) {
            writer.write(line);
            writer.newLine();
        }
        writer.flush();
    }
    String versionHash = archiver.upload(service, resource, warmingQueriesDir, List.of(), List.of(), false);
    archiver.blessVersion(service, resource, versionHash);
    IndexState mockIndexState = mock(IndexState.class);
    SearchHandler mockSearchHandler = mock(SearchHandler.class);
    warmer.warmFromS3(mockIndexState, 0, mockSearchHandler);
    warmer.warmFromS3(mockIndexState, 0, mockSearchHandler);
    for (SearchRequest testRequest : getTestSearchRequests()) {
        verify(mockSearchHandler, times(2)).handle(mockIndexState, testRequest);
    }
    verifyNoMoreInteractions(mockSearchHandler);
}
Also used : Path(java.nio.file.Path) SearchHandler(com.yelp.nrtsearch.server.luceneserver.SearchHandler) SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 14 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class DocCollectorTest method testOverrideDefaultTerminateAfter.

@Test
public void testOverrideDefaultTerminateAfter() {
    IndexState indexState = Mockito.mock(IndexState.class);
    when(indexState.getDefaultTerminateAfter()).thenReturn(100);
    SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setTerminateAfter(75).build();
    TestDocCollector docCollector = new TestDocCollector(request, indexState);
    assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
    assertTrue(docCollector.getWrappedManager() instanceof TerminateAfterWrapper);
    assertEquals(75, ((TerminateAfterWrapper<?>) docCollector.getWrappedManager()).getTerminateAfter());
}
Also used : SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) TerminateAfterWrapper(com.yelp.nrtsearch.server.luceneserver.search.TerminateAfterWrapper) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Test(org.junit.Test)

Example 15 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class DocCollectorTest method testUsesDefaultTerminateAfter.

@Test
public void testUsesDefaultTerminateAfter() {
    IndexState indexState = Mockito.mock(IndexState.class);
    when(indexState.getDefaultTerminateAfter()).thenReturn(100);
    SearchRequest request = SearchRequest.newBuilder().setTopHits(10).build();
    TestDocCollector docCollector = new TestDocCollector(request, indexState);
    assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
    assertTrue(docCollector.getWrappedManager() instanceof TerminateAfterWrapper);
    assertEquals(100, ((TerminateAfterWrapper<?>) docCollector.getWrappedManager()).getTerminateAfter());
}
Also used : SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) TerminateAfterWrapper(com.yelp.nrtsearch.server.luceneserver.search.TerminateAfterWrapper) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Test(org.junit.Test)

Aggregations

IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)23 Test (org.junit.Test)13 SearchRequest (com.yelp.nrtsearch.server.grpc.SearchRequest)9 Path (java.nio.file.Path)6 HashMap (java.util.HashMap)5 SearchCutoffWrapper (com.yelp.nrtsearch.server.luceneserver.search.SearchCutoffWrapper)4 SearchHandler (com.yelp.nrtsearch.server.luceneserver.SearchHandler)3 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)3 IndexableFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef)3 BufferedWriter (java.io.BufferedWriter)3 ArrayList (java.util.ArrayList)3 Facet (com.yelp.nrtsearch.server.grpc.Facet)2 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)2 VirtualFieldDef (com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef)2 TerminateAfterWrapper (com.yelp.nrtsearch.server.luceneserver.search.TerminateAfterWrapper)2 LocalStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend)2 RemoteStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend)2 StateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend)2 List (java.util.List)2 Facets (org.apache.lucene.facet.Facets)2