@@ -19,16 +19,12 @@ public class TestClusterCleanupOnShutdown implements Runnable {
1919
2020 private Set <ElasticsearchCluster > clustersToWatch = new HashSet <>();
2121
22- public void watch (Collection <ElasticsearchCluster > cluster ) {
23- synchronized (clustersToWatch ) {
24- clustersToWatch .addAll (clustersToWatch );
25- }
22+ public synchronized void watch (Collection <ElasticsearchCluster > clusters ) {
23+ clustersToWatch .addAll (clusters );
2624 }
2725
28- public void unWatch (Collection <ElasticsearchCluster > cluster ) {
29- synchronized (clustersToWatch ) {
30- clustersToWatch .removeAll (clustersToWatch );
31- }
26+ public synchronized void unWatch (Collection <ElasticsearchCluster > clusters ) {
27+ clustersToWatch .removeAll (clusters );
3228 }
3329
3430 @ Override
@@ -38,21 +34,23 @@ public void run() {
3834 Thread .sleep (Long .MAX_VALUE );
3935 }
4036 } catch (InterruptedException interrupted ) {
41- synchronized (clustersToWatch ) {
42- if (clustersToWatch .isEmpty ()) {
43- return ;
44- }
45- logger .info ("Cleanup thread was interrupted, shutting down all clusters" );
46- Iterator <ElasticsearchCluster > iterator = clustersToWatch .iterator ();
47- while (iterator .hasNext ()) {
48- ElasticsearchCluster cluster = iterator .next ();
49- iterator .remove ();
50- try {
51- cluster .stop (false );
52- } catch (Exception e ) {
53- logger .warn ("Could not shut down {}" , cluster , e );
54- }
55- }
37+ shutdownClusters ();
38+ }
39+ }
40+
41+ public synchronized void shutdownClusters () {
42+ if (clustersToWatch .isEmpty ()) {
43+ return ;
44+ }
45+ logger .info ("Cleanup thread was interrupted, shutting down all clusters" );
46+ Iterator <ElasticsearchCluster > iterator = clustersToWatch .iterator ();
47+ while (iterator .hasNext ()) {
48+ ElasticsearchCluster cluster = iterator .next ();
49+ iterator .remove ();
50+ try {
51+ cluster .stop (false );
52+ } catch (Exception e ) {
53+ logger .warn ("Could not shut down {}" , cluster , e );
5654 }
5755 }
5856 }
0 commit comments