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