Example usage for com.google.common.net HostAndPort getHostText

List of usage examples for com.google.common.net HostAndPort getHostText

Introduction

In this page you can find the example usage for com.google.common.net HostAndPort getHostText.

Prototype

public String getHostText() 

Source Link

Document

Returns the portion of this HostAndPort instance that should represent the hostname or IPv4/IPv6 literal.

Usage

From source file:org.apache.brooklyn.location.byon.ByonLocationResolver.java

protected LocationSpec<? extends MachineLocation> parseMachine(Map<String, ?> vals,
        Class<? extends MachineLocation> locationClass, Map<String, ?> defaults, String specForErrMsg) {
    Map<String, Object> valSanitized = Sanitizer.sanitize(vals);
    Map<String, Object> machineConfig = MutableMap.copyOf(vals);

    String osFamily = (String) machineConfig.remove(OS_FAMILY.getName());
    String ssh = (String) machineConfig.remove("ssh");
    String winrm = (String) machineConfig.remove("winrm");
    Map<Integer, String> tcpPortMappings = (Map<Integer, String>) machineConfig.get("tcpPortMappings");

    checkArgument(ssh != null ^ winrm != null, "Must specify exactly one of 'ssh' or 'winrm' for machine: %s",
            valSanitized);/*from   w w w .j  a  v a2s. com*/

    UserAndHostAndPort userAndHostAndPort;
    String host;
    int port;
    if (ssh != null) {
        userAndHostAndPort = parseUserAndHostAndPort((String) ssh, 22);
    } else {
        userAndHostAndPort = parseUserAndHostAndPort((String) winrm, 5985);
    }

    // If there is a tcpPortMapping defined for the connection-port, then use that for ssh/winrm machine
    port = userAndHostAndPort.getHostAndPort().getPort();
    if (tcpPortMappings != null && tcpPortMappings.containsKey(port)) {
        String override = tcpPortMappings.get(port);
        HostAndPort hostAndPortOverride = HostAndPort.fromString(override);
        if (!hostAndPortOverride.hasPort()) {
            throw new IllegalArgumentException(
                    "Invalid portMapping ('" + override + "') for port " + port + " in " + specForErrMsg);
        }
        port = hostAndPortOverride.getPort();
        host = hostAndPortOverride.getHostText().trim();
    } else {
        host = userAndHostAndPort.getHostAndPort().getHostText().trim();
    }

    machineConfig.put("address", host);
    try {
        InetAddress.getByName(host);
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "Invalid host '" + host + "' specified in '" + specForErrMsg + "': " + e);
    }

    if (userAndHostAndPort.getUser() != null) {
        checkArgument(!vals.containsKey("user"), "Must not specify user twice for machine: %s", valSanitized);
        machineConfig.put("user", userAndHostAndPort.getUser());
    }
    if (userAndHostAndPort.getHostAndPort().hasPort()) {
        checkArgument(!vals.containsKey("port"), "Must not specify port twice for machine: %s", valSanitized);
        machineConfig.put("port", port);
    }
    for (Map.Entry<String, ?> entry : defaults.entrySet()) {
        if (!machineConfig.containsKey(entry.getKey())) {
            machineConfig.put(entry.getKey(), entry.getValue());
        }
    }

    Class<? extends MachineLocation> locationClassHere = locationClass;
    if (osFamily != null) {
        locationClassHere = getLocationClass(osFamily);
    }

    return LocationSpec.create(locationClassHere).configure(machineConfig);
}

From source file:org.apache.brooklyn.entity.proxy.AbstractControllerImpl.java

/** returns URL, if it can be inferred; null otherwise */
protected String inferUrl(boolean requireManagementAccessible) {
    String protocol = checkNotNull(getProtocol(), "no protocol configured");
    String domain = getDomain();//from w  w w  . j  a v  a2  s . com
    if (domain != null && domain.startsWith("*.")) {
        domain = domain.replace("*.", ""); // Strip wildcard
    }
    Integer port = checkNotNull(getPort(), "no port configured (the requested port may be in use)");
    if (requireManagementAccessible) {
        HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port);
        if (accessible != null) {
            domain = accessible.getHostText();
            port = accessible.getPort();
        }
    }
    if (domain == null)
        domain = Machines.findSubnetHostname(this).orNull();
    if (domain == null)
        return null;
    return protocol + "://" + domain + ":" + port + "/" + getConfig(SERVICE_UP_URL_PATH);
}

