68
68
import java .util .concurrent .CountDownLatch ;
69
69
import java .util .concurrent .ExecutionException ;
70
70
import java .util .concurrent .TimeUnit ;
71
+ import java .util .concurrent .atomic .AtomicBoolean ;
71
72
import java .util .concurrent .atomic .AtomicLong ;
73
+ import java .util .concurrent .atomic .AtomicReference ;
72
74
import java .util .stream .Collectors ;
73
75
import java .util .stream .Stream ;
74
76
@@ -1448,9 +1450,8 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
1448
1450
1449
1451
ensureStableCluster (4 , internalCluster ().getClusterManagerName ());
1450
1452
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 );
1454
1455
Thread snapshotThread = new Thread (() -> {
1455
1456
try {
1456
1457
// Start snapshot creation
@@ -1459,10 +1460,10 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
1459
1460
.prepareCreateSnapshot (snapshotRepoName , snapshotName1 )
1460
1461
.setWaitForCompletion (true )
1461
1462
.get ();
1462
- snapshotInfo [ 0 ] = createSnapshotResponse .getSnapshotInfo ();
1463
+ snapshotInfoRef . set ( createSnapshotResponse .getSnapshotInfo () );
1463
1464
1464
1465
} catch (Exception e ) {
1465
- snapshotFailed [ 0 ] = true ;
1466
+ snapshotFailed . set ( true ) ;
1466
1467
}
1467
1468
});
1468
1469
snapshotThread .start ();
@@ -1482,10 +1483,11 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
1482
1483
repository .getRepositoryData (repositoryDataPlainActionFuture );
1483
1484
1484
1485
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 ());
1487
1489
} else {
1488
- assertTrue (repositoryData .getSnapshotIds ().contains (snapshotInfo [ 0 ] .snapshotId ()));
1490
+ assertTrue (repositoryData .getSnapshotIds ().contains (snapshotInfo .snapshotId ()));
1489
1491
}
1490
1492
}
1491
1493
0 commit comments