1313import  org .opensearch .action .LatchedActionListener ;
1414import  org .opensearch .action .admin .cluster .state .ClusterStateRequest ;
1515import  org .opensearch .action .admin .cluster .state .ClusterStateResponse ;
16- import  org .opensearch .action .admin .indices .flush .FlushRequest ;
1716import  org .opensearch .action .admin .indices .stats .IndicesStatsRequest ;
1817import  org .opensearch .action .admin .indices .stats .IndicesStatsResponse ;
1918import  org .opensearch .action .search .CreatePitAction ;
3837import  org .opensearch .test .ParameterizedStaticSettingsOpenSearchIntegTestCase ;
3938import  org .opensearch .threadpool .TestThreadPool ;
4039import  org .opensearch .threadpool .ThreadPool ;
41- import  org .opensearch .transport .client .Requests ;
4240import  org .junit .After ;
4341import  org .junit .Assert ;
4442import  org .junit .Before ;
@@ -83,6 +81,7 @@ public static Collection<Object[]> parameters() {
8381    public  void  setupIndex () throws  ExecutionException , InterruptedException  {
8482        createIndex ("index" , Settings .builder ().put ("index.number_of_shards" , 2 ).put ("index.number_of_replicas" , 0 ).build ());
8583        client ().prepareIndex ("index" ).setId ("1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).execute ().get ();
84+         flush (); // clear the translog to ensure accurate stats 
8685        ensureGreen ();
8786    }
8887
@@ -95,6 +94,7 @@ public void testPit() throws Exception {
9594        CreatePitRequest  request  = new  CreatePitRequest (TimeValue .timeValueDays (1 ), true );
9695        request .setIndices (new  String [] { "index"  });
9796        indexRandomForConcurrentSearch ("index" );
97+         flush (); // clear the translog to ensure accurate stats 
9898        ActionFuture <CreatePitResponse > execute  = client ().execute (CreatePitAction .INSTANCE , request );
9999        CreatePitResponse  pitResponse  = execute .get ();
100100        SearchResponse  searchResponse  = client ().prepareSearch ("index" )
@@ -366,9 +366,6 @@ public void onFailure(Exception e) {}
366366
367367    public  void  validatePitStats (String  index , long  expectedPitCurrent , long  expectedOpenContexts ) throws  ExecutionException ,
368368        InterruptedException  {
369-         // Clear the index transaction log 
370-         FlushRequest  flushRequest  = Requests .flushRequest (index );
371-         client ().admin ().indices ().flush (flushRequest ).get ();
372369        // Test stats 
373370        IndicesStatsRequest  indicesStatsRequest  = new  IndicesStatsRequest ();
374371        indicesStatsRequest .indices (index );
@@ -501,5 +498,4 @@ public void onFailure(Exception e) {}
501498            ThreadPool .terminate (testThreadPool , 500 , TimeUnit .MILLISECONDS );
502499        }
503500    }
504- 
505501}
0 commit comments