@@ -473,7 +473,7 @@ Directory createDirectory(Path path) {
473
473
wrapper .setRandomIOExceptionRateOnOpen (ioExceptionRate .get ());
474
474
}
475
475
476
- for (int i = 0 ; i < randomIntBetween (1 , 5 ); i ++ ) {
476
+ for (int i = between (1 , 5 ); 0 <= i ; i -- ) {
477
477
if (randomBoolean ()) {
478
478
final long version = randomNonNegativeLong ();
479
479
final String indexName = randomAlphaOfLength (10 );
@@ -529,7 +529,7 @@ public void testStatePersistenceWithFatalError() throws IOException {
529
529
final BigArrays mockBigArrays = mock (BigArrays .class );
530
530
when (mockBigArrays .newByteArray (anyLong ())).thenAnswer (invocationOnMock ->
531
531
{
532
- if (throwError .get ()) {
532
+ if (throwError .get () && randomBoolean () ) {
533
533
throw new TestError ();
534
534
}
535
535
return realBigArrays .newByteArray ((Long ) invocationOnMock .getArguments ()[0 ]);
@@ -546,18 +546,30 @@ public void testStatePersistenceWithFatalError() throws IOException {
546
546
547
547
throwError .set (true );
548
548
549
- final ClusterState newState = createClusterState (
550
- randomNonNegativeLong (),
551
- Metadata .builder ()
552
- .clusterUUID (randomAlphaOfLength (10 ))
553
- .coordinationMetadata (CoordinationMetadata .builder ().term (currentTerm ).build ())
554
- .build ());
555
- expectThrows (TestError .class , () -> persistedState .setLastAcceptedState (newState ));
556
-
557
- throwError .set (false );
558
-
559
- currentTerm += 1 ;
560
- persistedState .setCurrentTerm (currentTerm );
549
+ for (int i = between (1 , 5 ); 0 <= i ; i --) {
550
+ if (randomBoolean ()) {
551
+ final ClusterState newState = createClusterState (
552
+ randomNonNegativeLong (),
553
+ Metadata .builder ()
554
+ .clusterUUID (randomAlphaOfLength (10 ))
555
+ .coordinationMetadata (CoordinationMetadata .builder ().term (currentTerm ).build ())
556
+ .build ());
557
+ try {
558
+ persistedState .setLastAcceptedState (newState );
559
+ state = newState ;
560
+ } catch (TestError e ) {
561
+ // ok
562
+ }
563
+ } else {
564
+ final long newTerm = currentTerm + 1 ;
565
+ try {
566
+ persistedState .setCurrentTerm (newTerm );
567
+ currentTerm = newTerm ;
568
+ } catch (TestError e ) {
569
+ // ok
570
+ }
571
+ }
572
+ }
561
573
562
574
assertEquals (state , persistedState .getLastAcceptedState ());
563
575
assertEquals (currentTerm , persistedState .getCurrentTerm ());
0 commit comments