Repository navigation
fix(bigtable): disable SwitchingChannelPool when ChannelPoolConfiguration is empty - #14911
igorbernstein2 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for disabling the channel pool in SwitchingChannelPool by utilizing a new NoopChannelPool when the configuration is empty or default. It refactors delegate creation and config updates to seamlessly transition between enabled and disabled states, and adds a comprehensive test suite in SwitchingChannelPoolTest. The review feedback suggests a minor improvement in the test code to avoid reusing the same ArgumentCaptor instance across different mock verifications, which can lead to fragile tests.
| verify(secondListener).onClose(statusCaptor.capture(), any(Metadata.class)); | ||
| assertThat(statusCaptor.getValue().getCode()).isEqualTo(Status.Code.UNAVAILABLE); |
There was a problem hiding this comment.
Reusing the same ArgumentCaptor instance (statusCaptor) across different mock verifications (streamListener and secondListener) is a code smell and can lead to fragile tests or unexpected behavior if the verifications are reordered or if multiple interactions occur. It is safer and cleaner to use a separate ArgumentCaptor instance for the second verification.
| verify(secondListener).onClose(statusCaptor.capture(), any(Metadata.class)); | |
| assertThat(statusCaptor.getValue().getCode()).isEqualTo(Status.Code.UNAVAILABLE); | |
| ArgumentCaptor<Status> secondStatusCaptor = ArgumentCaptor.forClass(Status.class); | |
| verify(secondListener).onClose(secondStatusCaptor.capture(), any(Metadata.class)); | |
| assertThat(secondStatusCaptor.getValue().getCode()).isEqualTo(Status.Code.UNAVAILABLE); |
Summary
When
session_load == 0across all scopes,ClientConfigurationManager.normalizeConfigclearssession_configuration, resulting in an emptyChannelPoolConfiguration.getDefaultInstance().This change updates
SwitchingChannelPoolto treat an emptyChannelPoolConfiguration(config.equals(ChannelPoolConfiguration.getDefaultInstance())) as disabled:NoopChannelPoolwhen disabled, which creates no underlying channels and immediately failsnewStreamwithStatus.UNAVAILABLE.NoopChannelPool) and enabled (ChannelPoolDpImpl/FallbackChannelPool/SingleChannelPool) onupdateConfigviareplaceChannelPool(createDelegate()), shutting down the active pool's channels when disabled.