1212import org .elasticsearch .action .admin .indices .rollover .RolloverAction ;
1313import org .elasticsearch .action .admin .indices .rollover .RolloverRequest ;
1414import org .elasticsearch .action .downsample .DownsampleConfig ;
15- import org .elasticsearch .action .support .TestPlainActionFuture ;
1615import org .elasticsearch .cluster .metadata .DataStreamLifecycle ;
1716import org .elasticsearch .cluster .metadata .IndexMetadata ;
1817import org .elasticsearch .cluster .service .ClusterService ;
@@ -101,8 +100,7 @@ public void testDataStreamLifecycleDownsampleRollingRestart() throws Exception {
101100 );
102101
103102 logger .info ("-> Starting the disruption." );
104- internalCluster ().rollingRestart (new InternalTestCluster .RestartCallback () {
105- });
103+ internalCluster ().rollingRestart (new InternalTestCluster .RestartCallback ());
106104
107105 ensureDownsamplingStatus (targetIndex , Set .of (IndexMetadata .DownsampleTaskStatus .SUCCESS ), TimeValue .timeValueSeconds (120 ));
108106 ensureGreen (targetIndex );
@@ -115,28 +113,18 @@ private void ensureDownsamplingStatus(
115113 TimeValue timeout
116114 ) {
117115 final var clusterService = internalCluster ().getCurrentMasterNodeInstance (ClusterService .class );
118- final IndexMetadata .DownsampleTaskStatus [] downsamplingStatus = new IndexMetadata .DownsampleTaskStatus [1 ];
119116 final var listener = ClusterServiceUtils .addTemporaryStateListener (clusterService , clusterState -> {
120117 final var indexMetadata = clusterState .metadata ().getProject ().index (downsampledIndex );
121118 if (indexMetadata == null ) {
122119 return false ;
123120 }
124- downsamplingStatus [0 ] = INDEX_DOWNSAMPLE_STATUS .get (indexMetadata .getSettings ());
125- return expectedStatuses .contains (downsamplingStatus [0 ]);
126- });
127- try {
128- final var future = new TestPlainActionFuture <Void >();
129- listener .addListener (future );
130- future .get (timeout .getMillis (), TimeUnit .MILLISECONDS );
131- logger .info ("-> Downsampling status for index [{}] is [{}]" , downsampledIndex , downsamplingStatus [0 ]);
132- } catch (Exception e ) {
133- if (e instanceof InterruptedException ) {
134- Thread .currentThread ().interrupt ();
121+ var downsamplingStatus = INDEX_DOWNSAMPLE_STATUS .get (indexMetadata .getSettings ());
122+ if (expectedStatuses .contains (downsamplingStatus )) {
123+ logger .info ("-> Downsampling status for index [{}] is [{}]" , downsampledIndex , downsamplingStatus );
124+ return true ;
135125 }
136- throw new AssertionError (
137- "Error while waiting for " + expectedStatuses + " but found '" + downsamplingStatus [0 ] + "'. " + e .getMessage (),
138- e
139- );
140- }
126+ return false ;
127+ });
128+ safeAwait (listener , timeout .millis (), TimeUnit .MILLISECONDS );
141129 }
142130}
0 commit comments