Skip to content

Commit 007600e

Browse files
beanuwaveiigoninbennygoerzigKarstenSchnitterKai Sternad
authored
Fix flakiness of RemoteRestoreSnapshotIT.testClusterManagerFailoverDuringSnapshotCreation (#17589)
Signed-off-by: Igonin <[email protected]> Co-authored-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]>
1 parent d9a9274 commit 007600e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Diff for: server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
import java.util.concurrent.CountDownLatch;
6969
import java.util.concurrent.ExecutionException;
7070
import java.util.concurrent.TimeUnit;
71+
import java.util.concurrent.atomic.AtomicBoolean;
7172
import java.util.concurrent.atomic.AtomicLong;
73+
import java.util.concurrent.atomic.AtomicReference;
7274
import java.util.stream.Collectors;
7375
import java.util.stream.Stream;
7476

@@ -1448,9 +1450,8 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
14481450

14491451
ensureStableCluster(4, internalCluster().getClusterManagerName());
14501452

1451-
final SnapshotInfo[] snapshotInfo = new SnapshotInfo[1];
1452-
final Boolean[] snapshotFailed = new Boolean[1];
1453-
snapshotFailed[0] = false;
1453+
final AtomicReference<SnapshotInfo> snapshotInfoRef = new AtomicReference<>();
1454+
final AtomicBoolean snapshotFailed = new AtomicBoolean(false);
14541455
Thread snapshotThread = new Thread(() -> {
14551456
try {
14561457
// Start snapshot creation
@@ -1459,10 +1460,10 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
14591460
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
14601461
.setWaitForCompletion(true)
14611462
.get();
1462-
snapshotInfo[0] = createSnapshotResponse.getSnapshotInfo();
1463+
snapshotInfoRef.set(createSnapshotResponse.getSnapshotInfo());
14631464

14641465
} catch (Exception e) {
1465-
snapshotFailed[0] = true;
1466+
snapshotFailed.set(true);
14661467
}
14671468
});
14681469
snapshotThread.start();
@@ -1482,10 +1483,11 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
14821483
repository.getRepositoryData(repositoryDataPlainActionFuture);
14831484

14841485
RepositoryData repositoryData = repositoryDataPlainActionFuture.get();
1485-
if (snapshotFailed[0]) {
1486-
assertFalse(repositoryData.getSnapshotIds().contains(snapshotInfo[0].snapshotId()));
1486+
SnapshotInfo snapshotInfo = snapshotInfoRef.get();
1487+
if (snapshotFailed.get()) {
1488+
assertTrue(repositoryData.getSnapshotIds().isEmpty());
14871489
} else {
1488-
assertTrue(repositoryData.getSnapshotIds().contains(snapshotInfo[0].snapshotId()));
1490+
assertTrue(repositoryData.getSnapshotIds().contains(snapshotInfo.snapshotId()));
14891491
}
14901492
}
14911493

0 commit comments

Comments
 (0)