@@ -1244,14 +1244,72 @@ public void testGatewayForRemoteStateForInitialBootstrapBlocksApplied() throws I
1244
1244
}
1245
1245
}
1246
1246
1247
- private MockGatewayMetaState newGatewayForRemoteState (
1247
+ public void testGatewayMetaStateRemoteStateDownloadRetries () throws IOException {
1248
+ MockGatewayMetaState gateway = null ;
1249
+ MockGatewayMetaState gatewayMetaStateSpy = null ;
1250
+ try {
1251
+ RemoteClusterStateService remoteClusterStateService = mock (RemoteClusterStateService .class );
1252
+ when (remoteClusterStateService .getLastKnownUUIDFromRemote ("test-cluster" )).thenReturn ("test-cluster-uuid" );
1253
+ RemoteStoreRestoreService remoteStoreRestoreService = mock (RemoteStoreRestoreService .class );
1254
+ when (remoteStoreRestoreService .restore (any (), any (), anyBoolean (), any ())).thenThrow (
1255
+ new IllegalStateException ("unable to download cluster state" )
1256
+ ).thenReturn (RemoteRestoreResult .build ("test-cluster-uuid" , null , ClusterState .EMPTY_STATE ));
1257
+ final PersistedStateRegistry persistedStateRegistry = persistedStateRegistry ();
1258
+ gateway = initializeGatewayForRemoteState (true );
1259
+ gatewayMetaStateSpy = Mockito .spy (gateway );
1260
+ startGatewayForRemoteState (
1261
+ gatewayMetaStateSpy ,
1262
+ remoteClusterStateService ,
1263
+ remoteStoreRestoreService ,
1264
+ persistedStateRegistry ,
1265
+ ClusterState .EMPTY_STATE
1266
+ );
1267
+ verify (gatewayMetaStateSpy , times (2 )).restoreClusterState (Mockito .any (), Mockito .any (), Mockito .any ());
1268
+ } finally {
1269
+ IOUtils .close (gatewayMetaStateSpy );
1270
+ }
1271
+ }
1272
+
1273
+ public void testGatewayMetaStateRemoteStateDownloadFailure () throws IOException {
1274
+ MockGatewayMetaState gateway = null ;
1275
+ final MockGatewayMetaState gatewayMetaStateSpy ;
1276
+ try {
1277
+ RemoteClusterStateService remoteClusterStateService = mock (RemoteClusterStateService .class );
1278
+ when (remoteClusterStateService .getLastKnownUUIDFromRemote ("test-cluster" )).thenReturn ("test-cluster-uuid" );
1279
+ RemoteStoreRestoreService remoteStoreRestoreService = mock (RemoteStoreRestoreService .class );
1280
+ when (remoteStoreRestoreService .restore (any (), any (), anyBoolean (), any ())).thenThrow (
1281
+ new IllegalStateException ("unable to download cluster state" )
1282
+ );
1283
+ final PersistedStateRegistry persistedStateRegistry = persistedStateRegistry ();
1284
+ gateway = initializeGatewayForRemoteState (true );
1285
+ gatewayMetaStateSpy = Mockito .spy (gateway );
1286
+ assertThrows (
1287
+ Error .class ,
1288
+ () -> startGatewayForRemoteState (
1289
+ gatewayMetaStateSpy ,
1290
+ remoteClusterStateService ,
1291
+ remoteStoreRestoreService ,
1292
+ persistedStateRegistry ,
1293
+ ClusterState .EMPTY_STATE
1294
+ )
1295
+ );
1296
+ verify (gatewayMetaStateSpy , times (5 )).restoreClusterState (Mockito .any (), Mockito .any (), Mockito .any ());
1297
+ } finally {
1298
+ IOUtils .close (gateway );
1299
+ }
1300
+ }
1301
+
1302
+ private MockGatewayMetaState initializeGatewayForRemoteState (boolean prepareFullState ) {
1303
+ return new MockGatewayMetaState (localNode , bigArrays , prepareFullState );
1304
+ }
1305
+
1306
+ private MockGatewayMetaState startGatewayForRemoteState (
1307
+ MockGatewayMetaState gateway ,
1248
1308
RemoteClusterStateService remoteClusterStateService ,
1249
1309
RemoteStoreRestoreService remoteStoreRestoreService ,
1250
1310
PersistedStateRegistry persistedStateRegistry ,
1251
- ClusterState currentState ,
1252
- boolean prepareFullState
1311
+ ClusterState currentState
1253
1312
) throws IOException {
1254
- MockGatewayMetaState gateway = new MockGatewayMetaState (localNode , bigArrays , prepareFullState );
1255
1313
String randomRepoName = "randomRepoName" ;
1256
1314
String stateRepoTypeAttributeKey = String .format (
1257
1315
Locale .getDefault (),
@@ -1305,6 +1363,24 @@ private MockGatewayMetaState newGatewayForRemoteState(
1305
1363
return gateway ;
1306
1364
}
1307
1365
1366
+ private MockGatewayMetaState newGatewayForRemoteState (
1367
+ RemoteClusterStateService remoteClusterStateService ,
1368
+ RemoteStoreRestoreService remoteStoreRestoreService ,
1369
+ PersistedStateRegistry persistedStateRegistry ,
1370
+ ClusterState currentState ,
1371
+ boolean prepareFullState
1372
+ ) throws IOException {
1373
+ MockGatewayMetaState gatewayMetaState = initializeGatewayForRemoteState (prepareFullState );
1374
+ startGatewayForRemoteState (
1375
+ gatewayMetaState ,
1376
+ remoteClusterStateService ,
1377
+ remoteStoreRestoreService ,
1378
+ persistedStateRegistry ,
1379
+ currentState
1380
+ );
1381
+ return gatewayMetaState ;
1382
+ }
1383
+
1308
1384
private static BigArrays getBigArrays () {
1309
1385
return usually ()
1310
1386
? BigArrays .NON_RECYCLING_INSTANCE
0 commit comments