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