sashapolo commented on code in PR #6072: URL: https://github.com/apache/ignite-3/pull/6072#discussion_r2161397426
########## 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(); Review Comment: Drilling holes by introducing unnecessary protected methods does not make the code more testable and should always be the last resort -- 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