1 package org.apache.maven.index;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Set;
24
25 import org.apache.lucene.index.Term;
26 import org.apache.lucene.search.WildcardQuery;
27 import org.apache.lucene.store.Directory;
28 import org.apache.lucene.store.RAMDirectory;
29 import org.apache.maven.index.context.IndexingContext;
30
31 public class Nexus3177HitLimitChecks
32 extends AbstractNexusIndexerTest
33 {
34 protected File repo = new File( getBasedir(), "src/test/repo" );
35
36 protected Directory secondIndexDir = new RAMDirectory();
37
38 protected IndexingContext secondContext;
39
40 @Override
41 protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
42 throws Exception
43 {
44 context =
45 nexusIndexer.addIndexingContext( "nexus-3177", "nexus-3177", repo, indexDir, null, null, DEFAULT_CREATORS );
46
47 secondContext =
48 nexusIndexer.addIndexingContext( "nexus-3177b", "nexus-3177b", repo, secondIndexDir, null, null,
49 DEFAULT_CREATORS );
50
51 nexusIndexer.scan( context );
52 nexusIndexer.scan( secondContext );
53 }
54
55 @Override
56 protected void unprepareNexusIndexer( NexusIndexer nexusIndexer )
57 throws Exception
58 {
59 super.unprepareNexusIndexer( nexusIndexer );
60
61 nexusIndexer.removeIndexingContext( secondContext, false );
62 }
63
64
65
66
67
68
69
70
71
72 public void testHitLimitNotReachedSingleContext()
73 throws Exception
74 {
75 WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) );
76
77 FlatSearchRequest request = new FlatSearchRequest( q );
78 request.setCount( 5 );
79
80 request.getContexts().add( context );
81
82 FlatSearchResponse response = nexusIndexer.searchFlat( request );
83 Set<ArtifactInfo> r = response.getResults();
84 assertEquals( r.toString(), 4, r.size() );
85 assertEquals( r.toString(), 4, response.getTotalHitsCount() );
86 }
87
88 public void testHitLimitEqualSingleContext()
89 throws Exception
90 {
91 WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) );
92
93 FlatSearchRequest request = new FlatSearchRequest( q );
94 request.setCount( 4 );
95
96 request.getContexts().add( context );
97
98 FlatSearchResponse response = nexusIndexer.searchFlat( request );
99 Set<ArtifactInfo> r = response.getResults();
100 assertEquals( r.toString(), 4, r.size() );
101 assertEquals( r.toString(), 4, response.getTotalHitsCount() );
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 public void testHitLimitNotReachedMultipleContexts()
121 throws Exception
122 {
123 WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) );
124
125 FlatSearchRequest request = new FlatSearchRequest( q );
126 request.setCount( 9 );
127
128 request.setArtifactInfoComparator( ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
129 request.getContexts().add( context );
130 request.getContexts().add( secondContext );
131
132 FlatSearchResponse response = nexusIndexer.searchFlat( request );
133 Set<ArtifactInfo> r = response.getResults();
134 assertEquals( r.toString(), 8, r.size() );
135 assertEquals( r.toString(), 8, response.getTotalHitsCount() );
136 }
137
138 public void testHitLimitEqualMultipleContexts()
139 throws Exception
140 {
141 WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) );
142
143 FlatSearchRequest request = new FlatSearchRequest( q );
144 request.setCount( 8 );
145
146 request.setArtifactInfoComparator( ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
147 request.getContexts().add( context );
148 request.getContexts().add( secondContext );
149
150 FlatSearchResponse response = nexusIndexer.searchFlat( request );
151 Set<ArtifactInfo> r = response.getResults();
152 assertEquals( r.toString(), 8, r.size() );
153 assertEquals( r.toString(), 8, response.getTotalHitsCount() );
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 }