diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 0ea5f1e78cf..19af7a467a7 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 class Node implements Closeable { 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 class Node implements Closeable { 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 58a84bd6bbd..31b8ba01dc4 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 @@ public class MockNode extends Node { 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 + } }