From source file:org.apache.brooklyn.location.basic.WinRmMachineLocation.java

@Override
public void init() {
    super.init();

    // Register any pre-existing port-mappings with the PortForwardManager
    Map<Integer, String> tcpPortMappings = getConfig(TCP_PORT_MAPPINGS);
    if (tcpPortMappings != null) {
        PortForwardManager pfm = (PortForwardManager) getManagementContext().getLocationRegistry()
                .resolve("portForwardManager(scope=global)");
        for (Map.Entry<Integer, String> entry : tcpPortMappings.entrySet()) {
            int targetPort = entry.getKey();
            HostAndPort publicEndpoint = HostAndPort.fromString(entry.getValue());
            if (!publicEndpoint.hasPort()) {
                throw new IllegalArgumentException("Invalid portMapping ('" + entry.getValue() + "') for port "
                        + targetPort + " in machine " + this);
            }/* w  w w  .  j  a  v  a 2  s . c o  m*/
            pfm.associate(publicEndpoint.getHostText(), publicEndpoint, this, targetPort);
        }
    }
}

From source file:com.streamsets.pipeline.kafka.impl.KafkaLowLevelConsumer09.java

private HostAndPort findNewLeader(HostAndPort oldLeader, String topic, int partition) throws StageException {
    //try 3 times to find a new leader
    for (int i = 0; i < 3; i++) {
        boolean sleep;
        PartitionMetadata metadata = getPartitionMetadata(replicaBrokers, topic, partition);
        if (metadata == null || metadata.leader() == null) {
            sleep = true;//ww  w .  j  av  a 2 s .  com
        } else if (oldLeader.getHostText().equalsIgnoreCase(metadata.leader().host()) && i == 0) {
            //leader has not yet changed, give zookeeper sometime
            sleep = true;
        } else {
            return HostAndPort.fromParts(metadata.leader().host(), metadata.leader().port());
        }
        if (sleep) {
            ThreadUtil.sleep(ONE_SECOND);
        }
    }
    LOG.error(KafkaErrors.KAFKA_21.getMessage());
    throw new StageException(KafkaErrors.KAFKA_21);
}

From source file:org.wso2.mb.platform.tests.clustering.MultipleSubscriberMultiplePublisherTestCase.java

/**
 * Multiple subscribers and publishers in same node for a single queue
 *
 * @param messageCount Number of message to send and receive
 * @throws XPathExpressionException/*from   w  w  w .  ja  va  2 s  .  c o m*/
 * @throws AndesClientConfigurationException
 * @throws NamingException
 * @throws JMSException
 * @throws IOException
 * @throws AndesClientException
 */
