|
9 | 9 |
|
10 | 10 | package org.elasticsearch.synonyms; |
11 | 11 |
|
12 | | -import com.carrotsearch.randomizedtesting.annotations.Repeat; |
13 | | - |
14 | 12 | import org.apache.logging.log4j.Logger; |
15 | 13 | import org.elasticsearch.action.ActionListener; |
16 | 14 | import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; |
@@ -129,149 +127,153 @@ public void onFailure(Exception e) { |
129 | 127 | latch.await(5, TimeUnit.SECONDS); |
130 | 128 | } |
131 | 129 |
|
132 | | - @Repeat(iterations=500) |
133 | 130 | public void testCreateTooManySynonymsUsingRuleUpdates() throws InterruptedException { |
134 | | - CountDownLatch latch = new CountDownLatch(1); |
135 | | - int rulesToUpdate = randomIntBetween(1, 10); |
136 | | - int synonymsToCreate = maxSynonymSets - rulesToUpdate; |
137 | | - String synonymSetId = randomIdentifier(); |
138 | | - synonymsManagementAPIService.putSynonymsSet( |
139 | | - synonymSetId, |
140 | | - randomSynonymsSet(synonymsToCreate), |
141 | | - true, |
142 | | - new ActionListener<>() { |
143 | | - @Override |
144 | | - public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
145 | | - // Create as many rules as should fail |
146 | | - SynonymRule[] rules = randomSynonymsSet(atLeast(rulesToUpdate + 1)); |
147 | | - CountDownLatch updatedRulesLatch = new CountDownLatch(rulesToUpdate); |
148 | | - for (int i = 0; i < rulesToUpdate; i++) { |
149 | | - synonymsManagementAPIService.putSynonymRule(synonymSetId, rules[i], randomBoolean(), new ActionListener<>() { |
150 | | - @Override |
151 | | - public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
152 | | - updatedRulesLatch.countDown(); |
153 | | - } |
154 | | - |
155 | | - @Override |
156 | | - public void onFailure(Exception e) { |
157 | | - fail(e); |
158 | | - } |
159 | | - }); |
160 | | - } |
161 | | - try { |
162 | | - updatedRulesLatch.await(5, TimeUnit.SECONDS); |
163 | | - } catch (InterruptedException e) { |
164 | | - fail(e); |
165 | | - } |
166 | | - |
167 | | - // Updating more rules fails |
168 | | - int rulesToInsert = rules.length - rulesToUpdate; |
169 | | - CountDownLatch insertRulesLatch = new CountDownLatch(rulesToInsert); |
170 | | - for (int i = rulesToUpdate; i < rulesToInsert; i++) { |
171 | | - synonymsManagementAPIService.putSynonymRule( |
172 | | - // Error here |
173 | | - synonymSetId, |
174 | | - rules[i], |
175 | | - randomBoolean(), |
176 | | - new ActionListener<>() { |
| 131 | + for (int iters = 0; iters < 500; iters++) { |
| 132 | + CountDownLatch latch = new CountDownLatch(1); |
| 133 | + int rulesToUpdate = randomIntBetween(1, 10); |
| 134 | + int synonymsToCreate = maxSynonymSets - rulesToUpdate; |
| 135 | + String synonymSetId = randomIdentifier(); |
| 136 | + synonymsManagementAPIService.putSynonymsSet( |
| 137 | + synonymSetId, |
| 138 | + randomSynonymsSet(synonymsToCreate), |
| 139 | + true, |
| 140 | + new ActionListener<>() { |
| 141 | + @Override |
| 142 | + public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
| 143 | + // Create as many rules as should fail |
| 144 | + SynonymRule[] rules = randomSynonymsSet(atLeast(rulesToUpdate + 1)); |
| 145 | + CountDownLatch updatedRulesLatch = new CountDownLatch(rulesToUpdate); |
| 146 | + for (int i = 0; i < rulesToUpdate; i++) { |
| 147 | + synonymsManagementAPIService.putSynonymRule(synonymSetId, rules[i], randomBoolean(), new ActionListener<>() { |
177 | 148 | @Override |
178 | 149 | public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
179 | | - fail("Shouldn't have been able to update a rule"); |
| 150 | + updatedRulesLatch.countDown(); |
180 | 151 | } |
181 | 152 |
|
182 | 153 | @Override |
183 | 154 | public void onFailure(Exception e) { |
184 | | - if (e instanceof IllegalArgumentException == false) { |
185 | | - fail(e); |
| 155 | + fail(e); |
| 156 | + } |
| 157 | + }); |
| 158 | + } |
| 159 | + try { |
| 160 | + updatedRulesLatch.await(5, TimeUnit.SECONDS); |
| 161 | + } catch (InterruptedException e) { |
| 162 | + fail(e); |
| 163 | + } |
| 164 | + |
| 165 | + // Updating more rules fails |
| 166 | + int rulesToInsert = rules.length - rulesToUpdate; |
| 167 | + CountDownLatch insertRulesLatch = new CountDownLatch(rulesToInsert); |
| 168 | + for (int i = rulesToUpdate; i < rulesToInsert; i++) { |
| 169 | + synonymsManagementAPIService.putSynonymRule( |
| 170 | + // Error here |
| 171 | + synonymSetId, |
| 172 | + rules[i], |
| 173 | + randomBoolean(), |
| 174 | + new ActionListener<>() { |
| 175 | + @Override |
| 176 | + public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
| 177 | + fail("Shouldn't have been able to update a rule"); |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public void onFailure(Exception e) { |
| 182 | + if (e instanceof IllegalArgumentException == false) { |
| 183 | + fail(e); |
| 184 | + } |
| 185 | + updatedRulesLatch.countDown(); |
186 | 186 | } |
187 | | - updatedRulesLatch.countDown(); |
188 | 187 | } |
189 | | - } |
190 | | - ); |
| 188 | + ); |
| 189 | + } |
| 190 | + try { |
| 191 | + insertRulesLatch.await(5, TimeUnit.SECONDS); |
| 192 | + } catch (InterruptedException e) { |
| 193 | + fail(e); |
| 194 | + } |
191 | 195 | } |
192 | | - try { |
193 | | - insertRulesLatch.await(5, TimeUnit.SECONDS); |
194 | | - } catch (InterruptedException e) { |
| 196 | + |
| 197 | + @Override |
| 198 | + public void onFailure(Exception e) { |
195 | 199 | fail(e); |
196 | 200 | } |
197 | 201 | } |
| 202 | + ); |
| 203 | + |
| 204 | + latch.await(5, TimeUnit.SECONDS); |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + public void testUpdateRuleWithMaxSynonyms() throws InterruptedException { |
| 209 | + for (int iters = 0; iters < 500; iters++) { |
| 210 | + |
| 211 | + CountDownLatch latch = new CountDownLatch(1); |
| 212 | + String synonymSetId = randomIdentifier(); |
| 213 | + SynonymRule[] synonymsSet = randomSynonymsSet(maxSynonymSets, maxSynonymSets); |
| 214 | + synonymsManagementAPIService.putSynonymsSet(synonymSetId, synonymsSet, true, new ActionListener<>() { |
| 215 | + @Override |
| 216 | + public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
| 217 | + // Updating a rule fails |
| 218 | + synonymsManagementAPIService.putSynonymRule( |
| 219 | + synonymSetId, |
| 220 | + synonymsSet[randomIntBetween(0, maxSynonymSets - 1)], |
| 221 | + randomBoolean(), |
| 222 | + new ActionListener<>() { |
| 223 | + @Override |
| 224 | + public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
| 225 | + latch.countDown(); |
| 226 | + } |
| 227 | + |
| 228 | + @Override |
| 229 | + public void onFailure(Exception e) { |
| 230 | + fail("Should update a rule that already exists at max capcity"); |
| 231 | + } |
| 232 | + } |
| 233 | + ); |
| 234 | + } |
198 | 235 |
|
199 | 236 | @Override |
200 | 237 | public void onFailure(Exception e) { |
201 | 238 | fail(e); |
202 | 239 | } |
203 | | - } |
204 | | - ); |
| 240 | + }); |
205 | 241 |
|
206 | | - latch.await(5, TimeUnit.SECONDS); |
| 242 | + latch.await(5, TimeUnit.SECONDS); |
| 243 | + } |
207 | 244 | } |
208 | 245 |
|
209 | | - @Repeat(iterations=500) |
210 | | - public void testUpdateRuleWithMaxSynonyms() throws InterruptedException { |
211 | | - CountDownLatch latch = new CountDownLatch(1); |
212 | | - String synonymSetId = randomIdentifier(); |
213 | | - SynonymRule[] synonymsSet = randomSynonymsSet(maxSynonymSets, maxSynonymSets); |
214 | | - synonymsManagementAPIService.putSynonymsSet(synonymSetId, synonymsSet, true, new ActionListener<>() { |
215 | | - @Override |
216 | | - public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
217 | | - // Updating a rule fails |
218 | | - synonymsManagementAPIService.putSynonymRule( |
219 | | - synonymSetId, |
220 | | - synonymsSet[randomIntBetween(0, maxSynonymSets - 1)], |
221 | | - randomBoolean(), |
222 | | - new ActionListener<>() { |
| 246 | + public void testCreateRuleWithMaxSynonyms() throws InterruptedException { |
| 247 | + for (int iters = 0; iters < 500; iters++) { |
| 248 | + CountDownLatch latch = new CountDownLatch(1); |
| 249 | + String synonymSetId = randomIdentifier(); |
| 250 | + String ruleId = randomIdentifier(); |
| 251 | + SynonymRule[] synonymsSet = randomSynonymsSet(maxSynonymSets, maxSynonymSets); |
| 252 | + synonymsManagementAPIService.putSynonymsSet(synonymSetId, synonymsSet, true, new ActionListener<>() { |
| 253 | + @Override |
| 254 | + public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
| 255 | + // Updating a rule fails |
| 256 | + synonymsManagementAPIService.putSynonymRule(synonymSetId, randomSynonymRule(ruleId), randomBoolean(), new ActionListener<>() { |
223 | 257 | @Override |
224 | 258 | public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
225 | | - latch.countDown(); |
| 259 | + fail("Should not create a new rule that does not exist when at max capacity"); |
226 | 260 | } |
227 | 261 |
|
228 | 262 | @Override |
229 | 263 | public void onFailure(Exception e) { |
230 | | - fail("Should update a rule that already exists at max capcity"); |
| 264 | + latch.countDown(); |
231 | 265 | } |
232 | | - } |
233 | | - ); |
234 | | - } |
235 | | - |
236 | | - @Override |
237 | | - public void onFailure(Exception e) { |
238 | | - fail(e); |
239 | | - } |
240 | | - }); |
241 | | - |
242 | | - latch.await(5, TimeUnit.SECONDS); |
243 | | - } |
244 | | - |
245 | | - @Repeat(iterations=500) |
246 | | - public void testCreateRuleWithMaxSynonyms() throws InterruptedException { |
247 | | - CountDownLatch latch = new CountDownLatch(1); |
248 | | - String synonymSetId = randomIdentifier(); |
249 | | - String ruleId = randomIdentifier(); |
250 | | - SynonymRule[] synonymsSet = randomSynonymsSet(maxSynonymSets, maxSynonymSets); |
251 | | - synonymsManagementAPIService.putSynonymsSet(synonymSetId, synonymsSet, true, new ActionListener<>() { |
252 | | - @Override |
253 | | - public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
254 | | - // Updating a rule fails |
255 | | - synonymsManagementAPIService.putSynonymRule(synonymSetId, randomSynonymRule(ruleId), randomBoolean(), new ActionListener<>() { |
256 | | - @Override |
257 | | - public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { |
258 | | - fail("Should not create a new rule that does not exist when at max capacity"); |
259 | | - } |
260 | | - |
261 | | - @Override |
262 | | - public void onFailure(Exception e) { |
263 | | - latch.countDown(); |
264 | | - } |
265 | | - }); |
266 | | - } |
| 266 | + }); |
| 267 | + } |
267 | 268 |
|
268 | | - @Override |
269 | | - public void onFailure(Exception e) { |
270 | | - fail(e); |
271 | | - } |
272 | | - }); |
| 269 | + @Override |
| 270 | + public void onFailure(Exception e) { |
| 271 | + fail(e); |
| 272 | + } |
| 273 | + }); |
273 | 274 |
|
274 | | - latch.await(5, TimeUnit.SECONDS); |
| 275 | + latch.await(5, TimeUnit.SECONDS); |
| 276 | + } |
275 | 277 | } |
276 | 278 |
|
277 | 279 | public void testTooManySynonymsOnIndexTriggersWarning() throws InterruptedException { |
|
0 commit comments