View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.index;
20  
21  import java.io.File;
22  import java.io.IOException;
23  
24  import org.apache.lucene.search.Query;
25  import org.apache.maven.index.expr.SourcedSearchExpression;
26  import org.apache.maven.index.search.grouping.GAGrouping;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  
31  public class Mindexer14HitLimitTest extends AbstractNexusIndexerTest {
32      protected File repo = new File(getBasedir(), "target/repo/mindexer14");
33  
34      @Override
35      protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
36          repo.mkdirs();
37  
38          context = nexusIndexer.addIndexingContext("mindexer14", "mindexer14", repo, indexDir, null, null, MIN_CREATORS);
39  
40          nexusIndexer.scan(context, false);
41      }
42  
43      protected void createDummyAis(final String gid, final String aid, final int count) throws IOException {
44          int version = 0;
45  
46          for (int i = 0; i < count; i++) {
47              final ArtifactInfo ai = new ArtifactInfo("mindexer14", gid, aid, String.valueOf(version++), null, "jar");
48  
49              final ArtifactContext ac = new ArtifactContext(null, null, null, ai, ai.calculateGav());
50  
51              nexusIndexer.addArtifactToIndex(ac, context);
52          }
53      }
54  
55      @Test
56      public void testFlatSearchTotalHitsLie1k() throws Exception {
57          createDummyAis("org.test", "mindexer14", 1010);
58  
59          Query query = nexusIndexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.test"));
60  
61          FlatSearchRequest request = new FlatSearchRequest(query);
62  
63          FlatSearchResponse response = nexusIndexer.searchFlat(request);
64  
65          assertEquals(1010, response.getTotalHitsCount());
66  
67          response.close();
68      }
69  
70      @Test
71      public void testFlatSearchUnlimited() throws Exception {
72          createDummyAis("org.test", "mindexer14", 1010);
73  
74          Query query = nexusIndexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.test"));
75  
76          FlatSearchRequest request = new FlatSearchRequest(query);
77  
78          FlatSearchResponse response = nexusIndexer.searchFlat(request);
79  
80          assertEquals(1010, response.getTotalHitsCount());
81          assertEquals(1010, response.getReturnedHitsCount());
82          assertEquals(1010, response.getResults().size());
83  
84          response.close();
85      }
86  
87      @Test
88      public void testFlatSearchLimited() throws Exception {
89          createDummyAis("org.test", "mindexer14", 1010);
90  
91          Query query = nexusIndexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.test"));
92  
93          FlatSearchRequest request = new FlatSearchRequest(query);
94          request.setCount(234);
95  
96          FlatSearchResponse response = nexusIndexer.searchFlat(request);
97  
98          assertEquals(1010, response.getTotalHitsCount());
99          assertEquals(234, response.getReturnedHitsCount());
100         assertEquals(234, response.getResults().size());
101 
102         response.close();
103     }
104 
105     @Test
106     public void testGroupedSearchTotalHitsLie1k() throws Exception {
107         createDummyAis("org.test", "mindexer14", 1010);
108 
109         Query query = nexusIndexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.test"));
110 
111         GroupedSearchRequest request = new GroupedSearchRequest(query, new GAGrouping());
112 
113         GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
114 
115         assertEquals(1010, response.getTotalHitsCount());
116         // in case of GroupedSearch, grouping is the one that defines count
117         // we have 1010 dummies with same GA, and GA grouping, hence count is 1 just like the map has 1 entry
118         assertEquals(1, response.getReturnedHitsCount());
119         assertEquals(1, response.getResults().size());
120 
121         response.close();
122     }
123 
124     @Test
125     public void testIteratorSearchTotalHitsLie1k() throws Exception {
126         createDummyAis("org.test", "mindexer14", 1010);
127 
128         Query query = nexusIndexer.constructQuery(MAVEN.GROUP_ID, new SourcedSearchExpression("org.test"));
129 
130         IteratorSearchRequest request = new IteratorSearchRequest(query);
131 
132         IteratorSearchResponse response = nexusIndexer.searchIterator(request);
133 
134         assertEquals(1010, response.getTotalHitsCount());
135 
136         response.close();
137     }
138 }