sashapolo commented on code in PR #6072: URL: https://github.com/apache/ignite-3/pull/6072#discussion_r2161519711
########## 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: > I don't see really difference between protected methods for testing and @TestOnly getters in IgniteImpl. There's no difference, `@TestOnly` methods are also bad. We should avoid such methods as mush as possible. > I don't see better solution to test storages closing issues. One of the problems is the in-place instantiation and this method also improves it. Is there any better solution? Tx storage is closed inside `ZoneResourcesManager` what's wrong with mocking its behaviour instead of the tx state storage. You will literally be testing the same scenario but without any protected methods and copy-paste of TX storages creation in tests. ########## 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: > I don't see really difference between protected methods for testing and @TestOnly getters in IgniteImpl. There's no difference, `@TestOnly` methods are also bad. We should avoid such methods as mush as possible. > I don't see better solution to test storages closing issues. One of the problems is the in-place instantiation and this method also improves it. Is there any better solution? Tx storage is closed inside `ZoneResourcesManager`, what's wrong with mocking its behaviour instead of the tx state storage. You will literally be testing the same scenario but without any protected methods and copy-paste of TX storages creation in tests. -- 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