Search in sources :

Example 1 with EntryScore

use of org.apache.geode.cache.lucene.internal.distributed.EntryScore in project geode by apache.

the class PageableLuceneQueryResultsImplJUnitTest method setUp.

@Before
public void setUp() {
    hits = new ArrayList<EntryScore<String>>();
    for (int i = 0; i < 23; i++) {
        hits.add(new EntryScore("key_" + i, i));
        expected.add(new LuceneResultStructImpl<String, String>("key_" + i, "value_" + i, i));
    }
    userRegion = mock(Region.class);
    final ResultCollector collector = mock(ResultCollector.class);
    execution = mock(Execution.class);
    when(execution.withFilter(any())).thenReturn(execution);
    when(execution.withCollector(any())).thenReturn(execution);
    when(execution.execute(anyString())).thenReturn(collector);
    when(collector.getResult()).then(new Answer() {

        @Override
        public Map answer(InvocationOnMock invocation) throws Throwable {
            ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
            verify(execution, atLeast(1)).withFilter(captor.capture());
            Collection<String> keys = captor.getValue();
            Map<String, String> results = new HashMap<String, String>();
            for (String key : keys) {
                results.put(key, key.replace("key_", "value_"));
            }
            return results;
        }
    });
}
Also used : Set(java.util.Set) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.anyString(org.mockito.Matchers.anyString) Answer(org.mockito.stubbing.Answer) Execution(org.apache.geode.cache.execute.Execution) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) EntryScore(org.apache.geode.cache.lucene.internal.distributed.EntryScore) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 2 with EntryScore

use of org.apache.geode.cache.lucene.internal.distributed.EntryScore in project geode by apache.

the class LuceneQueryImplJUnitTest method addValueToResults.

private void addValueToResults() {
    TopEntries entries = new TopEntries();
    entries.addHit(new EntryScore("hi", 5));
    when(collector.getResult()).thenReturn(entries);
    when(results.getMaxScore()).thenReturn(5f);
    when(results.size()).thenReturn(1);
    List<LuceneResultStruct<Object, Object>> page = Collections.singletonList(new LuceneResultStructImpl<>("hi", "value", 5f));
    when(results.next()).thenReturn(page);
    when(results.hasNext()).thenReturn(true);
}
Also used : TopEntries(org.apache.geode.cache.lucene.internal.distributed.TopEntries) EntryScore(org.apache.geode.cache.lucene.internal.distributed.EntryScore) LuceneResultStruct(org.apache.geode.cache.lucene.LuceneResultStruct)

Example 3 with EntryScore

use of org.apache.geode.cache.lucene.internal.distributed.EntryScore in project geode by apache.

the class LuceneTestUtilities method verifyResultOrder.

public static void verifyResultOrder(Collection<EntryScore<String>> list, EntryScore<String>... expectedEntries) {
    Iterator<EntryScore<String>> iter = list.iterator();
    for (EntryScore expectedEntry : expectedEntries) {
        if (!iter.hasNext()) {
            fail();
        }
        EntryScore toVerify = iter.next();
        assertEquals(expectedEntry.getKey(), toVerify.getKey());
        assertEquals(expectedEntry.getScore(), toVerify.getScore(), .0f);
    }
}
Also used : EntryScore(org.apache.geode.cache.lucene.internal.distributed.EntryScore)

Aggregations

EntryScore (org.apache.geode.cache.lucene.internal.distributed.EntryScore)3 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Region (org.apache.geode.cache.Region)1 Execution (org.apache.geode.cache.execute.Execution)1 ResultCollector (org.apache.geode.cache.execute.ResultCollector)1 LuceneResultStruct (org.apache.geode.cache.lucene.LuceneResultStruct)1 TopEntries (org.apache.geode.cache.lucene.internal.distributed.TopEntries)1 Before (org.junit.Before)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1