From 9246261bc5dfc28efbbb7419ccd9053dc7706209 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 7 Apr 2017 20:47:40 +0200 Subject: [PATCH] [Test] Generate less fields in LocalExporterTests The test creates random documents, it looks like it generates too many fields. Original commit: elastic/x-pack-elasticsearch@f55a3d1fc766133881baacbdf9ce7f0a4571a44c --- .../exporter/local/LocalExporterTests.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java index c949c73146f..eb32fa44131 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java @@ -21,12 +21,12 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; -import org.elasticsearch.test.RandomObjects; import org.elasticsearch.test.TestCluster; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.monitoring.MonitoredSystem; @@ -364,7 +364,19 @@ public class LocalExporterTests extends MonitoringIntegTestCase { String monitoringVersion = MonitoringTemplateUtils.TEMPLATE_VERSION; MonitoringIndex index = randomFrom(MonitoringIndex.values()); XContentType xContentType = randomFrom(XContentType.values()); - BytesReference source = RandomObjects.randomSource(random(), xContentType); + + BytesReference source; + try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { + builder.startObject(); + { + final int nbFields = randomIntBetween(1, 3); + for (int i = 0; i < nbFields; i++) { + builder.field("field_" + i, i); + } + } + builder.endObject(); + source = builder.bytes(); + } // Aligns the type with the monitoring index and monitored system so that we can later // check if the document is indexed in the correct index.