1111import org .elasticsearch .action .DocWriteRequest ;
1212import org .elasticsearch .action .admin .cluster .health .ClusterHealthRequest ;
1313import org .elasticsearch .action .admin .indices .close .CloseIndexRequest ;
14+ import org .elasticsearch .action .admin .indices .create .CreateIndexRequest ;
15+ import org .elasticsearch .action .admin .indices .delete .DeleteIndexRequest ;
1416import org .elasticsearch .action .admin .indices .refresh .RefreshRequest ;
1517import org .elasticsearch .action .admin .indices .rollover .RolloverRequest ;
1618import org .elasticsearch .action .admin .indices .template .delete .TransportDeleteComposableIndexTemplateAction ;
@@ -56,6 +58,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
5658 }
5759
5860 private final Set <String > createdDataStreams = new HashSet <>();
61+ private final Set <String > createdStandAloneIndices = new HashSet <>();
5962
6063 @ Override
6164 @ After
@@ -66,6 +69,12 @@ public void tearDown() throws Exception {
6669 }
6770 createdDataStreams .clear ();
6871 }
72+ if (createdStandAloneIndices .isEmpty () == false ) {
73+ for (String indexName : createdStandAloneIndices ) {
74+ client ().admin ().indices ().delete (new DeleteIndexRequest (indexName ));
75+ }
76+ createdStandAloneIndices .clear ();
77+ }
6978 super .tearDown ();
7079 }
7180
@@ -80,6 +89,7 @@ public void testStatsNoDataStream() throws Exception {
8089 }
8190
8291 public void testStatsEmptyDataStream () throws Exception {
92+ maybeCreateCreatedStandAloneIndicesIndex ();
8393 String dataStreamName = createDataStream ();
8494
8595 DataStreamsStatsAction .Response stats = getDataStreamsStats ();
@@ -97,6 +107,7 @@ public void testStatsEmptyDataStream() throws Exception {
97107 }
98108
99109 public void testStatsExistingDataStream () throws Exception {
110+ maybeCreateCreatedStandAloneIndicesIndex ();
100111 String dataStreamName = createDataStream ();
101112 long timestamp = createDocument (dataStreamName );
102113
@@ -115,6 +126,7 @@ public void testStatsExistingDataStream() throws Exception {
115126 }
116127
117128 public void testStatsExistingDataStreamWithFailureStores () throws Exception {
129+ maybeCreateCreatedStandAloneIndicesIndex ();
118130 String dataStreamName = createDataStream (false , true );
119131 createFailedDocument (dataStreamName );
120132
@@ -137,6 +149,7 @@ public void testStatsExistingDataStreamWithFailureStores() throws Exception {
137149 }
138150
139151 public void testStatsExistingHiddenDataStream () throws Exception {
152+ maybeCreateCreatedStandAloneIndicesIndex ();
140153 String dataStreamName = createDataStream (true , false );
141154 long timestamp = createDocument (dataStreamName );
142155
@@ -155,6 +168,7 @@ public void testStatsExistingHiddenDataStream() throws Exception {
155168 }
156169
157170 public void testStatsClosedBackingIndexDataStream () throws Exception {
171+ maybeCreateCreatedStandAloneIndicesIndex ();
158172 String dataStreamName = createDataStream ();
159173 createDocument (dataStreamName );
160174 assertTrue (indicesAdmin ().rolloverIndex (new RolloverRequest (dataStreamName , null )).get ().isAcknowledged ());
@@ -198,6 +212,7 @@ public void testStatsClosedBackingIndexDataStream() throws Exception {
198212 }
199213
200214 public void testStatsRolledDataStream () throws Exception {
215+ maybeCreateCreatedStandAloneIndicesIndex ();
201216 String dataStreamName = createDataStream ();
202217 long timestamp = createDocument (dataStreamName );
203218 assertTrue (indicesAdmin ().rolloverIndex (new RolloverRequest (dataStreamName , null )).get ().isAcknowledged ());
@@ -218,6 +233,7 @@ public void testStatsRolledDataStream() throws Exception {
218233 }
219234
220235 public void testStatsMultipleDataStreams () throws Exception {
236+ maybeCreateCreatedStandAloneIndicesIndex ();
221237 for (int dataStreamCount = 0 ; dataStreamCount < (2 + randomInt (3 )); dataStreamCount ++) {
222238 createDataStream ();
223239 }
@@ -284,6 +300,14 @@ private String createDataStream(boolean hidden, boolean failureStore) throws Exc
284300 return dataStreamName ;
285301 }
286302
303+ private void maybeCreateCreatedStandAloneIndicesIndex () {
304+ if (randomBoolean ()) {
305+ String indexName = randomAlphaOfLength (10 ).toLowerCase (Locale .getDefault ());
306+ assertAcked (client ().admin ().indices ().create (new CreateIndexRequest (indexName )));
307+ createdStandAloneIndices .add (indexName );
308+ }
309+ }
310+
287311 private long createDocument (String dataStreamName ) throws Exception {
288312 // Get some randomized but reasonable timestamps on the data since not all of it is guaranteed to arrive in order.
289313 long timeSeed = System .currentTimeMillis ();
0 commit comments