Skip to content

Commit

Permalink
Do not set up NodeAndClusterIdStateListener in test (#38110)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pgomulka authored Jan 31, 2019
1 parent be381b4 commit 28b5c7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/src/main/java/org/elasticsearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 28b5c7c

Please sign in to comment.