@@ -128,152 +128,145 @@ public void onFailure(Exception e) {
128128 }
129129
130130 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 <>() {
148174 @ Override
149175 public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
150- updatedRulesLatch . countDown ( );
176+ fail ( "Shouldn't have been able to update a rule" );
151177 }
152178
153179 @ Override
154180 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 );
186183 }
184+ updatedRulesLatch .countDown ();
187185 }
188- );
189- }
190- try {
191- insertRulesLatch .await (5 , TimeUnit .SECONDS );
192- } catch (InterruptedException e ) {
193- fail (e );
194- }
186+ }
187+ );
195188 }
196-
197- @ Override
198- public void onFailure ( Exception e ) {
189+ try {
190+ insertRulesLatch . await ( 5 , TimeUnit . SECONDS );
191+ } catch ( InterruptedException e ) {
199192 fail (e );
200193 }
201194 }
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- }
235195
236196 @ Override
237197 public void onFailure (Exception e ) {
238198 fail (e );
239199 }
240- });
200+ }
201+ );
241202
242- latch .await (5 , TimeUnit .SECONDS );
243- }
203+ latch .await (5 , TimeUnit .SECONDS );
244204 }
245205
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 <>() {
257219 @ Override
258220 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 ( );
260222 }
261223
262224 @ Override
263225 public void onFailure (Exception e ) {
264- latch . countDown ( );
226+ fail ( "Should update a rule that already exists at max capcity" );
265227 }
266- });
267- }
228+ }
229+ );
230+ }
268231
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+ }
274255
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 );
277270 }
278271
279272 public void testTooManySynonymsOnIndexTriggersWarning () throws InterruptedException {
0 commit comments