This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
fix: InstantiatingGrpcChannelProvider.toBuilder() should carry over all config data #1298
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,45 @@ public void testWithPoolSize() throws IOException { | |
} | ||
} | ||
|
||
@Test | ||
public void testToBuilder() { | ||
Duration keepaliveTime = Duration.ofSeconds(1); | ||
Duration keepaliveTimeout = Duration.ofSeconds(2); | ||
ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator = | ||
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() { | ||
@Override | ||
public ManagedChannelBuilder apply(ManagedChannelBuilder input) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}; | ||
Map<String, ?> directPathServiceConfig = ImmutableMap.of("loadbalancingConfig", "grpclb"); | ||
|
||
InstantiatingGrpcChannelProvider provider = | ||
InstantiatingGrpcChannelProvider.newBuilder() | ||
.setProcessorCount(2) | ||
.setEndpoint("fake.endpoint:443") | ||
.setMaxInboundMessageSize(12345678) | ||
.setMaxInboundMetadataSize(4096) | ||
.setKeepAliveTime(keepaliveTime) | ||
.setKeepAliveTimeout(keepaliveTimeout) | ||
.setKeepAliveWithoutCalls(true) | ||
.setChannelConfigurator(channelConfigurator) | ||
.setChannelsPerCpu(2.5) | ||
.setDirectPathServiceConfig(directPathServiceConfig) | ||
.build(); | ||
|
||
InstantiatingGrpcChannelProvider.Builder builder = provider.toBuilder(); | ||
|
||
assertThat(builder.getEndpoint()).isEqualTo("fake.endpoint:443"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gratuitous use of Truth. assertEquals is fully adequate here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean |
||
assertThat(builder.getMaxInboundMessageSize()).isEqualTo(12345678); | ||
assertThat(builder.getMaxInboundMetadataSize()).isEqualTo(4096); | ||
assertThat(builder.getKeepAliveTime()).isEqualTo(keepaliveTime); | ||
assertThat(builder.getKeepAliveTimeout()).isEqualTo(keepaliveTimeout); | ||
assertThat(builder.getChannelConfigurator()).isEqualTo(channelConfigurator); | ||
assertThat(builder.getPoolSize()).isEqualTo(5); | ||
assertThat(builder.build().directPathServiceConfig).isEqualTo(directPathServiceConfig); | ||
} | ||
|
||
@Test | ||
public void testWithInterceptors() throws Exception { | ||
testWithInterceptors(1); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this class have a good equals method? that could make for a more robust test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not (resolves to default
Object#equals()
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InstantiatingGrpcChannelProvider
has complex logic such as relation between PoolSize and ProcessorCount and ChannelsPerCpu, and attributes depending on system properties and env. It might not make much sense to simply implementequals()
by comparing its fields, just for testing purpose.