@Test(groups = "wso2.mb", description = "Same node single queue multiple subscriber " + "publisher test case")
@Parameters({ "messageCount" })
public void testSameNodeSingleQueueMultipleSubscriberPublisher(long messageCount)
        throws XPathExpressionException, AndesClientConfigurationException, NamingException, JMSException,
        IOException, AndesClientException, DataAccessUtilException, InterruptedException {
    // Number of messages expected
    long expectedCount = messageCount;
    // Number of messages send
    long sendCount = messageCount;
    String queueName = "singleQueue1";

    HostAndPort brokerAddress = getRandomAMQPBrokerAddress();

    AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(
            brokerAddress.getHostText(), brokerAddress.getPort(), ExchangeType.QUEUE, queueName);
    consumerConfig.setMaximumMessagesToReceived(expectedCount);
    consumerConfig.setPrintsPerMessageCount(expectedCount / 10L);

    AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration(
            brokerAddress.getHostText(), brokerAddress.getPort(), ExchangeType.QUEUE, queueName);
    publisherConfig.setNumberOfMessagesToSend(sendCount);
    publisherConfig.setPrintsPerMessageCount(sendCount / 10L);

    AndesClient consumerClient1 = new AndesClient(consumerConfig, true);
    consumerClient1.startClient();
    AndesClient consumerClient2 = new AndesClient(consumerConfig, true);
    consumerClient2.startClient();
    AndesClient consumerClient3 = new AndesClient(consumerConfig, true);
    consumerClient3.startClient();
    AndesClient consumerClient4 = new AndesClient(consumerConfig, true);
    consumerClient4.startClient();

    AndesClient publisherClient1 = new AndesClient(publisherConfig, true);
    publisherClient1.startClient();
    AndesClient publisherClient2 = new AndesClient(publisherConfig, true);
    publisherClient2.startClient();
    AndesClient publisherClient3 = new AndesClient(publisherConfig, true);
    publisherClient3.startClient();
    AndesClient publisherClient4 = new AndesClient(publisherConfig, true);
    publisherClient4.startClient();

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient1, AndesClientConstants.DEFAULT_RUN_TIME);
    AndesClientUtils.shutdownClient(consumerClient2);
    AndesClientUtils.shutdownClient(consumerClient3);
    AndesClientUtils.shutdownClient(consumerClient4);
    // Wait until consumers are closed
    Thread.sleep(AndesClientConstants.DEFAULT_RUN_TIME);

    Assert.assertEquals(publisherClient1.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient1.");
    Assert.assertEquals(publisherClient2.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient2.");
    Assert.assertEquals(publisherClient3.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient3.");
    Assert.assertEquals(publisherClient4.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient4.");
    Assert.assertEquals(consumerClient1.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient1.");
    Assert.assertEquals(consumerClient2.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient2.");
    Assert.assertEquals(consumerClient3.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient3.");
    Assert.assertEquals(consumerClient4.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient4.");

    long totalMessagesSent = publisherClient1.getSentMessageCount() + publisherClient2.getSentMessageCount()
            + publisherClient3.getSentMessageCount() + publisherClient4.getSentMessageCount();
    long totalMessagesReceived = consumerClient1.getReceivedMessageCount()
            + consumerClient2.getReceivedMessageCount() + consumerClient3.getReceivedMessageCount()
            + consumerClient4.getReceivedMessageCount();
    Assert.assertEquals(totalMessagesSent, totalMessagesReceived, "Message receiving failed by all consumers");
    Assert.assertEquals(totalMessagesSent, sendCount * 4,
            "Message receiving by all consumers does not match the message count that was sent");

    // Evaluate messages left in database
    Assert.assertEquals(dataAccessUtil.getMessageCountForQueue(queueName), 0, "Messages left in database");
    // Evaluate slots left in database
    Assert.assertEquals(dataAccessUtil.getAssignedSlotCountForQueue(queueName), 0, "Slots left in database");
}

From source file:brooklyn.networking.vclouddirector.PortForwarderVcloudDirector.java

@Override
public HostAndPort openPortForwarding(HostAndPort targetEndpoint, Optional<Integer> optionalPublicPort,
        Protocol protocol, Cidr accessingCidr) {
    // TODO should associate ip:port with PortForwardManager; but that takes location param
    //      getPortForwardManager().associate(publicIp, publicPort, targetVm, targetPort);
    // TODO Could check old mapping, and re-use that public port
    // TODO Pass cidr in vcloud-director call
    String publicIp = subnetTier.getConfig(NETWORK_PUBLIC_IP);

    HostAndPort publicEndpoint;/*from ww w.jav  a 2 s . c  o  m*/
    PortRange portRangeToUse;
    if (optionalPublicPort.isPresent()) {
        publicEndpoint = HostAndPort.fromParts(publicIp, optionalPublicPort.get());
        portRangeToUse = null;
    } else if (getNatMicroserviceAutoAllocatesPorts()) {
        publicEndpoint = HostAndPort.fromString(publicIp);
        portRangeToUse = getPortRange();
    } else {
        PortForwardManager pfw = getPortForwardManager();
        int publicPort = pfw.acquirePublicPort(publicIp);
        publicEndpoint = HostAndPort.fromParts(publicIp, publicPort);
        portRangeToUse = null;
    }

    try {
        HostAndPort result = getClient().openPortForwarding(new PortForwardingConfig().protocol(Protocol.TCP)
                .publicEndpoint(publicEndpoint).publicPortRange(portRangeToUse).targetEndpoint(targetEndpoint));

        // TODO Work around for old vCD NAT microservice, which returned empty result
        if (!result.hasPort() && result.getHostText().equals("")) {
            if (publicEndpoint.hasPort()) {
                LOG.warn(
                        "[DEPRECATED] NAT Rule addition returned endpoint '{}'; probably old micro-service version; "
                                + "assuming result is {}->{} via {}",
                        new Object[] { result, publicEndpoint, targetEndpoint, subnetTier });
                result = publicEndpoint;
            } else {
                throw new IllegalStateException("Invalid result for NAT Rule addition, returned endpoint ''; "
                        + "cannot infer actual result as no explicit port requested for " + publicEndpoint
                        + "->" + targetEndpoint + " via " + subnetTier);
            }
        }

        LOG.debug("Enabled port-forwarding for {}, via {}, on ",
                new Object[] { targetEndpoint, result, subnetTier });
        return result;
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);
        LOG.info("Failed creating port forwarding rule on " + this + ": " + publicEndpoint + "->"
                + targetEndpoint + "; rethrowing", e);
        throw Exceptions.propagate(e);
    }
}

From source file:com.pinterest.secor.common.LegacyKafkaClient.java

private SimpleConsumer createConsumer(TopicPartition topicPartition) {
    HostAndPort leader = findLeader(topicPartition);
    if (leader == null) {
        LOG.warn("no leader for topic {} partition {}", topicPartition.getTopic(),
                topicPartition.getPartition());
        return null;
    }/*from w  w  w . ja v  a 2s .  c o m*/
    LOG.debug("leader for topic {} partition {} is {}", topicPartition.getTopic(),
            topicPartition.getPartition(), leader);
    final String clientName = getClientName(topicPartition);
    return createConsumer(leader.getHostText(), leader.getPort(), clientName);
}

From source file:brooklyn.entity.nosql.elasticsearch.ElasticSearchNodeImpl.java

@Override
protected void connectSensors() {
    super.connectSensors();
    Integer rawPort = getAttribute(HTTP_PORT);
    checkNotNull(rawPort, "HTTP_PORT sensors not set for %s; is an acceptable port available?", this);
    HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, rawPort);
    Function<Maybe<JsonElement>, String> getNodeId = new Function<Maybe<JsonElement>, String>() {
        @Override/*from   w w  w .  j  av a  2  s  . c  o m*/
        public String apply(Maybe<JsonElement> input) {
            if (input.isAbsent()) {
                return null;
            }
            return input.get().getAsJsonObject().entrySet().iterator().next().getKey();
        }
    };
    httpFeed = HttpFeed.builder().entity(this).period(1000)
            .baseUri(String.format("http://%s:%s/_nodes/_local/stats", hp.getHostText(), hp.getPort()))
            .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200))
                    .onFailureOrException(Functions.constant(false)))
            .poll(new HttpPollConfig<String>(NODE_ID)
                    .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(),
                            MaybeFunctions.<JsonElement>wrap(), JsonFunctions.walkM("nodes"), getNodeId))
                    .onFailureOrException(Functions.constant("")))
            .poll(getSensorFromNodeStat(NODE_NAME, "name"))
            .poll(getSensorFromNodeStat(DOCUMENT_COUNT, "indices", "docs", "count"))
            .poll(getSensorFromNodeStat(STORE_BYTES, "indices", "store", "size_in_bytes"))
            .poll(getSensorFromNodeStat(GET_TOTAL, "indices", "get", "total"))
            .poll(getSensorFromNodeStat(GET_TIME_IN_MILLIS, "indices", "get", "time_in_millis"))
            .poll(getSensorFromNodeStat(SEARCH_QUERY_TOTAL, "indices", "search", "query_total"))
            .poll(getSensorFromNodeStat(SEARCH_QUERY_TIME_IN_MILLIS, "indices", "search",
                    "query_time_in_millis"))
            .poll(new HttpPollConfig<String>(CLUSTER_NAME)
                    .onSuccess(HttpValueFunctions.jsonContents("cluster_name", String.class)))
            .build();
}

