Skip to content

Commit 01f0dbf

Browse files
committed
Fix tests
1 parent 882a2dd commit 01f0dbf

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -190,51 +190,42 @@ public void testSetLevels() {
190190
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build()));
191191
fail();
192192
} catch (IllegalArgumentException ex) {
193-
final String expected = "illegal value can't update [index.indexing.slowlog.threshold.index.trace] from [-1] to [NOT A TIME VALUE]";
194-
assertThat(ex, hasToString(containsString(expected)));
195-
assertNotNull(ex.getCause());
196-
assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
197-
final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
198-
assertThat(cause, hasToString(containsString("failed to parse setting [index.indexing.slowlog.threshold.index.trace] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized")));
193+
assertTimeValueException(ex, "index.indexing.slowlog.threshold.index.trace");
199194
}
200195

201196
try {
202197
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build()));
203198
fail();
204199
} catch (IllegalArgumentException ex) {
205-
final String expected = "illegal value can't update [index.indexing.slowlog.threshold.index.debug] from [-1] to [NOT A TIME VALUE]";
206-
assertThat(ex, hasToString(containsString(expected)));
207-
assertNotNull(ex.getCause());
208-
assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
209-
final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
210-
assertThat(cause, hasToString(containsString("failed to parse setting [index.indexing.slowlog.threshold.index.debug] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized")));
200+
assertTimeValueException(ex, "index.indexing.slowlog.threshold.index.debug");
211201
}
212202

213203
try {
214204
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO_SETTING.getKey(), "NOT A TIME VALUE").build()));
215205
fail();
216206
} catch (IllegalArgumentException ex) {
217-
final String expected = "illegal value can't update [index.indexing.slowlog.threshold.index.info] from [-1] to [NOT A TIME VALUE]";
218-
assertThat(ex, hasToString(containsString(expected)));
219-
assertNotNull(ex.getCause());
220-
assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
221-
final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
222-
assertThat(cause, hasToString(containsString("failed to parse setting [index.indexing.slowlog.threshold.index.info] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized")));
207+
assertTimeValueException(ex, "index.indexing.slowlog.threshold.index.info");
223208
}
224209

225210
try {
226211
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN_SETTING.getKey(), "NOT A TIME VALUE").build()));
227212
fail();
228213
} catch (IllegalArgumentException ex) {
229-
final String expected = "illegal value can't update [index.indexing.slowlog.threshold.index.warn] from [-1] to [NOT A TIME VALUE]";
230-
assertThat(ex, hasToString(containsString(expected)));
231-
assertNotNull(ex.getCause());
232-
assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
233-
final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
234-
assertThat(cause, hasToString(containsString("failed to parse setting [index.indexing.slowlog.threshold.index.warn] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized")));
214+
assertTimeValueException(ex, "index.indexing.slowlog.threshold.index.warn");
235215
}
236216
}
237217

218+
private void assertTimeValueException(final IllegalArgumentException e, final String key) {
219+
final String expected = "illegal value can't update [" + key + "] from [-1] to [NOT A TIME VALUE]";
220+
assertThat(e, hasToString(containsString(expected)));
221+
assertNotNull(e.getCause());
222+
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
223+
final IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
224+
final String causeExpected =
225+
"failed to parse setting [" + key + "] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized";
226+
assertThat(cause, hasToString(containsString(causeExpected)));
227+
}
228+
238229
private IndexMetaData newIndexMeta(String name, Settings indexSettings) {
239230
Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
240231
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)

core/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
import java.io.IOException;
4242

43+
import static org.hamcrest.Matchers.hasToString;
44+
import static org.hamcrest.Matchers.instanceOf;
4345
import static org.hamcrest.Matchers.not;
4446
import static org.hamcrest.Matchers.containsString;
4547
import static org.hamcrest.Matchers.startsWith;
@@ -176,7 +178,12 @@ public void testLevelSetting() {
176178
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), "NOT A LEVEL").build()));
177179
fail();
178180
} 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")));
180187
}
181188
assertEquals(SlowLogLevel.TRACE, log.getLevel());
182189
}
@@ -227,28 +234,28 @@ public void testSetQueryLevels() {
227234
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build()));
228235
fail();
229236
} 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");
231238
}
232239

233240
try {
234241
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build()));
235242
fail();
236243
} 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");
238245
}
239246

240247
try {
241248
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING.getKey(), "NOT A TIME VALUE").build()));
242249
fail();
243250
} 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");
245252
}
246253

247254
try {
248255
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING.getKey(), "NOT A TIME VALUE").build()));
249256
fail();
250257
} 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");
252259
}
253260
}
254261

@@ -298,31 +305,41 @@ public void testSetFetchLevels() {
298305
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build()));
299306
fail();
300307
} 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");
302309
}
303310

304311
try {
305312
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build()));
306313
fail();
307314
} 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");
309316
}
310317

311318
try {
312319
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING.getKey(), "NOT A TIME VALUE").build()));
313320
fail();
314321
} 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");
316323
}
317324

318325
try {
319326
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING.getKey(), "NOT A TIME VALUE").build()));
320327
fail();
321328
} 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");
323330
}
324331
}
325332

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+
}
326343

327344
private IndexMetaData newIndexMeta(String name, Settings indexSettings) {
328345
Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)

0 commit comments

Comments
 (0)