|
40 | 40 |
|
41 | 41 | import java.io.IOException; |
42 | 42 |
|
| 43 | +import static org.hamcrest.Matchers.hasToString; |
| 44 | +import static org.hamcrest.Matchers.instanceOf; |
43 | 45 | import static org.hamcrest.Matchers.not; |
44 | 46 | import static org.hamcrest.Matchers.containsString; |
45 | 47 | import static org.hamcrest.Matchers.startsWith; |
@@ -176,7 +178,12 @@ public void testLevelSetting() { |
176 | 178 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), "NOT A LEVEL").build())); |
177 | 179 | fail(); |
178 | 180 | } catch (IllegalArgumentException ex) { |
179 | | - assertEquals(ex.getMessage(), "No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL"); |
| 181 | + final String expected = "illegal value can't update [index.search.slowlog.level] from [TRACE] to [NOT A LEVEL]"; |
| 182 | + assertThat(ex, hasToString(containsString(expected))); |
| 183 | + assertNotNull(ex.getCause()); |
| 184 | + assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class)); |
| 185 | + final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause(); |
| 186 | + assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL"))); |
180 | 187 | } |
181 | 188 | assertEquals(SlowLogLevel.TRACE, log.getLevel()); |
182 | 189 | } |
@@ -227,28 +234,28 @@ public void testSetQueryLevels() { |
227 | 234 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build())); |
228 | 235 | fail(); |
229 | 236 | } catch (IllegalArgumentException ex) { |
230 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.query.trace] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 237 | + assertTimeValueException(ex, "index.search.slowlog.threshold.query.trace"); |
231 | 238 | } |
232 | 239 |
|
233 | 240 | try { |
234 | 241 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build())); |
235 | 242 | fail(); |
236 | 243 | } catch (IllegalArgumentException ex) { |
237 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.query.debug] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 244 | + assertTimeValueException(ex, "index.search.slowlog.threshold.query.debug"); |
238 | 245 | } |
239 | 246 |
|
240 | 247 | try { |
241 | 248 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING.getKey(), "NOT A TIME VALUE").build())); |
242 | 249 | fail(); |
243 | 250 | } catch (IllegalArgumentException ex) { |
244 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.query.info] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 251 | + assertTimeValueException(ex, "index.search.slowlog.threshold.query.info"); |
245 | 252 | } |
246 | 253 |
|
247 | 254 | try { |
248 | 255 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING.getKey(), "NOT A TIME VALUE").build())); |
249 | 256 | fail(); |
250 | 257 | } catch (IllegalArgumentException ex) { |
251 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.query.warn] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 258 | + assertTimeValueException(ex, "index.search.slowlog.threshold.query.warn"); |
252 | 259 | } |
253 | 260 | } |
254 | 261 |
|
@@ -298,31 +305,41 @@ public void testSetFetchLevels() { |
298 | 305 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build())); |
299 | 306 | fail(); |
300 | 307 | } catch (IllegalArgumentException ex) { |
301 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.fetch.trace] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 308 | + assertTimeValueException(ex, "index.search.slowlog.threshold.fetch.trace"); |
302 | 309 | } |
303 | 310 |
|
304 | 311 | try { |
305 | 312 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build())); |
306 | 313 | fail(); |
307 | 314 | } catch (IllegalArgumentException ex) { |
308 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.fetch.debug] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 315 | + assertTimeValueException(ex, "index.search.slowlog.threshold.fetch.debug"); |
309 | 316 | } |
310 | 317 |
|
311 | 318 | try { |
312 | 319 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING.getKey(), "NOT A TIME VALUE").build())); |
313 | 320 | fail(); |
314 | 321 | } catch (IllegalArgumentException ex) { |
315 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.fetch.info] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 322 | + assertTimeValueException(ex, "index.search.slowlog.threshold.fetch.info"); |
316 | 323 | } |
317 | 324 |
|
318 | 325 | try { |
319 | 326 | settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING.getKey(), "NOT A TIME VALUE").build())); |
320 | 327 | fail(); |
321 | 328 | } catch (IllegalArgumentException ex) { |
322 | | - assertEquals(ex.getMessage(), "failed to parse setting [index.search.slowlog.threshold.fetch.warn] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"); |
| 329 | + assertTimeValueException(ex, "index.search.slowlog.threshold.fetch.warn"); |
323 | 330 | } |
324 | 331 | } |
325 | 332 |
|
| 333 | + private void assertTimeValueException(final IllegalArgumentException e, final String key) { |
| 334 | + final String expected = "illegal value can't update [" + key + "] from [-1] to [NOT A TIME VALUE]"; |
| 335 | + assertThat(e, hasToString(containsString(expected))); |
| 336 | + assertNotNull(e.getCause()); |
| 337 | + assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); |
| 338 | + final IllegalArgumentException cause = (IllegalArgumentException) e.getCause(); |
| 339 | + final String causeExpected = |
| 340 | + "failed to parse setting [" + key + "] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized"; |
| 341 | + assertThat(cause, hasToString(containsString(causeExpected))); |
| 342 | + } |
326 | 343 |
|
327 | 344 | private IndexMetaData newIndexMeta(String name, Settings indexSettings) { |
328 | 345 | Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
|
0 commit comments