From source file:org.apache.brooklyn.entity.brooklynnode.BrooklynNodeImpl.java

@Override
protected void connectSensors() {
    super.connectSensors();

    // TODO what sensors should we poll?
    ConfigToAttributes.apply(this);

    URI webConsoleUri;/* ww w  .  j a  v  a  2 s  . c o m*/
    if (isHttpProtocolEnabled("http")) {
        int port = getConfig(PORT_MAPPER).apply(getAttribute(HTTP_PORT));
        HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port);
        webConsoleUri = URI
                .create(String.format("http://%s:%s", accessible.getHostText(), accessible.getPort()));
    } else if (isHttpProtocolEnabled("https")) {
        int port = getConfig(PORT_MAPPER).apply(getAttribute(HTTPS_PORT));
        HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port);
        webConsoleUri = URI
                .create(String.format("https://%s:%s", accessible.getHostText(), accessible.getPort()));
    } else {
        // web-console is not enabled
        webConsoleUri = null;
    }
    sensors().set(WEB_CONSOLE_URI, webConsoleUri);

    if (webConsoleUri != null) {
        httpFeed = HttpFeed.builder().entity(this).period(getConfig(POLL_PERIOD)).baseUri(webConsoleUri)
                .credentialsIfNotNull(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD))
                .poll(new HttpPollConfig<Boolean>(WEB_CONSOLE_ACCESSIBLE).suburl("/v1/server/healthy")
                        .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(),
                                JsonFunctions.cast(Boolean.class)))
                        //if using an old distribution the path doesn't exist, but at least the instance is responding
                        .onFailure(HttpValueFunctions.responseCodeEquals(404)).setOnException(false))
                .poll(new HttpPollConfig<ManagementNodeState>(MANAGEMENT_NODE_STATE)
                        .suburl("/v1/server/ha/state")
                        .onSuccess(Functionals.chain(
                                Functionals.chain(HttpValueFunctions.jsonContents(),
                                        JsonFunctions.cast(String.class)),
                                Enums.fromStringFunction(ManagementNodeState.class)))
                        .setOnFailureOrException(null))
                // TODO sensors for load, size, etc
                .build();

        if (!Lifecycle.RUNNING.equals(getAttribute(SERVICE_STATE_ACTUAL))) {
            // TODO when updating the map, if it would change from empty to empty on a successful run (see in nginx)
            ServiceNotUpLogic.updateNotUpIndicator(this, WEB_CONSOLE_ACCESSIBLE,
                    "No response from the web console yet");
        }
        enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS)
                .from(WEB_CONSOLE_ACCESSIBLE).computing(Functionals.ifNotEquals(true)
                        .value("URL where Brooklyn listens is not answering correctly"))
                .build());

        addEnricher(Enrichers.builder().transforming(WEB_CONSOLE_ACCESSIBLE).computing(Functions.identity())
                .publishing(SERVICE_PROCESS_IS_RUNNING).build());
    } else {
        connectServiceUpIsRunning();
    }
}

