@Override
    public Optional<SimpleAddress> selectAddress(Optional<String> addressSelectionContext)
    {
        if (addressSelectionContext.isPresent()) {
            return addressSelectionContext
                    .map(HostAndPort::fromString)
                    .map(SimpleAddress::new);
        }
        List<HostAndPort> resourceManagers = internalNodeManager.getResourceManagers().stream()
                .filter(node -> node.getThriftPort().isPresent())
                .map(resourceManagerNode -> {
                    HostAddress hostAndPort = resourceManagerNode.getHostAndPort();
                    return HostAndPort.fromParts(hostAndPort.getHostText(), resourceManagerNode.getThriftPort().getAsInt());
                })
                .collect(toImmutableList());
        return hostSelector.apply(resourceManagers).map(SimpleAddress::new);
    }
@Test
    public void testAddressSelectionContextPresent()
    {
        InMemoryNodeManager internalNodeManager = new InMemoryNodeManager();
        RandomResourceManagerAddressSelector selector = new RandomResourceManagerAddressSelector(internalNodeManager);

        HostAndPort hostAndPort = HostAndPort.fromParts("abc", 123);
        Optional<SimpleAddressSelector.SimpleAddress> address = selector.selectAddress(Optional.of(hostAndPort.toString()));
        assertTrue(address.isPresent());
        assertEquals(address.get().getHostAndPort(), hostAndPort);
    }