View Javadoc

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