From source file:org.wso2.mb.platform.tests.clustering.MultipleSubscriberMultiplePublisherTestCase.java

/**
 * Multiple subscribers and publishers in Multiple node for a single queue
 *
 * @param messageCount Number of message to send and receive
 * @throws AndesClientConfigurationException
 * @throws XPathExpressionException// w w w.  j  a v a  2 s.  co m
 * @throws NamingException
 * @throws JMSException
 * @throws IOException
 * @throws AndesClientException
 */
@Test(groups = "wso2.mb", description = "Multiple node single queue multiple subscriber "
        + "publisher test case")
@Parameters({ "messageCount" })
public void testMultiNodeSingleQueueMultipleSubscriberPublisher(long messageCount)
        throws AndesClientConfigurationException, XPathExpressionException, NamingException, JMSException,
        IOException, AndesClientException, CloneNotSupportedException, DataAccessUtilException,
        InterruptedException {
    // Number of messages expected
    long expectedCount = messageCount;
    // Number of messages send
    long sendCount = messageCount;
    String queueName = "singleQueue2";
    HostAndPort consumerBrokerAddress = getRandomAMQPBrokerAddress();

    AndesJMSConsumerClientConfiguration consumerConfig1 = new AndesJMSConsumerClientConfiguration(
            consumerBrokerAddress.getHostText(), consumerBrokerAddress.getPort(), ExchangeType.QUEUE,
            queueName);
    consumerConfig1.setMaximumMessagesToReceived(expectedCount);
    consumerConfig1.setPrintsPerMessageCount(expectedCount / 10L);

    HostAndPort publisherBrokerAddress = getRandomAMQPBrokerAddress();
    AndesJMSPublisherClientConfiguration publisherConfig1 = new AndesJMSPublisherClientConfiguration(
            publisherBrokerAddress.getHostText(), publisherBrokerAddress.getPort(), ExchangeType.QUEUE,
            queueName);
    publisherConfig1.setNumberOfMessagesToSend(sendCount);
    publisherConfig1.setPrintsPerMessageCount(sendCount / 10L);

    AndesClient consumerClient1 = new AndesClient(consumerConfig1, true);
    consumerClient1.startClient();

    AndesJMSConsumerClientConfiguration consumerConfig2 = consumerConfig1.clone();
    HostAndPort randomAMQPBrokerAddress = getRandomAMQPBrokerAddress();
    consumerConfig2.setHostName(randomAMQPBrokerAddress.getHostText());
    consumerConfig2.setPort(randomAMQPBrokerAddress.getPort());
    AndesClient consumerClient2 = new AndesClient(consumerConfig2, true);
    consumerClient2.startClient();

    AndesJMSConsumerClientConfiguration consumerConfig3 = consumerConfig1.clone();
    randomAMQPBrokerAddress = getRandomAMQPBrokerAddress();
    consumerConfig3.setHostName(randomAMQPBrokerAddress.getHostText());
    consumerConfig3.setPort(randomAMQPBrokerAddress.getPort());
    AndesClient consumerClient3 = new AndesClient(consumerConfig3, true);
    consumerClient3.startClient();

    AndesJMSConsumerClientConfiguration consumerConfig4 = consumerConfig1.clone();
    randomAMQPBrokerAddress = getRandomAMQPBrokerAddress();
    consumerConfig4.setHostName(randomAMQPBrokerAddress.getHostText());
    consumerConfig4.setPort(randomAMQPBrokerAddress.getPort());
    AndesClient consumerClient4 = new AndesClient(consumerConfig4, true);
    consumerClient4.startClient();

    AndesClient publisherClient1 = new AndesClient(publisherConfig1, true);
    publisherClient1.startClient();

    AndesJMSPublisherClientConfiguration publisherConfig2 = publisherConfig1.clone();
    randomAMQPBrokerAddress = getRandomAMQPBrokerAddress();
    publisherConfig2.setHostName(randomAMQPBrokerAddress.getHostText());
    publisherConfig2.setPort(randomAMQPBrokerAddress.getPort());
    AndesClient publisherClient2 = new AndesClient(publisherConfig2, true);
    publisherClient2.startClient();

    AndesJMSPublisherClientConfiguration publisherConfig3 = publisherConfig1.clone();
    randomAMQPBrokerAddress = getRandomAMQPBrokerAddress();
    publisherConfig3.setHostName(randomAMQPBrokerAddress.getHostText());
    publisherConfig3.setPort(randomAMQPBrokerAddress.getPort());
    AndesClient publisherClient3 = new AndesClient(publisherConfig3, true);
    publisherClient3.startClient();

    AndesJMSPublisherClientConfiguration publisherConfig4 = publisherConfig1.clone();
    randomAMQPBrokerAddress = getRandomAMQPBrokerAddress();
    publisherConfig4.setHostName(randomAMQPBrokerAddress.getHostText());
    publisherConfig4.setPort(randomAMQPBrokerAddress.getPort());
    AndesClient publisherClient4 = new AndesClient(publisherConfig4, true);
    publisherClient4.startClient();

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient1, AndesClientConstants.DEFAULT_RUN_TIME);
    AndesClientUtils.shutdownClient(consumerClient2);
    AndesClientUtils.shutdownClient(consumerClient3);
    AndesClientUtils.shutdownClient(consumerClient4);

    Assert.assertEquals(publisherClient1.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient1.");
    Assert.assertEquals(publisherClient2.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient2.");
    Assert.assertEquals(publisherClient3.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient3.");
    Assert.assertEquals(publisherClient4.getSentMessageCount(), sendCount,
            "Message sending failed by publisherClient4.");
    Assert.assertEquals(consumerClient1.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient1.");
    Assert.assertEquals(consumerClient2.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient2.");
    Assert.assertEquals(consumerClient3.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient3.");
    Assert.assertEquals(consumerClient4.getReceivedMessageCount(), expectedCount,
            "Message receiving failed by consumerClient4.");

    long totalMessagesSent = publisherClient1.getSentMessageCount() + publisherClient2.getSentMessageCount()
            + publisherClient3.getSentMessageCount() + publisherClient4.getSentMessageCount();

    long totalMessagesReceived = consumerClient1.getReceivedMessageCount()
            + consumerClient2.getReceivedMessageCount() + consumerClient3.getReceivedMessageCount()
            + consumerClient4.getReceivedMessageCount();

    Assert.assertEquals(totalMessagesSent, totalMessagesReceived,
            "Message receiving failed " + "by all consumers");
    Assert.assertEquals(totalMessagesSent, sendCount * 4,
            "Message receiving by all consumers" + " does not match the message count " + "that was sent");

    // Evaluate messages left in database
    Assert.assertEquals(dataAccessUtil.getMessageCountForQueue(queueName), 0, "Messages left in database");
    // Evaluate slots left in database
    Assert.assertEquals(dataAccessUtil.getAssignedSlotCountForQueue(queueName), 0, "Slots left in database");
}