From 19545596cf2ba6a7999ae8b1dfacb84090780c0a Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 28 Jan 2016 16:59:05 +0100 Subject: [PATCH] Marvel: Fix NodeStatsRendererTests and NodeStatsTests on Windows Load average is not available anymore on Windows, the tests should not check the presence of the field. Also, "node_stats.json" file is hard to maintain and quite useless so this commit removes it. Original commit: elastic/x-pack-elasticsearch@74d2e0dce65e36e00bce27a543013fc7df10e2f3 --- .../renderer/node/NodeStatsRendererTests.java | 31 ++++--- .../agent/renderer/node/NodeStatsTests.java | 7 ++ .../test/resources/samples/node_stats.json | 82 ------------------- 3 files changed, 27 insertions(+), 93 deletions(-) delete mode 100644 elasticsearch/x-pack/marvel/src/test/resources/samples/node_stats.json diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsRendererTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsRendererTests.java index 582fc70042c..e93d346bd2f 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsRendererTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsRendererTests.java @@ -5,16 +5,19 @@ */ package org.elasticsearch.marvel.agent.renderer.node; +import org.apache.lucene.util.Constants; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; +import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.marvel.agent.collector.node.NodeStatsMarvelDoc; -import org.elasticsearch.marvel.agent.renderer.Renderer; -import org.elasticsearch.marvel.agent.renderer.RendererTestUtils; import org.elasticsearch.node.service.NodeService; import org.elasticsearch.test.ESSingleNodeTestCase; -import org.elasticsearch.test.StreamsUtils; + +import java.util.Map; public class NodeStatsRendererTests extends ESSingleNodeTestCase { - private static final String SAMPLE_FILE = "/samples/node_stats.json"; public void testNodeStatsRenderer() throws Exception { createIndex("index-0"); @@ -27,13 +30,19 @@ public class NodeStatsRendererTests extends ESSingleNodeTestCase { "node-0", true, nodeStats, false, 90.0, true); logger.debug("--> rendering the document"); - Renderer renderer = new NodeStatsRenderer(); - String result = RendererTestUtils.renderAsJSON(marvelDoc, renderer); + try (BytesStreamOutput os = new BytesStreamOutput()) { + new NodeStatsRenderer().render(marvelDoc, XContentType.JSON, os); + Map result = XContentHelper.convertToMap(os.bytes(), false).v2(); - logger.debug("--> loading sample document from file {}", SAMPLE_FILE); - String expected = StreamsUtils.copyToStringFromClasspath(SAMPLE_FILE); - - logger.debug("--> comparing both documents, they must have the same structure"); - RendererTestUtils.assertJSONStructure(result, expected); + for (String field : NodeStatsRenderer.FILTERS) { + if (Constants.WINDOWS) { + // load average is unavailable on Windows + if ("node_stats.os.cpu.load_average.1m".equals(field)) { + continue; + } + } + assertNotNull("expecting field to be present:" + field, XContentMapValues.extractValue(field, result)); + } + } } } \ No newline at end of file diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsTests.java index a289ea03a31..6dc513406e4 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/node/NodeStatsTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.marvel.agent.renderer.node; +import org.apache.lucene.util.Constants; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector; @@ -66,6 +67,12 @@ public class NodeStatsTests extends MarvelIntegTestCase { Map fields = searchHit.sourceAsMap(); for (String filter : filters) { + if (Constants.WINDOWS) { + // load average is unavailable on Windows + if ("node_stats.os.cpu.load_average.1m".equals(filter)) { + continue; + } + } assertContains(filter, fields); } } diff --git a/elasticsearch/x-pack/marvel/src/test/resources/samples/node_stats.json b/elasticsearch/x-pack/marvel/src/test/resources/samples/node_stats.json deleted file mode 100644 index 7e1f85e6429..00000000000 --- a/elasticsearch/x-pack/marvel/src/test/resources/samples/node_stats.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "cluster_uuid": "dsFPzYRyQCe6cq48a0wxkQ", - "timestamp": "2015-07-22T15:54:02.979Z", - "node_stats": { - "node_id": "OB5Mr2NGQe6xYCFvMggReg", - "node_master": true, - "mlockall": false, - "disk_threshold_enabled": true, - "disk_threshold_watermark_high": 90.0, - "indices": { - "docs": { - "count": 0 - }, - "store": { - "size_in_bytes": 0, - "throttle_time_in_millis": 0 - }, - "indexing" : { - "index_total" : 1, - "index_time_in_millis" : 60, - "throttle_time_in_millis" : 0 - }, - "search" : { - "query_total" : 0, - "query_time_in_millis" : 0 - }, - "segments": { - "count": 0 - } - }, - "os": { - "cpu": { - "load_average": { - "1m": 0.66 - } - } - }, - "process": { - "open_file_descriptors": 235, - "max_file_descriptors": 4096, - "cpu": { - "percent": 47 - } - }, - "jvm": { - "mem": { - "heap_used_in_bytes": 58976328, - "heap_used_percent": 1 - }, - "gc": { - "collectors": { - "young": { - "collection_count": 4, - "collection_time_in_millis": 50 - }, - "old": { - "collection_count": 1, - "collection_time_in_millis": 42 - } - } - } - }, - "thread_pool": { - "bulk": { - "rejected": 0 - }, - "index": { - "rejected": 0 - }, - "search": { - "rejected": 0 - } - }, - "fs": { - "total": { - "total_in_bytes": 486599139328, - "free_in_bytes": 228134465536, - "available_in_bytes": 203393003520 - } - } - } -}