}
else
{
ServiceProperties serviceProperties =
_expectedServiceProperties.get(possibleService);
ClusterProperties clusterProperties =
_expectedClusterProperties.get(serviceProperties.getClusterName());
UriProperties uriProperties =
_expectedUriProperties.get(serviceProperties.getClusterName());
assertEquals(_state.getServiceProperties(possibleService).getProperty(),
serviceProperties);
// verify round robin'ing of the hosts for this service
for (int i = 0; i < 100; ++i)
{
try
{
// this call will queue up messages if we're not listening to the service, but
// it's ok, because all of the messengers have been stopped.
final TransportClient client =
_loadBalancer.getClient(new URIRequest("d2://" + possibleService +
random(_possiblePaths)), new RequestContext());
// if we didn't receive service unavailable, we should
// get a client back
assertNotNull(client);
}
catch (ServiceUnavailableException e)
{
if (uriProperties != null && clusterProperties != null)
{
// only way to get here is if the prioritized
// schemes could find no available uris in the
// cluster. let's see if we can find a URI that
// matches a prioritized scheme in the cluster.
Set<String> schemes = new HashSet<String>();
for (URI uri : uriProperties.Uris())
{
schemes.add(uri.getScheme());
}
for (String scheme : clusterProperties.getPrioritizedSchemes())
{
// if we got null, then we must not have a
// matching scheme, or we must be missing a
// client factory
// TODO if you're not using round robin
// strategy, it's possible that the strategy
// could return null (even though a factory is
// available), but i am not checking for this at
// the moment. See SimpleLoadBalancer.java to trace
// the code.
if (schemes.contains(scheme) && _clientFactories.containsKey(scheme))
{
break;
}
assertFalse(schemes.contains(scheme)
&& _clientFactories.containsKey(scheme),
"why couldn't a client be found for schemes "
+ clusterProperties.getPrioritizedSchemes()
+ " with URIs: " + uriProperties.Uris());
}
}
}
}