Skip to content

Commit 2ea5728

Browse files
committed
make testCloneShallowSnapshotIndex() establish the missing precondition: cluster at least YELLOW + no initializing shards + no relocating shards before each snapshot
Signed-off-by: Joe Liu <guoqing4@illinois.edu>
1 parent fcdd76d commit 2ea5728

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/CloneSnapshotIT.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,57 @@ public void testCloneShallowSnapshotIndex() throws Exception {
177177
createIndex(remoteStoreEnabledIndexName, remoteStoreEnabledIndexSettings);
178178
indexRandomDocs(remoteStoreEnabledIndexName, randomIntBetween(5, 10));
179179

180+
assertBusy(
181+
() -> client().admin()
182+
.cluster()
183+
.prepareHealth()
184+
.setWaitForStatus(org.opensearch.cluster.health.ClusterHealthStatus.YELLOW) // don't require GREEN
185+
.setWaitForNoInitializingShards(true)
186+
.setWaitForNoRelocatingShards(true)
187+
.setTimeout(TimeValue.timeValueSeconds(60))
188+
.get()
189+
);
190+
180191
final String snapshot = "snapshot";
181192
createFullSnapshot(snapshotRepoName, snapshot);
182-
assert (getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length == 0);
193+
assertBusy(() -> assertEquals(0, getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length));
183194

184195
indexRandomDocs(indexName, randomIntBetween(20, 100));
185196

197+
assertBusy(
198+
() -> client().admin()
199+
.cluster()
200+
.prepareHealth()
201+
.setWaitForStatus(org.opensearch.cluster.health.ClusterHealthStatus.YELLOW)
202+
.setWaitForNoInitializingShards(true)
203+
.setWaitForNoRelocatingShards(true)
204+
.setTimeout(TimeValue.timeValueSeconds(60))
205+
.get()
206+
);
207+
186208
final String shallowSnapshot = "shallow-snapshot";
187209
createFullSnapshot(shallowSnapshotRepoName, shallowSnapshot);
188-
assert (getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length == 1);
210+
assertBusy(() -> assertEquals(1, getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length));
189211

190212
if (randomBoolean()) {
191213
assertAcked(admin().indices().prepareDelete(indexName));
214+
assertBusy(
215+
() -> client().admin()
216+
.cluster()
217+
.prepareHealth()
218+
.setWaitForStatus(org.opensearch.cluster.health.ClusterHealthStatus.YELLOW)
219+
.setWaitForNoInitializingShards(true)
220+
.setWaitForNoRelocatingShards(true)
221+
.setTimeout(TimeValue.timeValueSeconds(60))
222+
.get()
223+
);
192224
}
193225

194226
final String sourceSnapshot = shallowSnapshot;
195227
final String targetSnapshot = "target-snapshot";
196228
assertAcked(startClone(shallowSnapshotRepoName, sourceSnapshot, targetSnapshot, indexName, remoteStoreEnabledIndexName).get());
197229
logger.info("Lock files count: {}", getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length);
198-
assert (getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length == 2);
230+
assertBusy(() -> assertEquals(2, getLockFilesInRemoteStore(remoteStoreEnabledIndexName, remoteStoreRepoName).length));
199231
}
200232

201233
public void testShallowCloneNameAvailability() throws Exception {

0 commit comments

Comments
 (0)