@@ -132,73 +132,68 @@ public void testCreateTooManySynonymsUsingRuleUpdates() throws InterruptedExcept
132132 int rulesToUpdate = randomIntBetween (1 , 10 );
133133 int synonymsToCreate = maxSynonymSets - rulesToUpdate ;
134134 String synonymSetId = randomIdentifier ();
135- synonymsManagementAPIService .putSynonymsSet (
136- synonymSetId ,
137- randomSynonymsSet (synonymsToCreate ),
138- randomBoolean (),
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 ], true , new ActionListener <>() {
135+ synonymsManagementAPIService .putSynonymsSet (synonymSetId , randomSynonymsSet (synonymsToCreate ), true , new ActionListener <>() {
136+ @ Override
137+ public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
138+ // Create as many rules as should fail
139+ SynonymRule [] rules = randomSynonymsSet (atLeast (rulesToUpdate + 1 ));
140+ CountDownLatch updatedRulesLatch = new CountDownLatch (rulesToUpdate );
141+ for (int i = 0 ; i < rulesToUpdate ; i ++) {
142+ synonymsManagementAPIService .putSynonymRule (synonymSetId , rules [i ], randomBoolean (), new ActionListener <>() {
143+ @ Override
144+ public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
145+ updatedRulesLatch .countDown ();
146+ }
147+
148+ @ Override
149+ public void onFailure (Exception e ) {
150+ fail (e );
151+ }
152+ });
153+ }
154+ try {
155+ updatedRulesLatch .await (5 , TimeUnit .SECONDS );
156+ } catch (InterruptedException e ) {
157+ fail (e );
158+ }
159+
160+ // Updating more rules fails
161+ int rulesToInsert = rules .length - rulesToUpdate ;
162+ CountDownLatch insertRulesLatch = new CountDownLatch (rulesToInsert );
163+ for (int i = rulesToUpdate ; i < rulesToInsert ; i ++) {
164+ synonymsManagementAPIService .putSynonymRule (
165+ // Error here
166+ synonymSetId ,
167+ rules [i ],
168+ randomBoolean (),
169+ new ActionListener <>() {
147170 @ Override
148171 public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
149- updatedRulesLatch . countDown ( );
172+ fail ( "Shouldn't have been able to update a rule" );
150173 }
151174
152175 @ Override
153176 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 <>() {
174- @ Override
175- public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
176- fail ("Shouldn't have been able to update a rule" );
177- }
178-
179- @ Override
180- public void onFailure (Exception e ) {
181- if (e instanceof IllegalArgumentException == false ) {
182- fail (e );
183- }
184- updatedRulesLatch .countDown ();
177+ if (e instanceof IllegalArgumentException == false ) {
178+ fail (e );
185179 }
180+ updatedRulesLatch .countDown ();
186181 }
187- );
188- }
189- try {
190- insertRulesLatch .await (5 , TimeUnit .SECONDS );
191- } catch (InterruptedException e ) {
192- fail (e );
193- }
182+ }
183+ );
194184 }
195-
196- @ Override
197- public void onFailure ( Exception e ) {
185+ try {
186+ insertRulesLatch . await ( 5 , TimeUnit . SECONDS );
187+ } catch ( InterruptedException e ) {
198188 fail (e );
199189 }
200190 }
201- );
191+
192+ @ Override
193+ public void onFailure (Exception e ) {
194+ fail (e );
195+ }
196+ });
202197
203198 latch .await (5 , TimeUnit .SECONDS );
204199 }
@@ -243,21 +238,26 @@ public void testCreateRuleWithMaxSynonyms() throws InterruptedException {
243238 String synonymSetId = randomIdentifier ();
244239 String ruleId = randomIdentifier ();
245240 SynonymRule [] synonymsSet = randomSynonymsSet (maxSynonymSets , maxSynonymSets );
246- synonymsManagementAPIService .putSynonymsSet (synonymSetId , synonymsSet , randomBoolean () , new ActionListener <>() {
241+ synonymsManagementAPIService .putSynonymsSet (synonymSetId , synonymsSet , true , new ActionListener <>() {
247242 @ Override
248243 public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
249244 // Updating a rule fails
250- synonymsManagementAPIService .putSynonymRule (synonymSetId , randomSynonymRule (ruleId ), true , 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- }
245+ synonymsManagementAPIService .putSynonymRule (
246+ synonymSetId ,
247+ randomSynonymRule (ruleId ),
248+ randomBoolean (),
249+ new ActionListener <>() {
250+ @ Override
251+ public void onResponse (SynonymsManagementAPIService .SynonymsReloadResult synonymsReloadResult ) {
252+ fail ("Should not create a new rule that does not exist when at max capacity" );
253+ }
255254
256- @ Override
257- public void onFailure (Exception e ) {
258- latch .countDown ();
255+ @ Override
256+ public void onFailure (Exception e ) {
257+ latch .countDown ();
258+ }
259259 }
260- } );
260+ );
261261 }
262262
263263 @ Override
0 commit comments