JAkutenshi commented on code in PR #6072: URL: https://github.com/apache/ignite-3/pull/6072#discussion_r2161226837
########## modules/partition-replicator/src/test/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManagerTest.java: ########## @@ -324,4 +378,55 @@ void producesEventsOnPartitionDestroy() { assertThat(beforeReplicaDestroyedFuture.thenApply(LocalPartitionReplicaEventParameters::zonePartitionId), willBe(zonePartitionId)); assertThat(afterReplicaDestroyedFuture.thenApply(LocalPartitionReplicaEventParameters::zonePartitionId), willBe(zonePartitionId)); } + + @Test + public void partitionLifecycleManagerStopsCorrectWhenAllComponentsAreStoppedFine() throws Exception { + assertDoesNotThrow(() -> partitionReplicaLifecycleManager.beforeNodeStop()); + + assertThat(partitionReplicaLifecycleManager.stopAsync(), willCompleteSuccessfully()); + + verify(replicaManager, times(CatalogUtils.DEFAULT_PARTITION_COUNT)).stopReplica(any()); + } + + @Test + public void partitionLifecycleManagerStopsCorrectWhenReplicasAreStoppedExceptionally() throws Exception { + when(replicaManager.stopReplica(any())).thenThrow(new NodeStoppingException()); + + assertDoesNotThrow(() -> partitionReplicaLifecycleManager.beforeNodeStop()); + + assertThat(partitionReplicaLifecycleManager.stopAsync(), willCompleteSuccessfully()); + + // One more because of exceptional mock above counts. + verify(replicaManager, times(CatalogUtils.DEFAULT_PARTITION_COUNT + 1)).stopReplica(any()); + + // Do reset for correct replica manager stop on tear down. + reset(replicaManager); + } + + @Test + public void partitionLifecycleManagerStopsCorrectWhenTxStatePartitionStoragesAreStoppedExceptionally() throws Exception { + doReturn(commonZonePartitionResources).when(zoneResourcesManager).getZonePartitionResources(any()); + + int defaultZoneId = 0; + List<ZonePartitionResources> defaultZoneResources = IntStream.range(0, CatalogUtils.DEFAULT_PARTITION_COUNT) + .mapToObj(partId -> new ZonePartitionId(defaultZoneId, partId)) + .map(partitionReplicaLifecycleManager::zonePartitionResources) + .collect(Collectors.toList()); + + defaultZoneResources.forEach(resources -> { + TxStatePartitionStorage txStorage = resources.txStatePartitionStorage(); + + doThrow(new RuntimeException()).when(txStorage).close(); + }); + + assertDoesNotThrow(() -> partitionReplicaLifecycleManager.beforeNodeStop()); + + assertThat(partitionReplicaLifecycleManager.stopAsync(), willThrow(RuntimeException.class)); + + verify(replicaManager, times(CatalogUtils.DEFAULT_PARTITION_COUNT)).stopReplica(any()); + + defaultZoneResources.forEach(resources -> verify(resources.txStatePartitionStorage(), atLeastOnce()).close()); + + defaultZoneResources.forEach(resources -> reset(resources.txStatePartitionStorage())); Review Comment: The first verifies that `close` was actually called, the last resets the storage mocks for tear down process without test related mocks problems. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org