8
8
9
9
package org .opensearch .remotestore ;
10
10
11
+ import org .hamcrest .MatcherAssert ;
11
12
import org .junit .Before ;
12
13
import org .opensearch .action .admin .indices .delete .DeleteIndexRequest ;
13
14
import org .opensearch .action .admin .indices .recovery .RecoveryResponse ;
14
15
import org .opensearch .action .index .IndexResponse ;
15
16
import org .opensearch .cluster .metadata .IndexMetadata ;
16
17
import org .opensearch .cluster .routing .RecoverySource ;
17
18
import org .opensearch .common .settings .Settings ;
18
- import org .opensearch .index .shard .RemoteStoreRefreshListener ;
19
19
import org .opensearch .indices .recovery .RecoveryState ;
20
20
import org .opensearch .plugins .Plugin ;
21
21
import org .opensearch .test .OpenSearchIntegTestCase ;
29
29
import java .util .concurrent .TimeUnit ;
30
30
31
31
import static org .hamcrest .Matchers .comparesEqualTo ;
32
- import static org .hamcrest .Matchers .comparesEqualTo ;
32
+ import static org .hamcrest .Matchers .is ;
33
+ import static org .hamcrest .Matchers .oneOf ;
34
+ import static org .opensearch .index .shard .RemoteStoreRefreshListener .LAST_N_METADATA_FILES_TO_KEEP ;
33
35
import static org .opensearch .test .hamcrest .OpenSearchAssertions .assertAcked ;
34
36
import static org .opensearch .test .hamcrest .OpenSearchAssertions .assertHitCount ;
35
37
@@ -143,10 +145,9 @@ public void testRemoteTranslogCleanup() throws Exception {
143
145
verifyRemoteStoreCleanup ();
144
146
}
145
147
146
- @ AwaitsFix (bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/8658" )
147
148
public void testStaleCommitDeletionWithInvokeFlush () throws Exception {
148
- internalCluster ().startDataOnlyNodes (3 );
149
- createIndex (INDEX_NAME , remoteStoreIndexSettings (1 , 10000l ));
149
+ internalCluster ().startDataOnlyNodes (1 );
150
+ createIndex (INDEX_NAME , remoteStoreIndexSettings (1 , 10000l , - 1 ));
150
151
int numberOfIterations = randomIntBetween (5 , 15 );
151
152
indexData (numberOfIterations , true , INDEX_NAME );
152
153
String indexUUID = client ().admin ()
@@ -158,20 +159,22 @@ public void testStaleCommitDeletionWithInvokeFlush() throws Exception {
158
159
// Delete is async.
159
160
assertBusy (() -> {
160
161
int actualFileCount = getFileCount (indexPath );
161
- if (numberOfIterations <= RemoteStoreRefreshListener . LAST_N_METADATA_FILES_TO_KEEP ) {
162
- assertEquals ( numberOfIterations , actualFileCount );
162
+ if (numberOfIterations <= LAST_N_METADATA_FILES_TO_KEEP ) {
163
+ MatcherAssert . assertThat ( actualFileCount , is ( oneOf ( numberOfIterations - 1 , numberOfIterations , numberOfIterations + 1 )) );
163
164
} else {
164
165
// As delete is async its possible that the file gets created before the deletion or after
165
166
// deletion.
166
- assertTrue (actualFileCount >= 10 || actualFileCount <= 11 );
167
+ MatcherAssert .assertThat (
168
+ actualFileCount ,
169
+ is (oneOf (LAST_N_METADATA_FILES_TO_KEEP - 1 , LAST_N_METADATA_FILES_TO_KEEP , LAST_N_METADATA_FILES_TO_KEEP + 1 ))
170
+ );
167
171
}
168
172
}, 30 , TimeUnit .SECONDS );
169
173
}
170
174
171
- @ AwaitsFix (bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/8658" )
172
175
public void testStaleCommitDeletionWithoutInvokeFlush () throws Exception {
173
- internalCluster ().startDataOnlyNodes (3 );
174
- createIndex (INDEX_NAME , remoteStoreIndexSettings (1 , 10000l ));
176
+ internalCluster ().startDataOnlyNodes (1 );
177
+ createIndex (INDEX_NAME , remoteStoreIndexSettings (1 , 10000l , - 1 ));
175
178
int numberOfIterations = randomIntBetween (5 , 15 );
176
179
indexData (numberOfIterations , false , INDEX_NAME );
177
180
String indexUUID = client ().admin ()
@@ -180,6 +183,8 @@ public void testStaleCommitDeletionWithoutInvokeFlush() throws Exception {
180
183
.get ()
181
184
.getSetting (INDEX_NAME , IndexMetadata .SETTING_INDEX_UUID );
182
185
Path indexPath = Path .of (String .valueOf (absolutePath ), indexUUID , "/0/segments/metadata" );
183
- assertEquals (numberOfIterations , getFileCount (indexPath ));
186
+ int actualFileCount = getFileCount (indexPath );
187
+ // We also allow (numberOfIterations + 1) as index creation also triggers refresh.
188
+ MatcherAssert .assertThat (actualFileCount , is (oneOf (numberOfIterations - 1 , numberOfIterations , numberOfIterations + 1 )));
184
189
}
185
190
}
0 commit comments