Skip to content

Commit 28b5c7c

Browse files
authored
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
1 parent be381b4 commit 28b5c7c

File tree

2 files changed

+11
-2
lines changed
  • server/src/main/java/org/elasticsearch/node
  • test/framework/src/main/java/org/elasticsearch/node

2 files changed

+11
-2
lines changed

server/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ public Node start() throws NodeValidationException {
684684
transportService.acceptIncomingRequests();
685685
discovery.startInitialJoin();
686686
final TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings);
687-
NodeAndClusterIdStateListener.getAndSetNodeIdAndClusterId(clusterService,
688-
injector.getInstance(ThreadPool.class).getThreadContext());
687+
configureNodeAndClusterIdStateListener(clusterService);
689688

690689
if (initialStateTimeout.millis() > 0) {
691690
final ThreadPool thread = injector.getInstance(ThreadPool.class);
@@ -737,6 +736,11 @@ public void onTimeout(TimeValue timeout) {
737736
return this;
738737
}
739738

739+
protected void configureNodeAndClusterIdStateListener(ClusterService clusterService) {
740+
NodeAndClusterIdStateListener.getAndSetNodeIdAndClusterId(clusterService,
741+
injector.getInstance(ThreadPool.class).getThreadContext());
742+
}
743+
740744
private Node stop() {
741745
if (!lifecycle.moveToStopped()) {
742746
return this;

test/framework/src/main/java/org/elasticsearch/node/MockNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,9 @@ protected HttpServerTransport newHttpTransport(NetworkModule networkModule) {
174174
return new MockHttpTransport();
175175
}
176176
}
177+
178+
@Override
179+
protected void configureNodeAndClusterIdStateListener(ClusterService clusterService) {
180+
//do not configure this in tests as this is causing SetOnce to throw exceptions when jvm is used for multiple tests
181+
}
177182
}

0 commit comments

Comments
 (0)