@Override
    public void handleResolvedAddresses(final ResolvedAddresses resolvedAddresses) {
        setAttribute(resolvedAddresses.getAttributes());
        Set<EquivalentAddressGroup> currentAddrs = subchannels.keySet();
        Map<EquivalentAddressGroup, EquivalentAddressGroup> latestAddrs = stripAttrs(resolvedAddresses.getAddresses());
        Set<EquivalentAddressGroup> removedAddrs = setsDifference(currentAddrs, latestAddrs.keySet());
        for (Map.Entry<EquivalentAddressGroup, EquivalentAddressGroup> latestEntry : latestAddrs.entrySet()) {
            EquivalentAddressGroup strippedAddressGroup = latestEntry.getKey();
            EquivalentAddressGroup originalAddressGroup = latestEntry.getValue();
            Subchannel subchannel;
            Subchannel existingSubchannel = subchannels.get(strippedAddressGroup);
            if (Objects.nonNull(existingSubchannel)) {
                subchannel = existingSubchannel;
                SubChannels.updateAttributes(existingSubchannel, originalAddressGroup.getAttributes());
            } else {
                subchannel = SubChannels.createSubChannel(helper, strippedAddressGroup, originalAddressGroup.getAttributes());
                subchannel.start(state -> processSubchannelState(subchannel, state));
                subchannels.put(strippedAddressGroup, subchannel);
            }
            subchannel.requestConnection();
        }
        List<Subchannel> removedSubchannels = new ArrayList<>();
        for (EquivalentAddressGroup addressGroup : removedAddrs) {
            removedSubchannels.add(subchannels.remove(addressGroup));
        }
        updateBalancingState();
        for (Subchannel removedSubchannel : removedSubchannels) {
            shutdownSubchannel(removedSubchannel);
        }
    }
@Test
    public void testHandleResolvedAddresses() {
        LoadBalancer.Helper helper = new UnitTestReadHelper();
        final LoadBalancer loadBalancer = randomLoadBalancerProvider.newLoadBalancer(helper);
        EquivalentAddressGroup group = new EquivalentAddressGroup(new LocalAddress("id"));
        LoadBalancer.ResolvedAddresses resolvedAddresses = mock(LoadBalancer.ResolvedAddresses.class);
        when(resolvedAddresses.getAddresses()).thenReturn(Collections.singletonList(group));
        Attributes attributes = mock(Attributes.class);
        when(attributes.get(GrpcAttributeUtils.APP_NAME)).thenReturn("");
        when(resolvedAddresses.getAttributes()).thenReturn(attributes);
        loadBalancer.handleResolvedAddresses(resolvedAddresses);

        LoadBalancer.Helper idleHelper = new UnitTestIdleHelper();
        final LoadBalancer idleLoadBalancer = randomLoadBalancerProvider.newLoadBalancer(idleHelper);
        idleLoadBalancer.handleResolvedAddresses(resolvedAddresses);
        idleLoadBalancer.shutdown();
    }