|
84 | 84 | import io.grpc.InternalChannelz;
|
85 | 85 | import io.grpc.InternalChannelz.ChannelStats;
|
86 | 86 | import io.grpc.InternalChannelz.ChannelTrace;
|
| 87 | +import io.grpc.InternalChannelz.ChannelTrace.Event.Severity; |
87 | 88 | import io.grpc.InternalConfigSelector;
|
88 | 89 | import io.grpc.InternalInstrumented;
|
89 | 90 | import io.grpc.LoadBalancer;
|
|
123 | 124 | import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
|
124 | 125 | import io.grpc.internal.ManagedChannelImplBuilder.FixedPortProvider;
|
125 | 126 | import io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder;
|
| 127 | +import io.grpc.internal.ManagedChannelServiceConfig.MethodInfo; |
126 | 128 | import io.grpc.internal.ServiceConfigUtil.PolicySelection;
|
127 | 129 | import io.grpc.internal.TestUtils.MockClientTransportInfo;
|
128 | 130 | import io.grpc.stub.ClientCalls;
|
@@ -1127,6 +1129,55 @@ public void noMoreCallbackAfterLoadBalancerShutdown_configError() throws Interru
|
1127 | 1129 | verifyNoMoreInteractions(mockLoadBalancer);
|
1128 | 1130 | }
|
1129 | 1131 |
|
| 1132 | + @Test |
| 1133 | + public void addressResolutionError_noPriorNameResolution_usesDefaultServiceConfig() |
| 1134 | + throws Exception { |
| 1135 | + Map<String, Object> rawServiceConfig = |
| 1136 | + parseConfig("{\"methodConfig\":[{" |
| 1137 | + + "\"name\":[{\"service\":\"service\"}]," |
| 1138 | + + "\"waitForReady\":true}]}"); |
| 1139 | + ManagedChannelServiceConfig managedChannelServiceConfig = |
| 1140 | + createManagedChannelServiceConfig(rawServiceConfig, null); |
| 1141 | + FakeNameResolverFactory nameResolverFactory = |
| 1142 | + new FakeNameResolverFactory.Builder(expectedUri) |
| 1143 | + .setServers(Collections.singletonList(new EquivalentAddressGroup(socketAddress))) |
| 1144 | + .setResolvedAtStart(false) |
| 1145 | + .build(); |
| 1146 | + nameResolverFactory.nextConfigOrError.set( |
| 1147 | + ConfigOrError.fromConfig(managedChannelServiceConfig)); |
| 1148 | + channelBuilder.nameResolverFactory(nameResolverFactory); |
| 1149 | + Map<String, Object> defaultServiceConfig = |
| 1150 | + parseConfig("{\"methodConfig\":[{" |
| 1151 | + + "\"name\":[{\"service\":\"service\"}]," |
| 1152 | + + "\"waitForReady\":true}]}"); |
| 1153 | + channelBuilder.defaultServiceConfig(defaultServiceConfig); |
| 1154 | + Status resolutionError = Status.UNAVAILABLE.withDescription("Resolution failed"); |
| 1155 | + channelBuilder.maxTraceEvents(10); |
| 1156 | + createChannel(); |
| 1157 | + FakeNameResolverFactory.FakeNameResolver resolver = nameResolverFactory.resolvers.get(0); |
| 1158 | + |
| 1159 | + resolver.listener.onError(resolutionError); |
| 1160 | + |
| 1161 | + InternalConfigSelector configSelector = channel.getConfigSelector(); |
| 1162 | + ManagedChannelServiceConfig config = |
| 1163 | + (ManagedChannelServiceConfig) configSelector.selectConfig(null).getConfig(); |
| 1164 | + MethodInfo methodConfig = config.getMethodConfig(method); |
| 1165 | + assertThat(methodConfig.waitForReady).isTrue(); |
| 1166 | + timer.forwardNanos(1234); |
| 1167 | + assertThat(getStats(channel).channelTrace.events).contains(new ChannelTrace.Event.Builder() |
| 1168 | + .setDescription("Initial Name Resolution error, using default service config") |
| 1169 | + .setSeverity(Severity.CT_ERROR) |
| 1170 | + .setTimestampNanos(0) |
| 1171 | + .build()); |
| 1172 | + |
| 1173 | + // Check that "lastServiceConfig" variable has been set above: a config resolution with the same |
| 1174 | + // config simply gets ignored and not gets reassigned. |
| 1175 | + resolver.resolved(); |
| 1176 | + timer.forwardNanos(1234); |
| 1177 | + assertThat(getStats(channel).channelTrace.events.stream().filter( |
| 1178 | + event -> event.description.equals("Service config changed")).count()).isEqualTo(0); |
| 1179 | + } |
| 1180 | + |
1130 | 1181 | @Test
|
1131 | 1182 | public void interceptor() throws Exception {
|
1132 | 1183 | final AtomicLong atomic = new AtomicLong();
|
@@ -4595,7 +4646,7 @@ public void notUseDefaultImmediatelyIfEnableLookUp() throws Exception {
|
4595 | 4646 | int size = getStats(channel).channelTrace.events.size();
|
4596 | 4647 | assertThat(getStats(channel).channelTrace.events.get(size - 1))
|
4597 | 4648 | .isNotEqualTo(new ChannelTrace.Event.Builder()
|
4598 |
| - .setDescription("Using default service config") |
| 4649 | + .setDescription("timer.forwardNanos(1234);") |
4599 | 4650 | .setSeverity(ChannelTrace.Event.Severity.CT_INFO)
|
4600 | 4651 | .setTimestampNanos(timer.getTicker().read())
|
4601 | 4652 | .build());
|
|
0 commit comments