99
1010package  org .elasticsearch .reservedstate .service ;
1111
12+ import  org .apache .logging .log4j .Level ;
13+ import  org .apache .logging .log4j .LogManager ;
14+ import  org .apache .logging .log4j .Logger ;
1215import  org .elasticsearch .action .ActionListener ;
1316import  org .elasticsearch .cluster .ClusterChangedEvent ;
1417import  org .elasticsearch .cluster .ClusterName ;
2225import  org .elasticsearch .cluster .routing .RerouteService ;
2326import  org .elasticsearch .cluster .service .ClusterService ;
2427import  org .elasticsearch .common .component .Lifecycle ;
28+ import  org .elasticsearch .common .file .AbstractFileWatchingService ;
29+ import  org .elasticsearch .common .logging .Loggers ;
2530import  org .elasticsearch .common .settings .ClusterSettings ;
2631import  org .elasticsearch .common .settings .Settings ;
2732import  org .elasticsearch .core .IOUtils ;
6772import  static  org .mockito .Mockito .verify ;
6873
6974public  class  FileSettingsServiceTests  extends  ESTestCase  {
75+     private  static  final  Logger  logger  = LogManager .getLogger (FileSettingsServiceTests .class );
7076    private  Environment  env ;
7177    private  ClusterService  clusterService ;
7278    private  ReservedClusterStateService  controller ;
@@ -76,6 +82,8 @@ public class FileSettingsServiceTests extends ESTestCase {
7682    @ Before 
7783    public  void  setUp () throws  Exception  {
7884        super .setUp ();
85+         // TODO remove me once https://github.com/elastic/elasticsearch/issues/115280 is closed 
86+         Loggers .setLevel (LogManager .getLogger (AbstractFileWatchingService .class ), Level .DEBUG );
7987
8088        threadpool  = new  TestThreadPool ("file_settings_service_tests" );
8189
@@ -120,16 +128,23 @@ public void setUp() throws Exception {
120128
121129    @ After 
122130    public  void  tearDown () throws  Exception  {
123-         if  (fileSettingsService .lifecycleState () == Lifecycle .State .STARTED ) {
124-             fileSettingsService .stop ();
125-         }
126-         if  (fileSettingsService .lifecycleState () == Lifecycle .State .STOPPED ) {
127-             fileSettingsService .close ();
128-         }
131+         try  {
132+             if  (fileSettingsService .lifecycleState () == Lifecycle .State .STARTED ) {
133+                 logger .info ("Stopping file settings service" );
134+                 fileSettingsService .stop ();
135+             }
136+             if  (fileSettingsService .lifecycleState () == Lifecycle .State .STOPPED ) {
137+                 logger .info ("Closing file settings service" );
138+                 fileSettingsService .close ();
139+             }
129140
130-         super .tearDown ();
131-         clusterService .close ();
132-         threadpool .shutdownNow ();
141+             super .tearDown ();
142+             clusterService .close ();
143+             threadpool .shutdownNow ();
144+         } finally  {
145+             // TODO remove me once https://github.com/elastic/elasticsearch/issues/115280 is closed 
146+             Loggers .setLevel (LogManager .getLogger (AbstractFileWatchingService .class ), Level .INFO );
147+         }
133148    }
134149
135150    public  void  testStartStop () {
@@ -355,17 +370,25 @@ public void testHandleSnapshotRestoreResetsMetadata() throws Exception {
355370    private  static  void  writeTestFile (Path  path , String  contents ) {
356371        Path  tempFile  = null ;
357372        try  {
373+             logger .info ("Creating settings temp file under [{}]" , path .toAbsolutePath ());
358374            tempFile  = Files .createTempFile (path .getParent (), path .getFileName ().toString (), "tmp" );
375+             logger .info ("Created settings temp file [{}]" , tempFile .getFileName ());
359376            Files .writeString (tempFile , contents );
360377
361378            try  {
379+                 logger .info ("Moving settings temp file to replace [{}]" , tempFile .getFileName ());
362380                Files .move (tempFile , path , REPLACE_EXISTING , ATOMIC_MOVE );
363381            } catch  (AtomicMoveNotSupportedException  e ) {
382+                 logger .info (
383+                     "Atomic move was not available. Falling back on non-atomic move for settings temp file to replace [{}]" ,
384+                     tempFile .getFileName ()
385+                 );
364386                Files .move (tempFile , path , REPLACE_EXISTING );
365387            }
366388        } catch  (final  IOException  e ) {
367389            throw  new  UncheckedIOException (Strings .format ("could not write file [%s]" , path .toAbsolutePath ()), e );
368390        } finally  {
391+             logger .info ("Deleting settings temp file [{}]" , tempFile  != null  ? tempFile .getFileName () : null );
369392            // we are ignoring exceptions here, so we do not need handle whether or not tempFile was initialized nor if the file exists 
370393            IOUtils .deleteFilesIgnoringExceptions (tempFile );
371394        }
0 commit comments