|
16 | 16 | import org.elasticsearch.common.settings.ClusterSettings;
|
17 | 17 | import org.elasticsearch.common.settings.Settings;
|
18 | 18 | import org.elasticsearch.common.util.Maps;
|
| 19 | +import org.elasticsearch.common.xcontent.XContentElasticsearchExtension; |
19 | 20 | import org.elasticsearch.common.xcontent.XContentHelper;
|
20 | 21 | import org.elasticsearch.core.TimeValue;
|
21 | 22 | import org.elasticsearch.node.Node;
|
|
41 | 42 | import java.util.concurrent.atomic.AtomicBoolean;
|
42 | 43 | import java.util.concurrent.locks.ReadWriteLock;
|
43 | 44 | import java.util.concurrent.locks.ReentrantReadWriteLock;
|
| 45 | +import java.util.function.BiConsumer; |
44 | 46 | import java.util.function.Consumer;
|
45 | 47 |
|
46 | 48 | import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_CLIENT_STATS_ENABLED;
|
@@ -419,18 +421,18 @@ public void testToXContent() throws IOException {
|
419 | 421 | assertEquals(description, clientStats.forwardedFor(), xcontentMap.get("x_forwarded_for"));
|
420 | 422 | assertEquals(description, clientStats.opaqueId(), xcontentMap.get("x_opaque_id"));
|
421 | 423 |
|
422 |
| - assertEquals(description, clientStats.openedTimeMillis(), xcontentMap.get("opened_time_millis")); |
423 |
| - assertEquals(description, Instant.ofEpochMilli(clientStats.openedTimeMillis()).toString(), xcontentMap.get("opened_time")); |
424 |
| - |
425 |
| - assertEquals(description, clientStats.closedTimeMillis(), xcontentMap.get("closed_time_millis")); |
426 |
| - assertEquals(description, Instant.ofEpochMilli(clientStats.closedTimeMillis()).toString(), xcontentMap.get("closed_time")); |
| 424 | + final BiConsumer<Long, String> timestampFieldAsserter = (timestampMillis, fieldName) -> { |
| 425 | + assertEquals(description, timestampMillis, xcontentMap.get(fieldName + "_millis")); |
| 426 | + assertEquals( |
| 427 | + description, |
| 428 | + XContentElasticsearchExtension.DEFAULT_FORMATTER.format(Instant.ofEpochMilli(timestampMillis)), |
| 429 | + xcontentMap.get(fieldName) |
| 430 | + ); |
| 431 | + }; |
427 | 432 |
|
428 |
| - assertEquals(description, clientStats.lastRequestTimeMillis(), xcontentMap.get("last_request_time_millis")); |
429 |
| - assertEquals( |
430 |
| - description, |
431 |
| - Instant.ofEpochMilli(clientStats.lastRequestTimeMillis()).toString(), |
432 |
| - xcontentMap.get("last_request_time") |
433 |
| - ); |
| 433 | + timestampFieldAsserter.accept(clientStats.openedTimeMillis(), "opened_time"); |
| 434 | + timestampFieldAsserter.accept(clientStats.closedTimeMillis(), "closed_time"); |
| 435 | + timestampFieldAsserter.accept(clientStats.lastRequestTimeMillis(), "last_request_time"); |
434 | 436 |
|
435 | 437 | assertEquals(description, clientStats.requestCount(), (long) xcontentMap.get("request_count"));
|
436 | 438 | assertEquals(description, clientStats.requestSizeBytes(), (long) xcontentMap.get("request_size_bytes"));
|
|
0 commit comments