From 541644fbb22e1e874ac9c35b138395986e02f350 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 1 Sep 2015 09:44:43 +0200 Subject: [PATCH] Marvel: Remove usages of Guava's ImmutableMap and Predicate Original commit: elastic/x-pack-elasticsearch@71d0a7f43690fd1534a7a4c78517f2ae4bf7f5d4 --- .../agent/renderer/RendererRegistry.java | 4 +-- .../agent/exporter/HttpESExporterTests.java | 25 ++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/RendererRegistry.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/RendererRegistry.java index 5c0108cdc36..c22fb4f699f 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/RendererRegistry.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/RendererRegistry.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.marvel.agent.renderer; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.inject.Inject; +import java.util.Collections; import java.util.Map; public class RendererRegistry { @@ -16,7 +16,7 @@ public class RendererRegistry { @Inject public RendererRegistry(Map renderers) { - this.renderers = ImmutableMap.copyOf(renderers); + this.renderers = Collections.unmodifiableMap(renderers); } public Renderer renderer(String type) { diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java index 551307cc5ed..e3041ce006d 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.marvel.agent.exporter; -import com.google.common.base.Predicate; import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.common.Strings; @@ -22,7 +21,6 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.hamcrest.Matchers; import org.junit.Test; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -30,6 +28,7 @@ import java.util.Collections; import java.util.concurrent.atomic.AtomicLong; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.equalTo; // Transport Client instantiation also calls the marvel plugin, which then fails to find modules @@ -162,14 +161,15 @@ public class HttpESExporterTests extends ESIntegTestCase { } @Test - public void testHostFailureChecksTemplate() throws InterruptedException, IOException { + public void testHostFailureChecksTemplate() throws Exception { Settings.Builder builder = Settings.builder() .put(MarvelSettings.STARTUP_DELAY, "200m") .put(Node.HTTP_ENABLED, true); final String node0 = internalCluster().startNode(builder); - String node1 = internalCluster().startNode(builder); + final HttpESExporter httpEsExporter0 = getEsExporter(node0); + assertThat(node0, equalTo(internalCluster().getMasterName())); - HttpESExporter httpEsExporter0 = getEsExporter(node0); + final String node1 = internalCluster().startNode(builder); final HttpESExporter httpEsExporter1 = getEsExporter(node1); logger.info("--> exporting events to force host resolution"); @@ -194,23 +194,18 @@ public class HttpESExporterTests extends ESIntegTestCase { assertAcked(client().admin().indices().prepareDeleteTemplate("marvel").get()); logger.info("--> shutting down node0"); - internalCluster().stopRandomNode(new Predicate() { - @Override - public boolean apply(Settings settings) { - return settings.get("name").equals(node0); - } - }); + internalCluster().stopCurrentMasterNode(); logger.info("--> exporting events from node1"); // we use assert busy node because url caching may cause the node failure to be only detected while sending the event - assertTrue("failed to find a template named 'marvel'", awaitBusy(new Predicate() { + assertBusy(new Runnable() { @Override - public boolean apply(Object o) { + public void run() { httpEsExporter1.export(Collections.singletonList(newRandomMarvelDoc())); logger.debug("--> checking for template"); - return findMarvelTemplate(); + assertTrue("failed to find a template named 'marvel'", findMarvelTemplate()); } - })); + }); } private HttpESExporter getEsExporter() {