@@ -1351,21 +1351,26 @@ public void shouldReturnTrueFromCheckStateUpdaterIfActiveTasksAreNotRestoringAnd
1351
1351
}
1352
1352
1353
1353
@ Test
1354
- public void shouldAddActiveTaskWithRevokedInputPartitionsInStateUpdaterToPendingTasksToSuspend () {
1354
+ public void shouldSuspendActiveTaskWithRevokedInputPartitionsInStateUpdater () {
1355
1355
final StreamTask task = statefulTask (taskId00 , taskId00ChangelogPartitions )
1356
1356
.inState (State .RESTORING )
1357
1357
.withInputPartitions (taskId00Partitions ).build ();
1358
1358
final TasksRegistry tasks = mock (TasksRegistry .class );
1359
1359
final TaskManager taskManager = setupForRevocationAndLost (mkSet (task ), tasks );
1360
1360
when (stateUpdater .getTasks ()).thenReturn (mkSet (task ));
1361
+ final CompletableFuture <StateUpdater .RemovedTaskResult > future = new CompletableFuture <>();
1362
+ when (stateUpdater .removeWithFuture (task .id ())).thenReturn (future );
1363
+ future .complete (new StateUpdater .RemovedTaskResult (task ));
1361
1364
1362
1365
taskManager .handleRevocation (task .inputPartitions ());
1363
1366
1364
- verify (tasks ).addPendingActiveTaskToSuspend (task .id ());
1365
- verify (stateUpdater , never ()).remove (task .id ());
1367
+ verify (task ).suspend ();
1368
+ verify (tasks ).addTask (task );
1369
+ verify (stateUpdater ).removeWithFuture (task .id ());
1366
1370
}
1367
1371
1368
- public void shouldAddMultipleActiveTasksWithRevokedInputPartitionsInStateUpdaterToPendingTasksToSuspend () {
1372
+ @ Test
1373
+ public void shouldSuspendMultipleActiveTasksWithRevokedInputPartitionsInStateUpdater () {
1369
1374
final StreamTask task1 = statefulTask (taskId00 , taskId00ChangelogPartitions )
1370
1375
.inState (State .RESTORING )
1371
1376
.withInputPartitions (taskId00Partitions ).build ();
@@ -1374,15 +1379,23 @@ public void shouldAddMultipleActiveTasksWithRevokedInputPartitionsInStateUpdater
1374
1379
.withInputPartitions (taskId01Partitions ).build ();
1375
1380
final TasksRegistry tasks = mock (TasksRegistry .class );
1376
1381
final TaskManager taskManager = setupForRevocationAndLost (mkSet (task1 , task2 ), tasks );
1382
+ final CompletableFuture <StateUpdater .RemovedTaskResult > future1 = new CompletableFuture <>();
1383
+ when (stateUpdater .removeWithFuture (task1 .id ())).thenReturn (future1 );
1384
+ future1 .complete (new StateUpdater .RemovedTaskResult (task1 ));
1385
+ final CompletableFuture <StateUpdater .RemovedTaskResult > future2 = new CompletableFuture <>();
1386
+ when (stateUpdater .removeWithFuture (task2 .id ())).thenReturn (future2 );
1387
+ future2 .complete (new StateUpdater .RemovedTaskResult (task2 ));
1377
1388
1378
1389
taskManager .handleRevocation (union (HashSet ::new , taskId00Partitions , taskId01Partitions ));
1379
1390
1380
- verify (tasks ).addPendingActiveTaskToSuspend (task1 .id ());
1381
- verify (tasks ).addPendingActiveTaskToSuspend (task2 .id ());
1391
+ verify (task1 ).suspend ();
1392
+ verify (tasks ).addTask (task1 );
1393
+ verify (task2 ).suspend ();
1394
+ verify (tasks ).addTask (task2 );
1382
1395
}
1383
1396
1384
1397
@ Test
1385
- public void shouldNotAddActiveTaskWithoutRevokedInputPartitionsInStateUpdaterToPendingTasksToSuspend () {
1398
+ public void shouldNotSuspendActiveTaskWithoutRevokedInputPartitionsInStateUpdater () {
1386
1399
final StreamTask task = statefulTask (taskId00 , taskId00ChangelogPartitions )
1387
1400
.inState (State .RESTORING )
1388
1401
.withInputPartitions (taskId00Partitions ).build ();
@@ -1391,8 +1404,9 @@ public void shouldNotAddActiveTaskWithoutRevokedInputPartitionsInStateUpdaterToP
1391
1404
1392
1405
taskManager .handleRevocation (taskId01Partitions );
1393
1406
1394
- verify (stateUpdater , never ()).remove (task .id ());
1395
- verify (tasks , never ()).addPendingActiveTaskToSuspend (task .id ());
1407
+ verify (task , never ()).suspend ();
1408
+ verify (tasks , never ()).addTask (task );
1409
+ verify (stateUpdater , never ()).removeWithFuture (task .id ());
1396
1410
}
1397
1411
1398
1412
@ Test
@@ -1405,8 +1419,39 @@ public void shouldNotRevokeStandbyTaskInStateUpdaterOnRevocation() {
1405
1419
1406
1420
taskManager .handleRevocation (taskId00Partitions );
1407
1421
1408
- verify (stateUpdater , never ()).remove (task .id ());
1409
- verify (tasks , never ()).addPendingActiveTaskToSuspend (task .id ());
1422
+ verify (task , never ()).suspend ();
1423
+ verify (tasks , never ()).addTask (task );
1424
+ verify (stateUpdater , never ()).removeWithFuture (task .id ());
1425
+ }
1426
+
1427
+ @ Test
1428
+ public void shouldThrowIfRevokingTasksInStateUpdaterFindsFailedTasks () {
1429
+ final StreamTask task1 = statefulTask (taskId00 , taskId00ChangelogPartitions )
1430
+ .inState (State .RESTORING )
1431
+ .withInputPartitions (taskId00Partitions ).build ();
1432
+ final StreamTask task2 = statefulTask (taskId01 , taskId01ChangelogPartitions )
1433
+ .inState (State .RESTORING )
1434
+ .withInputPartitions (taskId01Partitions ).build ();
1435
+ final TasksRegistry tasks = mock (TasksRegistry .class );
1436
+ final TaskManager taskManager = setupForRevocationAndLost (mkSet (task1 , task2 ), tasks );
1437
+ final CompletableFuture <StateUpdater .RemovedTaskResult > future1 = new CompletableFuture <>();
1438
+ when (stateUpdater .removeWithFuture (task1 .id ())).thenReturn (future1 );
1439
+ future1 .complete (new StateUpdater .RemovedTaskResult (task1 ));
1440
+ final CompletableFuture <StateUpdater .RemovedTaskResult > future2 = new CompletableFuture <>();
1441
+ when (stateUpdater .removeWithFuture (task2 .id ())).thenReturn (future2 );
1442
+ final StreamsException streamsException = new StreamsException ("Something happened" );
1443
+ future2 .complete (new StateUpdater .RemovedTaskResult (task2 , streamsException ));
1444
+
1445
+ final StreamsException thrownException = assertThrows (
1446
+ StreamsException .class ,
1447
+ () -> taskManager .handleRevocation (union (HashSet ::new , taskId00Partitions , taskId01Partitions ))
1448
+ );
1449
+
1450
+ assertEquals (thrownException , streamsException );
1451
+ verify (task1 ).suspend ();
1452
+ verify (tasks ).addTask (task1 );
1453
+ verify (task2 , never ()).suspend ();
1454
+ verify (tasks ).addTask (task2 );
1410
1455
}
1411
1456
1412
1457
@ Test
0 commit comments