@@ -133,73 +133,68 @@ public void testCreateTooManySynonymsUsingRuleUpdates() throws InterruptedExcept
133133 int rulesToUpdate = randomIntBetween (1 , 10 );
134134 int synonymsToCreate = maxSynonymSets - rulesToUpdate ;
135135 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 <>() {
136+ synonymsManagementAPIService .putSynonymsSet (synonymSetId , randomSynonymsSet (synonymsToCreate ), true , new ActionListener <>() {
137+ @ Override
138+ public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
139+ // Create as many rules as should fail
140+ SynonymRule [] rules = randomSynonymsSet (atLeast (rulesToUpdate + 1 ));
141+ CountDownLatch updatedRulesLatch = new CountDownLatch (rulesToUpdate );
142+ for (int i = 0 ; i < rulesToUpdate ; i ++) {
143+ synonymsManagementAPIService .putSynonymRule (synonymSetId , rules [i ], randomBoolean (), new ActionListener <>() {
144+ @ Override
145+ public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
146+ updatedRulesLatch .countDown ();
147+ }
148+
149+ @ Override
150+ public void onFailure (Exception e ) {
151+ fail (e );
152+ }
153+ });
154+ }
155+ try {
156+ updatedRulesLatch .await (5 , TimeUnit .SECONDS );
157+ } catch (InterruptedException e ) {
158+ fail (e );
159+ }
160+
161+ // Updating more rules fails
162+ int rulesToInsert = rules .length - rulesToUpdate ;
163+ CountDownLatch insertRulesLatch = new CountDownLatch (rulesToInsert );
164+ for (int i = rulesToUpdate ; i < rulesToInsert ; i ++) {
165+ synonymsManagementAPIService .putSynonymRule (
166+ // Error here
167+ synonymSetId ,
168+ rules [i ],
169+ randomBoolean (),
170+ new ActionListener <>() {
148171 @ Override
149172 public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
150- updatedRulesLatch . countDown ( );
173+ fail ( "Shouldn't have been able to update a rule" );
151174 }
152175
153176 @ Override
154177 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 ();
178+ if (e instanceof IllegalArgumentException == false ) {
179+ fail (e );
186180 }
181+ updatedRulesLatch .countDown ();
187182 }
188- );
189- }
190- try {
191- insertRulesLatch .await (5 , TimeUnit .SECONDS );
192- } catch (InterruptedException e ) {
193- fail (e );
194- }
183+ }
184+ );
195185 }
196-
197- @ Override
198- public void onFailure ( Exception e ) {
186+ try {
187+ insertRulesLatch . await ( 5 , TimeUnit . SECONDS );
188+ } catch ( InterruptedException e ) {
199189 fail (e );
200190 }
201191 }
202- );
192+
193+ @ Override
194+ public void onFailure (Exception e ) {
195+ fail (e );
196+ }
197+ });
203198
204199 latch .await (5 , TimeUnit .SECONDS );
205200 }
@@ -253,17 +248,22 @@ public void testCreateRuleWithMaxSynonyms() throws InterruptedException {
253248 @ Override
254249 public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
255250 // Updating a rule fails
256- synonymsManagementAPIService .putSynonymRule (synonymSetId , randomSynonymRule (ruleId ), randomBoolean (), new ActionListener <>() {
257- @ Override
258- public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
259- fail ("Should not create a new rule that does not exist when at max capacity" );
260- }
251+ synonymsManagementAPIService .putSynonymRule (
252+ synonymSetId ,
253+ randomSynonymRule (ruleId ),
254+ randomBoolean (),
255+ 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+ }
261260
262- @ Override
263- public void onFailure (Exception e ) {
264- latch .countDown ();
261+ @ Override
262+ public void onFailure (Exception e ) {
263+ latch .countDown ();
264+ }
265265 }
266- } );
266+ );
267267 }
268268
269269 @ Override
0 commit comments