From 28b5c7ce7848f8da4739bb082d4030821846b1ce Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 31 Jan 2019 18:59:40 +0100 Subject: [PATCH] Do not set up NodeAndClusterIdStateListener in test (#38110) When extending ESIntegTestCase are run on the same jvm, the static field in NodeAndClusterIdConverter will throw an AlreadySet exceptions. overriding the configuration method from Node.configureNodeAndClusterIdStateListener in the MockNode will prevent the listener registration from happening relates #32850 --- server/src/main/java/org/elasticsearch/node/Node.java | 8 ++++++-- .../src/main/java/org/elasticsearch/node/MockNode.java | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 0ea5f1e78cf8b..19af7a467a789 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -684,8 +684,7 @@ public Node start() throws NodeValidationException { transportService.acceptIncomingRequests(); discovery.startInitialJoin(); final TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings); - NodeAndClusterIdStateListener.getAndSetNodeIdAndClusterId(clusterService, - injector.getInstance(ThreadPool.class).getThreadContext()); + configureNodeAndClusterIdStateListener(clusterService); if (initialStateTimeout.millis() > 0) { final ThreadPool thread = injector.getInstance(ThreadPool.class); @@ -737,6 +736,11 @@ public void onTimeout(TimeValue timeout) { return this; } + protected void configureNodeAndClusterIdStateListener(ClusterService clusterService) { + NodeAndClusterIdStateListener.getAndSetNodeIdAndClusterId(clusterService, + injector.getInstance(ThreadPool.class).getThreadContext()); + } + private Node stop() { if (!lifecycle.moveToStopped()) { return this; diff --git a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java index 58a84bd6bbd6e..31b8ba01dc4a8 100644 --- a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java +++ b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java @@ -174,4 +174,9 @@ protected HttpServerTransport newHttpTransport(NetworkModule networkModule) { return new MockHttpTransport(); } } + + @Override + protected void configureNodeAndClusterIdStateListener(ClusterService clusterService) { + //do not configure this in tests as this is causing SetOnce to throw exceptions when jvm is used for multiple tests + } }